Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. declare
  2. zmienna integer;
  3. begin
  4. select count(1) into zmienna from emp;
  5. dbms_output.put_line(zmienna);
  6. end;
  7.  
  8. declare
  9. suma integer;
  10. begin
  11. select count(1) into suma from emp;
  12. if(suma<16) then
  13. dbms_output.put_line('mniejsza od 16');
  14. else
  15. dbms_output.put_line('wieksza rowna');
  16. end if;
  17. end;
  18.  
  19. create or replace procedure zad3(nrdzialu integer, nazwa in varchar, lokalizacja in varchar) as
  20. sprawdzenie integer;
  21. begin
  22. select count(1) into sprawdzenie from dept where deptno=nrdzialu and dname=nazwa and loc= lokalizacja;
  23. if(sprawdzenie=0) then
  24. dbms_output.put_line('nie ma takiego i wstawia');
  25. else
  26. dbms_output.put_line('jest taki i nie wstawia');
  27. end if;
  28. end;
  29.  
  30. exec zad3(30, 'SALES', 'CHICAGO');
  31.  
  32. create or replace procedure zad4(nrdzialu integer, nazwisko in varchar) as
  33. sprawdzenie integer;
  34. pensja integer;
  35. identyfikator integer;
  36. begin
  37. select count(1) into sprawdzenie from dept where deptno= nrdzialu;
  38. if(sprawdzenie>0) then
  39. select min(sal) into pensja from emp;
  40. select max(empno) +1 into identyfikator from emp;
  41. insert into emp(empno, ename, sal, deptno) values (identyfikator, nazwisko, pensja, nrdzialu);
  42. dbms_output.put_line('wstawia');
  43. else
  44. raise_application_error(-20500,'nie ma dzialu');
  45. end if;
  46. end;
  47.  
  48. exec zad4(200, 'Testowy');
  49. rollback;
  50. select * from emp;
  51. select * from magazyn;
  52.  
  53. create or replace procedure zad5 as
  54. najwiecej magazyn%rowtype;
  55. maksimum integer;
  56. begin
  57. select max(ilosc) into maksimum from magazyn;
  58. select * into najwiecej from magazyn where ilosc = maksimum;
  59. dbms_output.put_line(najwiecej.nazwa);
  60. end;
  61.  
  62. exec zad5;
  63.  
  64. declare
  65. mempno integer;
  66. msal integer;
  67. linijka emp%rowtype;
  68. cursor zad1 is select empno from emp;
  69. begin
  70. open zad1;
  71. loop
  72. fetch zad1 into mempno;
  73. exit when zad1%notfound;
  74. select sal into msal from emp where empno=mempno;
  75. select * into linijka from emp where empno=mempno;
  76. if(msal<1000) then
  77. update emp set sal=sal+0.1*sal;
  78. dbms_output.put_line(linijka.ename);
  79. elsif(msal>1500)then
  80. update emp set sal= sal- 0.1*sal;
  81. end if;
  82. end loop;
  83. close zad1;
  84. end;
  85.  
  86. create or replace procedure zad21(salmin integer, salmax integer) as
  87. cursor cursor2 is select empno from emp;
  88. mempno integer;
  89. msal integer;
  90. begin
  91. open cursor2;
  92. loop
  93. fetch cursor2 into mempno;
  94. exit when cursor2%notfound;
  95. select sal into msal from emp where empno= mempno;
  96. if(msal<salmin) then
  97. update emp set sal=sal+0.1*sal;
  98. dbms_output.put_line('zaktualizowano dla min');
  99. elsif(msal>salmax) then
  100. update emp set sal= sal- 0.1*sal;
  101. dbms_output.put_line('zaktualizowano dla max');
  102. end if;
  103. end loop;
  104. close cursor2;
  105. end;
  106.  
  107. exec zad21(1222,1600);
  108. select * from emp;
  109.  
  110. create or replace procedure zad31(dzial integer) as
  111. srednia integer;
  112. wiersz emp%rowtype;
  113. cursor cursor3 is select * from emp where deptno= dzial;
  114. begin
  115. select avg(sal) into srednia from emp where deptno= dzial;
  116. open cursor3;
  117. loop
  118. fetch cursor3 into wiersz;
  119. exit when cursor3%notfound;
  120. if(wiersz.sal < srednia) then
  121. dbms_output.put_line('mniejsza= prowizja');
  122. end if;
  123. end loop;
  124. close cursor3;
  125. end;
  126.  
  127.  
  128. exec zad31(10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement