如何查看/验证程序结果?
有人可以解释如何查看程序的结果,一切正常,代码有效,执行和编译没有错误。现在我如何才能将结果视为查询或其他内容。
前程序是关于工资的总和。
CREATE OR REPLACE PROCEDURE HR.TOTAL_SALARY AS
total_salary NUMBER(12,2);
BEGIN
SET TRANSACTION READ ONLY;
SELECT SUM (salary)
INTO total_salary
FROM employees;
DBMS_OUTPUT.PUT_LINE('Total salary 1: ' || total_salary);
COMMIT;
END;
Can someone explain how to see the results of a procedure, everything is working fine and the code is valid, executed and compiled with no errors. Now how can I see the results as Query or anything.
The ex procedure is about sum of salary.
CREATE OR REPLACE PROCEDURE HR.TOTAL_SALARY AS
total_salary NUMBER(12,2);
BEGIN
SET TRANSACTION READ ONLY;
SELECT SUM (salary)
INTO total_salary
FROM employees;
DBMS_OUTPUT.PUT_LINE('Total salary 1: ' || total_salary);
COMMIT;
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在 SQL*Plus 中运行它吗?您是否“设置了服务器输出;”?
Are you running this in SQL*Plus? Have you "set serveroutput on;"?
我为此推荐一个函数,
其用法如下:
I recommend for this a function
The usage for this is like:
要在过程中输出 select 语句的结果,您需要使用游标。
然后要使用它,声明游标,执行过程,并输出结果。
(不保证上面的语法在语法上是完美的 - 我现在远离数据库。但它应该足够接近,可以让你朝着正确的方向前进。)
哦 - 你可以在 a 内部使用用户定义的游标类型包,如果它适合您的环境。
To output the results of a select statement in a procedure you need to use a cursor.
then to use it, declare the cursor, execute the proc, and output the results.
(no promises that the above is syntactically perfect - I'm away from the DB right now. But it should be close enough to get you in the right direction.)
Oh - and you can use a user-defined cursor type inside of a package, if that is appropriate for your environment.