DBMS_OUTPUT.PUT_LINE未在函数内部打印

时间:2018-11-02 18:23:53

标签: oracle plsql

我正在下面的代码段中运行,其中dbms_ouput不会打印任何内容,只是显示在SQL Developer中成功编译的函数。

set serveroutput on size 30000;
create or replace function check_status (p_user_name in varchar2) return number is
begin
DBMS_OUTPUT.PUT_LINE('Yoo');
end;
/

下面的代码段正在打印。我很伤心,为什么它不打印内部功能。

set serveroutput on size 30000;
begin
DBMS_OUTPUT.PUT_LINE('Yoo');
end;
/

1 个答案:

答案 0 :(得分:2)

您已经编译了函数,但是尚未调用该函数。该函数中的代码仅在调用该函数时才运行,因此在编译时不显示任何输出是正确的。

您的函数还需要返回一个值;现在调用它会得到:

.container {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-flow: column nowrap;
  position: relative;
  overflow: hidden;
}

.game-container {
  display: flex;
  flex-flow: row nowrap;
  height: 100%;
  width: 100%;

  .left {
    flex-grow: 1;
    background: lightcoral;

    .topbar-inventory-container {
      width: calc( 100% - 40px );
      margin: 0 20px;
      display: flex;
      flex-flow: column nowrap;

      .inventory-hanger-container {
        height: 40px;
        width: 100%;
        display: flex;
        flex-flow: row nowrap;
        justify-content: space-between;

        .vertical-separator {
          margin: 0 40px;
          background: lightgrey;
        }
      }

      .inventory {
        height: 80px;
        background: lightgrey;
        width: 100%;
      }
    }
  }

  .right-container {
    position: relative;
    display: flex;
    flex-flow: row nowrap;
    transition: transform .3s ease-in-out;

    &.closed {
      transform: translateX( $thickness + 400px);
    }

    .hide-shop-btn {
      position: absolute;
      height: 60px;
      width: 40px;
      left: -40px;
      border-top-left-radius: 50%;
      border-bottom-left-radius: 50%;
      background: black;
      display: flex;
      align-self: center;
      align-items: center;
      justify-content: center;

      .fa-caret-left {
        color: white;
        font-size: 25px;
      }
    }

    .right {
      width: 400px;
      height: 100%;
      background: darkgray;
    }
  }
}

确实显示输出,但也显示错误。

因此您的函数需要返回一些内容:

select check_status('test') from dual;

ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "MYSCHEMA.CHECK_STATUS", line 4

Yoo

还要注意,任何调用该函数的人只有在其会话或客户端中启用了输出后,才会看到create or replace function check_status (p_user_name in varchar2) return number is begin DBMS_OUTPUT.PUT_LINE('Yoo'); return 42; end; / Function CHECK_STATUS compiled select check_status('test') from dual; CHECK_STATUS('TEST') -------------------- 42 Yoo 。由于您无法控制自己不应该依赖它。它对调试最有用。