如何查看/验证程序结果?

发布于 2024-09-24 21:16:42 字数 397 浏览 6 评论 0原文

有人可以解释如何查看程序的结果,一切正常,代码有效,执行和编译没有错误。现在我如何才能将结果视为查询或其他内容。

前程序是关于工资的总和。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隱形的亼 2024-10-01 21:16:42

您在 SQL*Plus 中运行它吗?您是否“设置了服务器输出;”?

Are you running this in SQL*Plus? Have you "set serveroutput on;"?

满栀 2024-10-01 21:16:42

我为此推荐一个函数,

CREATE OR REPLACE FUNCTION HR.TOTAL_SALARY return number AS    
   total_salary NUMBER(12,2);    
BEGIN    

  SELECT SUM (salary) 
    INTO total_salary 
    FROM employees;    

return total_salary;

END; 

其用法如下:

select hr.TOTAL_SALARY() as total_sal from dual.

I recommend for this a function

CREATE OR REPLACE FUNCTION HR.TOTAL_SALARY return number AS    
   total_salary NUMBER(12,2);    
BEGIN    

  SELECT SUM (salary) 
    INTO total_salary 
    FROM employees;    

return total_salary;

END; 

The usage for this is like:

select hr.TOTAL_SALARY() as total_sal from dual.
你列表最软的妹 2024-10-01 21:16:42

要在过程中输出 select 语句的结果,您需要使用游标。

create procedure myproc 
(in_variable IN number, out_records OUT sys_refcursor)
as
begin
open out_records for

select * from mytable
where column = in_variable;

end;

然后要使用它,声明游标,执行过程,并输出结果。

variable records refcursor;
exec myproc(1, :records);
print :records;

(不保证上面的语法在语法上是完美的 - 我现在远离数据库。但它应该足够接近,可以让你朝着正确的方向前进。)

哦 - 你可以在 a 内部使用用户定义的游标类型包,如果它适合您的环境。

To output the results of a select statement in a procedure you need to use a cursor.

create procedure myproc 
(in_variable IN number, out_records OUT sys_refcursor)
as
begin
open out_records for

select * from mytable
where column = in_variable;

end;

then to use it, declare the cursor, execute the proc, and output the results.

variable records refcursor;
exec myproc(1, :records);
print :records;

(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文