Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. 4.
  2. begin
  3. DBMS_OUTPUT.PUT_LINE('HELLO WORLD!');
  4. END;
  5.  
  6. ----
  7.  
  8.  
  9. 4.
  10.  
  11. DECLARE
  12. v_myage number:=31;
  13. begin
  14. if v_myage > 11
  15. then
  16. dbms_output.put_line('I am not a child');
  17. end if;
  18. end;
  19.  
  20. ;
  21.  
  22.  
  23. 7.
  24. DECLARE
  25. v_deptid number;
  26. v_deptname varchar2(20);
  27. v_emps number;
  28. v_mngid number :=108;
  29.  
  30. begin
  31.  
  32. case v_mngid
  33. when 108 then
  34. select department_id, department_name
  35. into v_deptid, v_deptname from departments
  36. where manager_id=108;
  37. select count(*) into v_emps from employees
  38. where department_id = v_deptid;
  39. end case;
  40. dbms_output.put_line('pracujesz w departamencie: '|| v_deptname || ' department. Jest tam '|| v_emps || ' pracownikow');
  41. end;
  42.  
  43.  
  44. 8.
  45. DECLARE
  46. v_countryid locations.country_id%type :='CA';
  47. v_loc_id locations.location_id%type;
  48. v_counter number(2):=1;
  49. v_new_city locations.city%type:='Montreal';
  50.  
  51. begin
  52. select max(location_id)
  53. into v_loc_id from locations
  54. where country_id=v_countryid;
  55. loop
  56. insert into locations (location_id, city, country_id)
  57. values ((v_loc_id + v_counter), v_new_city, v_countryid);
  58. v_counter:=v_counter+1;
  59. exit when v_counter>3;
  60. end loop;
  61. commit;
  62. end;
  63.  
  64.  
  65. 9.
  66. select * from locations;
  67.  
  68. 10.
  69. DECLARE
  70. v_countryid locations.country_id%type :='CA';
  71. v_loc_id locations.location_id%type;
  72. v_counter number(2):=0;
  73. v_new_city locations.city%type:='Montreal';
  74.  
  75. begin
  76. select max(location_id)
  77. into v_loc_id from locations
  78. where country_id=v_countryid;
  79. loop
  80. delete from locations where location_id=(v_loc_id - v_counter);
  81. v_counter:=v_counter+1;
  82. exit when v_counter>2;
  83. end loop;
  84. commit;
  85. end;
  86.  
  87.  
  88. 11.
  89. DECLARE
  90. v_countryid locations.country_id%type :='CA';
  91. v_loc_id locations.location_id%type;
  92. v_counter number(2):=1;
  93. v_new_city locations.city%type:='Montreal';
  94.  
  95. begin
  96. select max(location_id)
  97. into v_loc_id from locations
  98. where country_id=v_countryid;
  99. loop
  100. insert into locations (location_id, city, country_id)
  101. values ((v_loc_id + v_counter), v_new_city, v_countryid);
  102. dbms_output.put_line('v counter: '||v_counter||' wartosc nowego loc_id: '||(v_loc_id+v_counter));
  103. v_counter:=v_counter+1;
  104. exit when v_counter>3;
  105. end loop;
  106. commit;
  107. end;
  108.  
  109. 12.
  110. DECLARE
  111. v_countryid locations.country_id%type :='CA';
  112. v_loc_id locations.location_id%type;
  113. v_counter number(2):=0;
  114. v_new_city locations.city%type:='Montreal';
  115.  
  116. begin
  117. select max(location_id)
  118. into v_loc_id from locations
  119. where country_id=v_countryid;
  120. loop
  121. delete from locations where location_id=(v_loc_id - v_counter);
  122. v_counter:=v_counter+1;
  123. exit when v_counter>2;
  124. end loop;
  125. commit;
  126. end;
  127.  
  128. 13.
  129. DECLARE
  130. v_countryid locations.country_id%type :='CA';
  131. v_loc_id locations.location_id%type;
  132. v_counter number(2):=1;
  133. v_new_city locations.city%type:='Montreal';
  134.  
  135. begin
  136. select max(location_id)
  137. into v_loc_id from locations
  138. where country_id=v_countryid;
  139.  
  140. while v_counter<3 loop
  141. insert into locations (location_id, city, country_id)
  142. values ((v_loc_id + v_counter), v_new_city, v_countryid);
  143. v_counter:=v_counter+1;
  144. end loop;
  145. commit;
  146. end;
  147.  
  148. 14.
  149. DECLARE
  150. v_countryid locations.country_id%type :='CA';
  151. v_loc_id locations.location_id%type;
  152. v_counter number(2):=1;
  153. v_new_city locations.city%type:='Montreal';
  154.  
  155. begin
  156. select max(location_id)
  157. into v_loc_id from locations
  158. where country_id=v_countryid;
  159.  
  160. while v_counter<=2 loop
  161. delete from locations where
  162. location_id=(v_loc_id - v_counter);
  163. v_counter:=v_counter+1;
  164. end loop;
  165. commit;
  166. end;
  167.  
  168. select * from locations;
  169.  
  170. 15.
  171. DECLARE
  172. v_countryid locations.country_id%type :='CA';
  173. v_loc_id locations.location_id%type;
  174. v_counter number(2):=1;
  175. v_new_city locations.city%type:='Montreal';
  176.  
  177. begin
  178. select max(location_id)
  179. into v_loc_id from locations
  180. where country_id=v_countryid;
  181.  
  182. for a in 1..3 loop
  183. insert into locations (location_id, city, country_id)
  184. values ((v_loc_id + v_counter), v_new_city, v_countryid);
  185. v_counter:=v_counter+1;
  186. end loop;
  187. commit;
  188. end;
  189.  
  190. 16.
  191.  
  192. DECLARE
  193. v_countryid locations.country_id%type :='CA';
  194. v_loc_id locations.location_id%type;
  195. v_counter number(2):=1;
  196. v_new_city locations.city%type:='Montreal';
  197.  
  198. begin
  199. select max(location_id)
  200. into v_loc_id from locations
  201. where country_id=v_countryid;
  202.  
  203. for a in 1..3 loop
  204. delete from locations where
  205. location_id=(v_loc_id - v_counter);
  206. v_counter:=v_counter+1;
  207. end loop;
  208. commit;
  209. end;
  210.  
  211. 17.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement