将逗号分割的clob字段转化为varchar,并将字符串拆分为多行
来源:互联网 发布:欧特克软件下载 编辑:程序博客网 时间:2024/05/18 00:42
SELECT '远大洪雨' 企业名称, sgpro.project_name 工程名称, pur.product_type 产品类别, pur.product_name 产品名称, pur.purchase_num 涉及数量, pur.product_regdate 材料进场时间, sgpro.build_licence 施工许可证号, sgpro.contractor_name 总包单位名称 FROM t_purchase_info pur, t_allproject_info sgpro WHERE pur.project_id = sgpro.id AND pur.id in (select distinct regexp_substr(ids, '[^,]+', 1, level) project_id from (select dbms_lob.substr(project_ids) ids from g_enterprise_score where class in (3, 4) and score_type = 5 AND bad_no = 1 AND enterprise_id in (select distinct id from bemms.g_enterprise_info where name like '%远大洪雨%') and project_ids is not null) connect by level <= length(dbms_lob.substr(ids)) - length(replace(dbms_lob.substr(ids), ',', '')) + 1 )
其中,将clob转化为varchar,利用dbms_lob.substr,例:
select dbms_lob.substr(project_ids) from g_enterprise_score where class in (3, 4) and score_type = 5 AND bad_no = 1 AND enterprise_id in (select distinct id from bemms.g_enterprise_info where name like '%远大洪雨%') and project_ids is not null ;
将一行字符串(逗号分割)转化多行,利用regexp_substr() connect by level,例:
select distinct regexp_substr(ids, '[^,]+', 1, level) project_id from (select dbms_lob.substr(project_ids) ids from g_enterprise_score where class in (3, 4) and score_type = 5 AND bad_no = 1 AND enterprise_id in (select distinct id from bemms.g_enterprise_info where name like '%远大洪雨%') and project_ids is not null)connect by level <= length(dbms_lob.substr(ids)) - length(replace(dbms_lob.substr(ids), ',', '')) + 1
以上SQL执行效率特别低,我们欢欢大神说过: 越是高级的函数越有可能影响效率,还是最基础的函数好,效率杠杠的。
其中尽量少用in,用exists,或者instr,经过优化后的SQL如下:
SELECT '北京XXX股份有限公司' 企业名称, sgpro.project_name 工程名称, pur.product_type 产品类别, pur.product_name 产品名称, pur.purchase_num 涉及数量, pur.product_regdate 材料进场时间, sgpro.build_licence 施工许可证号, sgpro.contractor_name 总包单位名称 FROM t_purchase_info pur, t_allproject_info sgpro WHERE pur.project_id = sgpro.id AND instr((select ',' || wm_concat(dbms_lob.substr(g.project_ids)) || ',' ids from g_enterprise_score g where exists (select id from bemms.g_enterprise_info e where g.enterprise_id = e.id and name like '%北京%东方雨虹%') and (g.class = 3 or g.class = 4) and g.score_type = 5 AND g.bad_no = 1 and project_ids is not null), ',' || pur.id || ',') > 0
0 0
- 将逗号分割的clob字段转化为varchar,并将字符串拆分为多行
- Oracle利用SQL将clob字段数据转化为字符串
- 将varchar修改为clob的方法
- 将记录集转换为逗号分割的字符串形式
- 将以逗号隔开的字符串,转化为字符数组并获取每一个的内容
- 将指定字符串拆分为两个字段的记录集
- oracle数据库中使用sql将clob转化为字符串
- Python split() 函数 拆分字符串 将字符串转化为列
- Python split() 函数 拆分字符串 将字符串转化为列
- Python split() 函数 拆分字符串 将字符串转化为列
- 将带有、号的字符串,以逗号分割,然后拼接为SQL语句的WHERE条件
- C++按行读取文本文件,并将每行字符串拆分为double value的坐标值
- 将字符串拆分为数组
- 将varchar2类型的字段修改为clob类型
- 将数值转化为字符串的函数
- 将数值转化为字符串的函数
- 将文件转化为字符串的方法
- SQL将datetime转化为字符串并截取字符串
- LeakCanary:检测你APP所有的内存泄露
- 袁文雪-1323110839-仿微博界面布局
- 有意思的数学基础面试题
- mysql初始化修改root用户密码,mysqladmin: Can't turn off logging; error: 'Access denied; you need the SUPER pri
- 通过数据库链导出遇到ORA-39126错误
- 将逗号分割的clob字段转化为varchar,并将字符串拆分为多行
- iframe直接调用第三方网站的天气预报
- 测试你的液晶显示器是8bit还是6bit (附测试图)(更新为GIF动画测试)
- 插入法排序
- [Accessibility] Missing contentDescription attribute on image
- spring配置文件xsi:schemaLocation无法解析导致启动失败的解决方案
- C语言条件编译及编译预处理阶段(__LINE__)
- Unity中碰撞体和触发器的区别
- 第八周项目一-实现复数类的运算符重载(3)