我想打印 的数据Cursor_pkg.c1.row_emp
,例如:在之后的过程中将Cursor_pkg.c1.row_emp.last_name
存在的数据将起作用。我该怎么做?Cursor_pkg.row_emp
Cursor_pkg_func.Print_Cur
- 我用 cursor 和 rec 创建 PACKAGE
- 我使用在 rec 中获取游标数据的过程创建 PACKAGE
- 我想输出获取的数据。如何?
有两个问题:我想从包emp_rec
(行)输出数据,我想直接从PACKAGECursor_pkg_func
过程输出它PS主要思想是存储数据和用于获取和选择数据的过程/函数
CREATE OR REPLACE PACKAGE Cursor_pkg AUTHID DEFINER IS
CURSOR C1 IS
SELECT last_name, job_id FROM employees
WHERE job_id LIKE '%CLERK%' AND manager_id > 120
ORDER BY last_name;
row_emp C1%ROWTYPE;
END Cursor_pkg;
/
CREATE OR REPLACE PACKAGE Cursor_pkg_func IS
PROCEDURE Print_Cur;
END Cursor_pkg_func;
/
CREATE OR REPLACE PACKAGE BODY Cursor_pkg_func IS
PROCEDURE Print_Cur IS
BEGIN
OPEN Cursor_pkg.C1;
LOOP
FETCH Cursor_pkg.C1 INTO Cursor_pkg.row_emp;
EXIT when Cursor_pkg.C1%NOTFOUND;
DBMS_OUTPUT.put_line(Cursor_pkg.row_emp.last_name);
END LOOP;
CLOSE Cursor_pkg.C1;
END;
END;
/
BEGIN
Cursor_pkg_func.Print_Cur;
END;
但是我想在没有创建函数的情况下从 Cursor_pkg.row_emp PACKAGE 中选择和打印。以及如何不仅打印 last_name 还打印所有行?错误开始于:最后三个语句有什么问题?
CREATE OR REPLACE PACKAGE Cursor_pkg_func IS
TYPE outrec_typ IS RECORD (
var_char2 VARCHAR2(30)
);
TYPE outrecset IS TABLE OF outrec_typ;
FUNCTION f_trans (p in number ) RETURN outrecset PIPELINED;
END Cursor_pkg_func;
/
CREATE OR REPLACE PACKAGE BODY Cursor_pkg_func IS
FUNCTION f_trans (p in number) RETURN outrecset PIPELINED IS
out_rec outrec_typ;
BEGIN
OPEN Cursor_pkg.C1;
LOOP
FETCH Cursor_pkg.C1 INTO Cursor_pkg.row_emp;
EXIT when Cursor_pkg.C1%NOTFOUND;
END LOOP;
LOOP
out_rec.var_char2 := Cursor_pkg.row_emp.last_name;
PIPE ROW(out_rec);
DBMS_OUTPUT.put_line(out_rec.var_char2);
END LOOP;
CLOSE Cursor_pkg.C1;
RETURN;
END f_trans;
END Cursor_pkg_func;
/
begin
Cursor_pkg_func.f_trans(5);
end;
/