用SQL脚本 生成INSERT SQL语句

配置表B 中的数据,可以从A表中查询到,在实际配置时,通过sql脚本生成B表的insert脚本,最多用到的是sql中连接符【||】,以及双引号【''''】

 

例1:电销系统中地区出单机构关系表配置数据生成sql

select
'insert into tbl_area_org_code (area_code,area_name,parent_area_code ,yc_area_code,dept_code,dept_name,area_short_name ,quan_pin,dept_flag, id)
values ( '''',' ||
''''||substr(t.dept_abbr,0,2) ||'''' || ','||
''''|| '' ||'''' || ','||
''''||substr(t.dept_code,0,2) ||'''' || ','||
''''||t.dept_code ||'''' || ','||
''''||t.dept_abbr ||'''' || ',' ||
''''||'简称' ||'''' || ',' ||
''''|| fn_getpy(t.dept_abbr) ||'''' || ',' ||
''''||'1' ||'''' || ',' ||
''''|| AREA_ORG_CODE_SEQUENCE2.NEXTVAL ||'''' ||
');'
from tbl_cs_organization t where t.dept_code in(
'33047702');

 

注意:脚本中用到一个中文转拼音函数,详见:http://blog.csdn.net/stevendbaguo/article/details/22047811

posted @ 2017-09-18 15:29  雨 燕  阅读(2493)  评论(0编辑  收藏  举报