在过程中输出 table 的所有名称
Output all names of a table in a procedure
我想在此过程中显示我的 employees
table 中的所有 last_name
。
错误:ORA-01422: Request returns more than the requested number of lines
代码:
CREATE OR REPLACE PROCEDURE writeAllEmployees AS
lastn employees.last_name%TYPE;
BEGIN
SELECT last_name INTO lastn FROM employees;
DBMS_OUTPUT.PUT_LINE(lastn);
END;
/
EXEC writeAllEmployees;
由于 table 中有不止一行,您需要一个循环:
CREATE OR REPLACE PROCEDURE writeAllEmployees AS
BEGIN
for cur_r in (SELECT last_name FROM employees) loop
DBMS_OUTPUT.PUT_LINE(cur_r.last_name);
end loop;
END;
/
EXEC writeAllEmployees;
不要忘记启用服务器输出;在 运行 set serveroutput on
.
的一些工具中
我想在此过程中显示我的 employees
table 中的所有 last_name
。
错误:ORA-01422: Request returns more than the requested number of lines
代码:
CREATE OR REPLACE PROCEDURE writeAllEmployees AS
lastn employees.last_name%TYPE;
BEGIN
SELECT last_name INTO lastn FROM employees;
DBMS_OUTPUT.PUT_LINE(lastn);
END;
/
EXEC writeAllEmployees;
由于 table 中有不止一行,您需要一个循环:
CREATE OR REPLACE PROCEDURE writeAllEmployees AS
BEGIN
for cur_r in (SELECT last_name FROM employees) loop
DBMS_OUTPUT.PUT_LINE(cur_r.last_name);
end loop;
END;
/
EXEC writeAllEmployees;
不要忘记启用服务器输出;在 运行 set serveroutput on
.