2016-11-16 57 views

回答

0

您可以定義變量和存儲選擇的值顯示在下面的代碼塊

DECLARE 
    v_wm_concat user_cons_columns.column_name%TYPE; 

BEGIN 
    SELECT WM_CONCAT(COLUMN_NAME) FROM USER_CONS_COLUMNS INTO v_wm_concat 
    DBMS_OUTPUT.PUT_LINE('Comma seperated list of columns: '|| v_wm_concat); 
1

你就是不行。

您需要添加一個額外層 - 在SQL查詢的結果集將被綁定的變量。 PL/SQL有一個特殊的構造。在這種情況下適用的構造是select into。請參閱the fine manualQuery Result Set Processing瞭解更多詳情。

你的榜樣將無法編譯:

begin 
    dbms_output.put_line((select dummy from dual)); 
end; 
/

但將導致PLS-00103:

dbms_output.put_line((select dummy from dual)); 
         * 
ERROR at line 2: 
ORA-06550: line 2, column 25: 
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: 
(- + case mod new not null <an identifier> 
<a double-quoted delimited-identifier> <a bind variable> 
continue avg count current exists max min prior sql stddev 
sum variance execute forall merge time timestamp interval 
date <a string literal with character set specification> 
<a number> <a single-quoted SQL string> pipe 
<an alternatively-quoted string literal with character set specification> 
<an alternat 
ORA-06550: line 2, column 49: 
PLS-00103: Encountered the symbol ";" when expecting one of the following: 
. () , * % & = - + </> at in is mod remainder not rem 
<an exponent (**)> <> or != or ~= >= <= <> and or like like2 
like4 likec between || multiset mem 

工作示例的select into

declare 
    v_dummy varchar2(32767); 
begin 
    -- the select statement can be arbitrary complex as long as it returns 
    -- only one single row with a single column 
    select dummy into v_dummy from dual; 
    dbms_output.put_line(v_dummy); 
end; 
/
相關問題