oracle 数据库中存储过程输出情况

2025年03月23日 07:33
有5个网友回答
网友(1):

1、编写存储过程,

create or replace procedure test_pro(in_num number)

as

  M number;

begin

  M := in_num;

  if 0 < M then

    dbms_output.put_line('输出SQL语句1');

  elsif M < 3 then

    dbms_output.put_line('输出SQL语句2');

  else

    dbms_output.put_line('nothing');

  end if;

end;

2、在command窗口编译,

3、执行存储过程,输入变量,实际什么也不输入,

4、切到DBMS输出窗口,查看输出结果,‘nothing’,也就是说并没有执行‘输出SQL语句’,

网友(2):

可用DBMS_OUTPUT.PUT_LINE()对存储过程的内容进行输出。

如:一个简单的存储过程如下

declare
       cursor c_job
       is
       select empno,ename,job,sal
       from emp
       where job='MANAGER';
       c_row c_job%rowtype;
begin
       for c_row in c_job loop
         dbms_output.put_line(c_row.empno||'-'||c_row.ename||'-'||c_row.job||'-'||c_row.sal);
       end loop;
end;

结果中,红色部分就是存储过程的输出。

网友(3):

在你注释的地方插入一句话: null;
完整的如下:
if m<0 then
dbms_output.put_line('m<0');
elsif m<3 then
dbms_output.put_line('m<3');
else
null;
end if;

网友(4):

不可以什么都不写的,你可以写成"null”,就是什么都不执行的意思,希望可以解决你的问题

网友(5):

你什么都不写不就可以了吗!