Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4.
- begin
- DBMS_OUTPUT.PUT_LINE('HELLO WORLD!');
- END;
- ----
- 4.
- DECLARE
- v_myage number:=31;
- begin
- if v_myage > 11
- then
- dbms_output.put_line('I am not a child');
- end if;
- end;
- ;
- 7.
- DECLARE
- v_deptid number;
- v_deptname varchar2(20);
- v_emps number;
- v_mngid number :=108;
- begin
- case v_mngid
- when 108 then
- select department_id, department_name
- into v_deptid, v_deptname from departments
- where manager_id=108;
- select count(*) into v_emps from employees
- where department_id = v_deptid;
- end case;
- dbms_output.put_line('pracujesz w departamencie: '|| v_deptname || ' department. Jest tam '|| v_emps || ' pracownikow');
- end;
- 8.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- loop
- insert into locations (location_id, city, country_id)
- values ((v_loc_id + v_counter), v_new_city, v_countryid);
- v_counter:=v_counter+1;
- exit when v_counter>3;
- end loop;
- commit;
- end;
- 9.
- select * from locations;
- 10.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=0;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- loop
- delete from locations where location_id=(v_loc_id - v_counter);
- v_counter:=v_counter+1;
- exit when v_counter>2;
- end loop;
- commit;
- end;
- 11.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- loop
- insert into locations (location_id, city, country_id)
- values ((v_loc_id + v_counter), v_new_city, v_countryid);
- dbms_output.put_line('v counter: '||v_counter||' wartosc nowego loc_id: '||(v_loc_id+v_counter));
- v_counter:=v_counter+1;
- exit when v_counter>3;
- end loop;
- commit;
- end;
- 12.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=0;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- loop
- delete from locations where location_id=(v_loc_id - v_counter);
- v_counter:=v_counter+1;
- exit when v_counter>2;
- end loop;
- commit;
- end;
- 13.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- while v_counter<3 loop
- insert into locations (location_id, city, country_id)
- values ((v_loc_id + v_counter), v_new_city, v_countryid);
- v_counter:=v_counter+1;
- end loop;
- commit;
- end;
- 14.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- while v_counter<=2 loop
- delete from locations where
- location_id=(v_loc_id - v_counter);
- v_counter:=v_counter+1;
- end loop;
- commit;
- end;
- select * from locations;
- 15.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- for a in 1..3 loop
- insert into locations (location_id, city, country_id)
- values ((v_loc_id + v_counter), v_new_city, v_countryid);
- v_counter:=v_counter+1;
- end loop;
- commit;
- end;
- 16.
- DECLARE
- v_countryid locations.country_id%type :='CA';
- v_loc_id locations.location_id%type;
- v_counter number(2):=1;
- v_new_city locations.city%type:='Montreal';
- begin
- select max(location_id)
- into v_loc_id from locations
- where country_id=v_countryid;
- for a in 1..3 loop
- delete from locations where
- location_id=(v_loc_id - v_counter);
- v_counter:=v_counter+1;
- end loop;
- commit;
- end;
- 17.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement