在Oracle的过程中选择Statement

Mik*_*yev 11 select stored-procedures oracle10g

很抱歉提出这个问题,但是因为之前给出的答案都不足以让我理解.我想编写一个存储过程来返回表中的所有列.作为一个广告hod查询我只是写

SELECT * FROM EMPLOYEES
Run Code Online (Sandbox Code Playgroud)

但在这里,我收到一个错误,提示我提供INTO条款,我不明白为什么以及如何.有人可以解释我在上述情况下如何做以及只想返回一个列值(多行) .

Ton*_*ews 15

具有SQL Server背景的人员用于编写返回整个查询结果的存储过程,因此尝试编写如下的PL/SQL过程:

procedure get_emps is
begin
    -- this will NOT work!
    select * from emp;
end;
Run Code Online (Sandbox Code Playgroud)

不幸的是,事情并非那么简单.可能PL/SQL中最接近的等价物是返回引用游标的函数:

function get_emps return sys_refcursor is
    rc sys_refcursor;
begin
    open rc for
        select * from emp;
    return rc;
end;
Run Code Online (Sandbox Code Playgroud)

你可以从这样的调用程序中调用它:

declare
    cur sys_refcursor;
    emp_rec emp%rowtype;
begin
    cur := get_emps;
    loop
        fetch cur into emp_rec;
        exit when cur%notfound;
    end loop;
    close cur;
end;
Run Code Online (Sandbox Code Playgroud)

或者在SQL Plus中你可以这样做:

var rc refcursor
:rc := get_emps;
print rc
Run Code Online (Sandbox Code Playgroud)

  • 怎么做的?对不起,我接受了"谢谢Tony.I得到了一切",这意味着你完全明白我的回答.你不明白什么? (2认同)