2016-11-16 53 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; 
/
相关问题