1.声明若干个字段,并为其赋值(使用%type)
declare c_id number := 1; c_name customers.name%type; c_age customers.age%type; c_address customers.address%type; c_salary customers.salary%type; begin select name,age,address,salary into c_name,c_age,c_address,c_salary from customers where id = c_id; dbms_output.put_line(c_id||c_name||c_age||c_address||c_salary); end;
2.声明一个对象,并为其赋值(使用%rowtype)
declare c customers%rowtype; begin select * into c from customers where id = 1; dbms_output.put_line(c.id||c.name||c.age||c.address||c.salary); end;
3.创建一个新对象,只拥有原对象的部分属性(使用type 对象名称 is record)
declare type info is record( c_name customers.name%type, c_salary customers.salary%type ); c info; begin select name,salary into c from customers where id = 1; dbms_output.put_line(c.c_name||c.c_salary); end;