【问题标题】:Oracle PL/SQL SELECT INTO clause thinks it needs another INTOOracle PL/SQL SELECT INTO 子句认为它需要另一个 INTO
【发布时间】:2019-10-15 01:23:47
【问题描述】:

我有一个简单的测试函数,我在其中传递一个特定的 ID(我从中选择的表的主键),并在其上计算一个简单的函数和参数。

骨架代码及测试:

create or replace function test(id varchar2, area float) return float is
    theRow forest%ROWTYPE;
begin
    select * into theRow from forest where Forest_No = id;
    return area / theRow.Area;
end;

begin
    select test('1', 16000) from dual;
end;

输出:

[2019-10-14 21:19:10] [65000][6550] ORA-06550: line 2, column 5:
[2019-10-14 21:19:10] PLS-00428: an INTO clause is expected in this SELECT statement

据我所知,文档和示例使用相同的顺序和语法,我不知道该怎么做。我曾尝试像在 Postgresql 中那样将 into 子句移到末尾,但这没有用。

我在这里错过了什么?

【问题讨论】:

    标签: oracle plsql datagrip


    【解决方案1】:

    问题在于调用语句。

    每当select 语句在plsql 块中使用时,它必须有into 子句来为变量分配返回值。

    您应该从调用代码中删除 beginend

    --begin -- remove this
        select test('1', 16000) from dual;
    --end; -- remove this
    

    或者如果你想在 plsql 块中使用它然后添加到子句中:

    Declare
    Area_ float(precision);
    begin
        select test('1', 16000) into area_ from dual;
        -- use area_ in your code wherever required
        dbms_output.put_line('area: ' || area_);
    end;
    

    干杯!!

    【讨论】:

      猜你喜欢
      • 2019-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      相关资源
      最近更新 更多