(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> declare
2 v_lastname customer.lastname%type;
3 v_area_code customer.area_code%type;
4 v_phone customer.phone%type;
5 begin
6 SELECT lastname, area_code, phone
7 INTO v_lastname, v_area_code, v_phone
8 FROM customer
9 WHERE cust_no = 1;
10 dbms_output.put_line(v_lastname || ' (' ||
11 v_area_code || ')' || v_phone);
12 exception
13 when no_data_found then
14 raise_application_error(-20000, 'Customer not found');
15 end;
16 /
JONES (212)221-4333
PL/SQL procedure successfully completed.
One variable for each column retrieved
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> begin
2 for x in (select lastname from customer) loop
3 dbms_output.put_line(x.lastname);
4 end loop;
5 END;
6 /
Jones
Smith
Anderson
Murdy
. . .
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create or replace procedure phone_book_load
2 as
3 v_lastname customer.lastname%type;
4 v_firstname customer.firstname%type;
5 begin
6 for x in (select lastname,firstname, phone
7 from customer) loop
8 insert into phone_book
9 values(x.lastname, x.firstname, x.phone)
10 returning lastname, firstname
11 into v_lastname, v_firstname;
12 dbms_output.put_line(v_lastname);
13 end loop;
14 end;
15 /
Procedure created.
SQL> exec phone_book_load
JONES
SMITH
ANDERSON
MURDY
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
update customer
set discount = v_discount
where cust_no = v_cust_no;
if sql%rowcount = 0 then
/* some processing */
end if;
. . .
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create or replace procedure create_table
2 authid current_user as
3 begin
4 execute immediate 'create table test(c1 number)';
5 end;
6 /
Procedure created.
SQL> exec create_table
PL/SQL procedure successfully completed.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).