User:Zudio/sandbox

1)DECLARE v_count NUMBER; BEGIN  -- Check if the table has any rows  SELECT COUNT(*) INTO v_count FROM my_table;  IF v_count = 0 THEN    -- Insert a new row    INSERT INTO my_table (column1, column2, column3) VALUES (value1, value2, value3);    -- Commit the transaction    COMMIT;  ELSE    -- Rollback the transaction    ROLLBACK;  END IF; END; 7) explicit declare id cst.id%type; name cst.name%type; address cst.address%type; CURSOR c_cst is SELECT id,name,address FROM cst; BEGIN OPEN c_cst; LOOP FETCH c_cst into id,name,address; EXIT WHEN c_cst%notfound; dbms_output.put_line(id||' '||name||' '||address); END LOOP; CLOSE c_cst; END;

6)implicit declare total_rows number(2); BEGIN UPDATE ct SET salary=salary+1000; IF sql%notfound THEN dbms_output.put_line('no customer selected'); ELSIF sql%found THEN total_rows:=sql%rowcount; dbms_output.put_line(total_rows||'customers selected'); END IF; END;

5)user defiend DECLARE var_dividend NUMBER:=24; var_divisor NUMBER:=0; var_result NUMBER; ex_divzero EXCEPTION; BEGIN IF var_divisor=0 THEN RAISE ex_divzero; END IF; var_result:=var_dividend/var_divisor; dbms_output.put_line('Result=' ||var_result); EXCEPTION WHEN ex_divzero THEN dbms_output.put_line('error error!.your divisor is zero'); END;

3)exception DECLARE citizen EXCEPTION; age NUMBER:=35; BEGIN IF age<50 THEN RAISE citizen; END IF; END;

EXCEPTION WHEN citizen THEN DBMS_OUTPUT.PUT_LINE ('handling citizen exception');

WHEN others THEN DBMS_OUTPUT.PUT_LINE ('could not recognize exception citizen in the scope'); END;

4) create or replace function totalpublisher

return number is total number(2):=0;

begin select count(*) into total from my_table;

return total; end;

declare

c number(2);

begin

c:=total;

dbms_output.put_line('total customers'||c);

end;