我正在嘗試嵌套記錄示例。 請看看聲明部分。如何在PL/SQL的嵌套記錄中獲取數據?
DECLARE
TYPE r_emp IS RECORD (
name VARCHAR2(50),
dept_rec departments%ROWTYPE
);
r_emp_row r_emp;
BEGIN
SELECT emp.first_name||' '||emp.last_name,dept.*
INTO r_emp_row
FROM employees emp,departments dept
WHERE emp.department_id = dept.department_id
AND emp.employee_id = 100;
DBMS_OUTPUT.PUT_LINE('Name:'||r_emp_row.name);
DBMS_OUTPUT.PUT_LINE('Department ID:'||r_emp_row.dept_rec.department_id);
DBMS_OUTPUT.PUT_LINE('Department Name:'||r_emp_row.dept_rec.department_name);
EXCEPTION
when others then
null;
END;
我想以上塊運行,但得到如下錯誤:
Error report -
ORA-06550: line 10, column 8:
PLS-00597: expression 'R_EMP_ROW' in the INTO list is of wrong type
ORA-06550: line 11, column 3:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
幫助表示讚賞。
這種結構的目的是什麼?也許你可以使用'FOR LOOP語句' '來簡化這個操作rec in(select * from xxx)loop rec.column_name end loop; ' –
是的,我知道FOR LOOP語句,並且它更喜歡嵌套記錄。此查詢是在培訓會議期間提出的。 –