加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

How cool it is!

(2010-09-30 01:00:17)
标签:

it

oracle

database

在oracle中把连串字符转变为table fields,原来要做loop很麻烦,现在用expression就行了。

 

真爽!特此记录,怕以后忘了,呵呵。

 

if A_PROSPECTIDS is not null

then

 

-- remove from ua_r0095_prospects_main any not in list of ids:

T_UPDATESQL := 'delete from ua_r0095_prospects_main pm where pm.id_number

not in (( select lpad(trim(regexp_substr(a_prospectids,'[^,]+{1}',1,level)), 10, 0) ids from dual

connect by level <= length(regexp_replace(a_prospectids,'[^,]*'))+1 ) ';

 

execute immediate T_UPDATESQL;

 

commit;

 

exception

when others then

RAISE_APPLICATION_ERROR(-20999,

'ua_r0095_priority_prospects: Error removing prospects: ' ||

sqlcode || ': ' || sqlerrm);

end;

end if;

 

外在用动态的SQL (dynamic SQL)时, 变量要用加串,两个双引号相当于一个单引号:

lpad(trim(regexp_substr(' ||''''|| t_formattedids ||'''' || ',' || '''' || '[^,]+{1}' || '''' || ',1,level)), 10, 0) ids from dual

connect by level <= length(regexp_replace(' ||''''|| t_formattedids ||'''' || ',' || '''' || '[^,]*' || '''' || '))+1

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有