declare TYPE employee_record is RECORD( id employee.id % TYPE, name employee.name % TYPE, email employee.email % TYPE); em_record employee_record; begin select id,name,email into em_record from employee where name =& name; dbms_output.put_line( ' 雇员名: ' || em_record.name || ' 雇员ID: ' || em_record.id); end ;
2.PL/SQL表,类似于数组概念,不同的是PL/SQL表允许负值下标,而且没有上下限,如:
declare TYPE employee_table is table of employee.name % TYPE index by BINaRY_INTEGER; em_table employee_table; begin select name into em_table( - 1 ) from employee where name =& name; dbms_output.put_line( ' 雇员名: ' || em_table( - 1 )); end ;
3.嵌套表,与PL/SQL 表相似,不同的是嵌套表可以做表列的
数据类型
,而PL/SQL表不能,使用嵌套表作为表列时,必须为其指定专门的存储表,如:
create or replace TYPE emp_type as OBJECT(name VARCHAR2 ( 10 ),salary NUMBER ( 6 , 2 ),hiredate DATE);
CREATE OR REPLACE TYPE emp_array IS TABLE OF emp_type;
CREATE TABLE department( deptno NUMBER ( 2 ),dname VARCHAR2 ( 10 ), employee emp_array)NESTED TABLE employee STORE as employee_dept;
DECLARE TYPE c1 IS REF CURSOR ; emp_cursor c1; v_name employee.name % TYPE; v_sal employee.salary % TYPE; begin open emp_cursor for SELECT name,salary FROM EMPLOYEE ; LOOP FETCH emp_cursor INTO v_name,v_sal; EXIT WHEN emp_cursor % NOTFOUND; dbms_output.put_line(v_name); END LOOP; close emp_cursor; end ;