标签:insert from 转换 分享图片 tail 替换 csdn 方法 用法
转自:
http://blog.csdn.net/wenzhongyan/article/details/50315473
http://blog.csdn.net/ojerryzuo/article/details/53927057
1、通过dbms_lob.substr()转换clob字段为varchar2类型
在查询dba_stat_extensions视图的时候,其中extension字段是clob类型,直接通过select语句无法显示,如下:
需要通过dbms_lob.substr()转换
SELECT owner ,a.table_name,trim(dbms_lob.substr(extension,4000)) as extension FROM dba_stat_extensions a 转换后显示如下:
2.
首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以","号分隔起来,并显示成一行,接下来上例子,看看这个神奇的函数如何应用 准备测试数据 SQL> create table test(id number,name varchar2(20)); SQL> insert into test values(1,‘a‘); SQL> insert into test values(1,‘b‘); SQL> insert into test values(1,‘c‘); SQL> insert into test values(2,‘d‘); SQL> insert into test values(2,‘e‘); SQL> commit; 效果1 : 行转列 SQL> select wm_concat(name) from test; WM_CONCAT(NAME) ------------------------------------------------------------------------- a,b,c,d,e 效果2: 把结果里的逗号替换成"|" SQL> select replace(wm_concat(name),‘,‘,‘|‘) from test; REPLACE(WM_CONCAT(NAME),‘,‘,‘|‘) ----------------------------------------------------------------------- a|b|c|d|e 效果3:按ID分组合并name SQL> select id,wm_concat(name) name from test group by id; ID NAME ---------- ------------------------------ 1 a,b,c 2 d,e 懒人扩展用法: 案例:我要写一个视图,类似"create or replace view as select 字段1,...字段50 from tablename" ,基表有50多个字段,要是靠手工写太麻烦了,有没有什么简便的方法? 当然有了,看我如果应用wm_concat来让这个需求变简单 SQL> select ‘create or replace view as select ‘|| wm_concat(column_name) || ‘ from dept‘from user_tab_columns where table_name=‘DEPT‘; ‘CREATEORREPLACEVIEWASSELECT‘||WM_CONCAT(COLUMN_NAME)||‘FROMDEPT‘ -------------------------------------------------------------------------------- create or replace view as select DEPTNO,DNAME,LOC from dept
2个sql 函数dbms_lob.substr 和 wm_concat
标签:insert from 转换 分享图片 tail 替换 csdn 方法 用法
原文地址:http://www.cnblogs.com/feiyun8616/p/7852629.html