2011-02-16 28 views
2

我有l_vc_rowid被定義爲VARCHAR2(10)這個查詢是否需要PL SQL查詢[執行立即]

EXECUTE IMMEDIATE 'UPDATE ' || dest || ' SET COUNTRY_CODE = :v1 WHERE col_id = :v2 returning rowid into :out' 
      USING l_vc_CountryCode, l_vc_ColId 
      returning into l_vc_rowid; 

幫助;

我想谷歌,但找不到問題。

+0

什麼與您的查詢的問題,你得到一個錯誤信息?哪一個? – jachguate 2011-02-16 22:59:24

+0

有點深入研究這個問題讓我意識到錯誤是*** RETURNING ***不支持的功能。我只想知道給定的值是否已更新,我不想使用單獨的select語句。有任何想法嗎? – 2011-02-16 23:04:20

回答

4

使用sql%rowcount來確定有多少行受到更新的影響。

利用有效的PL/SQL函數:

create table tq84_update_test (
    country_code number, 
    col_id  varchar2(10) 
); 


create or replace 
function tq84_update_func (dest   in varchar2, 
          col_id  in varchar2, 
          country_code in number 
          ) 
return varchar2 
as 
begin 

    execute immediate 
'update ' || dest || ' set country_code = :v1 ' || 
'where col_id = :v2' 
    using country_code, col_id; 

    return sql%rowcount || ' rows updated'; 
end tq84_update_func; 
/


insert into tq84_update_test values (4,'Italy'); 

exec dbms_output.put_line(tq84_update_func('tq84_update_test', 'foo', 2)); 

exec dbms_output.put_line(tq84_update_func('tq84_update_test', 'Italy', 9)); 

select * from tq84_update_test;