是否需要PL SQL查询[执行立即]
问题描述:
我有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;
帮助;
我想谷歌,但找不到问题。
答
使用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;
什么与您的查询的问题,你得到一个错误信息?哪一个? – jachguate 2011-02-16 22:59:24
有点深入研究这个问题让我意识到错误是*** RETURNING ***不支持的功能。我只想知道给定的值是否已更新,我不想使用单独的select语句。有任何想法吗? – 2011-02-16 23:04:20