Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PROCEDURE marire_bursa(
- given_id IN NUMBER)
- AS
- v_bursa number;
- counter number;
- bursa_mare exception;
- student_inexistent exception;
- PRAGMA EXCEPTION_INIT(bursa_mare, -20511);
- PRAGMA EXCEPTION_INIT(student_inexistent, -20512);
- BEGIN
- SELECT COUNT(*) INTO counter FROM studenti WHERE given_id = id;
- if(counter<1) then raise student_inexistent;
- end if;
- UPDATE studenti set bursa=bursa*2 where id=given_id;
- select bursa into v_bursa from studenti where id=given_id;
- if(v_bursa>3000 and v_bursa is not null)
- then update studenti set bursa=3000 where id=given_id;
- raise bursa_mare;
- end if;
- EXCEPTION
- WHEN bursa_mare THEN
- DBMS_OUTPUT.PUT_LINE('Studentul cu id ' || given_id ||' are bursa mare');
- WHEN student_inexistent THEN
- DBMS_OUTPUT.PUT_LINE('Studentul cu id ' || given_id ||' nu exista in baza de date');
- END marire_bursa;
- DECLARE
- v_index number;
- v_id number;
- v_counter number;
- v_bursa studenti.bursa%type;
- bursa_mare exception;
- student_inexistent exception;
- PRAGMA EXCEPTION_INIT(bursa_mare, -20511);
- PRAGMA EXCEPTION_INIT(student_inexistent, -20512);
- BEGIN
- v_counter:=1;
- FOR v_index in 1..100 LOOP
- MARIRE_BURSA(v_index);
- v_id:=v_index;
- if(v_index<=100)
- then
- select bursa into v_bursa from studenti where id=v_index ;
- if(v_bursa is not null)
- then
- if(v_counter<=10)
- then
- DBMS_OUTPUT.PUT_LINE(v_counter || '. Bursa studentului cu id '|| v_id||' este acum ' || v_bursa || ' (inainte era ' ||v_bursa/2 || ')' );
- v_counter:=v_counter+1;
- end if;
- end if;
- end if;
- END LOOP;
- EXCEPTION
- WHEN bursa_mare THEN
- DBMS_OUTPUT.PUT_LINE('Studentul cu id ' || v_id ||' are bursa mare');
- WHEN student_inexistent THEN
- DBMS_OUTPUT.PUT_LINE('Studentul cu id ' || v_id ||' nu exista in baza de date');
- END;
- ROLLBACK;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement