oracle的存儲過程查詢整張表返回結果?
創建返回結果集的函數SQL> create or replace package pkg_HelloWorld as 2 -- 定義ref cursor類型 3 type myrctype is ref cursor; 4 --函數申明 5 function getHelloWorld return myrctype; 6 end pkg_HelloWorld; 7 /程序包已創建。SQL> CREATE OR REPLACE package body pkg_HelloWorld as 2 function getHelloWorld return myrctype 3 IS 4 return_cursor myrctype; 5 BEGIN 6 OPEN return_cursor FOR 7 SELECT 'Hello
1' AS a, 'World 1' AS B FROM dual 8 UNION ALL 9 SELECT 'Hello
2' AS a, 'World 2' AS B FROM dual; 10 return return_cursor; 11 END getHelloWorld; 12 end pkg_HelloWorld; 13 /程序包體已創建。注:Oracle 這里的函數,是一個返回游標類型的函數, 不是像 SQL Server 的那種叫 “表值函數” 的東西。因此下面的寫法會報錯。SQL> SELECT * FROM pkg_HelloWorld.getHelloWorld();SELECT * FROM pkg_HelloWorld.getHelloWorld() *第 1 行出現錯誤:ORA-00933: SQL 命令未正確結束SQL> SELECT pkg_HelloWorld.getHelloWorld() FROM dual;PKG_HELLOWORLD.GETHE--------------------CURSOR STATEMENT : 1CURSOR STATEMENT : 1A B------- -------Hello 1 World 1Hello 2 World 2