转自:

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
 
 
issue 1:ORA-0103

######1
SELECT TRIM(DBMS_LOB.SUBSTR(WM_CONCAT(ABC))) DATAVAL
*
ERROR at line 63:
ORA-01031: insufficient privileges

###########2
select wm_concat('aaa') from dual;

*
ERROR at line 1:
ORA-01031: insufficient privileges

###### fix  3:

grant execute on wm_concat to Dbmonopr;

#########re-create function

scp owmctab.plb owmaggrs.plb owmaggrb.plb admin@25.16.1.1:/tmp/dba

  1. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmctab.plb;
  2. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmaggrs.plb
  3. SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmaggrb.plb

####

WMSYS Packages/Functions missing on 12c (文档 ID 2368194.1)

There are WMSYS functionalities that are gone in 12c, while available in 11g.

Please find the list of missing ones below, they all belong to WMSYS Owner

select * from SYS.DBA_TAB_PRIVS WHERE PRIVILEGE = 'EXECUTE' and OWNER = 'WMSYS';
WM_CONCAT_IMPL
WM_CONCAT
WM$GETDBVERSIONSTR
WM$DISALLOWQNDML
WM$CONVERTDBVERSION
OWM_9IP_PKG

Is there any change, new function or substitute for using this on Oracle 12c with WMSYS?

SOLUTION

All of those packages/functions are meant for internal use only and should not be used by customers. This is expected behavior for 12g. Some of them were dropped, others were moved into a package.

WM_CONCAT : Use listagg.
WM$GETDBVERSIONSTR : Use the v$version view or the dbms_utility.db_version procedure.
WM$DISALLOWQNDML : All this does is unconditionally raise an error. Create a procedure that raises a similar error.
WM$CONVERTDBVERSION : No alternative. Would need to write their own procedure to do the version substitution.
OWM_9IP_PKG : They should not be directly altering the session context used by Workspace Manager.

2个sql 函数dbms_lob.substr 和 wm_concat的更多相关文章

  1. Oracle 中的sql函数以及分页

    SELECT LPAD(,'*.') "LPAD example" FROM DUAL; 1.分页查询 (1)方法一:使用  between  and 来实现分页 select * ...

  2. Oracle 内置sql函数大全

    F.1字符函数--返回字符值 这些函数全都接收的是字符族类型的参数(CHR除外)并且返回字符值.除了特别说明的之外,这些函数大部分返回VARCHAR2类型的数值.字符函数的返回类型所受的限制和基本数据 ...

  3. oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数

        花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...

  4. Oracle数据库--SQL函数

    Oracle SQL函数  1.ASCII返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii( ...

  5. 常用的sql函数

    常用的sql函数 concat('hello','world') 结果:helloworld  作用:拼接 substr('helloworld',1,5)      hello           ...

  6. oracle内置sql函数(转)

    转自:http://www.cnblogs.com/yening10000/archive/2009/07/02/1515284.html F.1字符函数——返回字符值 这些函数全都接收的是字符族类型 ...

  7. oracle的sql函数

    只读事务set transaction read only当一个用户添加了只读事务,则查询时只会查到设置只读事务之前的内容,在并发量大的系统中,通过设置只读事务 便于统计 oracle的sql函数的使 ...

  8. Oracle SQL函数之字符串函数

    1.SQL> ) from dual; --ASCLL(x)返回x的ASCLL码,CHR(x)返回ASCLL码为x的字符 ASCII() ---------- ---------- ------ ...

  9. DB2开发系列之三——SQL函数

    1.内置函数分类(SYSIBM模式内) 1)标量函数:返回一个标量值的函数: 2)聚合函数:也叫列函数,也返回一个标量值,这个值是一组输入值的计算结果:3)表函数:向引用它的 SQL 语句返回一个表: ...

随机推荐

  1. HTML5 Canvas 时钟

    1. [图片] QQ截图20120712130049.png ​2. [代码][HTML]代码 <!DOCTYPE html><html lang="en" &g ...

  2. Java版本更新历史(ing)

    历史版本特性 JDK Version 1.0 开发代号为Oak(橡树),于1996-01-23发行. JDK Version 1.1 于1997-02-19发行. 引入的新特性包括: 引入JDBC(J ...

  3. [USACO 2008 MAR] 土地购买

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1597 [算法] 首先将所有土地按长为第一关键字 , 宽为第二关键字排序 显然 , 当 ...

  4. Update 出现在的问题

    报错提示:之前的操作没有完成,运行deanup被打断,请先执行Cleanup方法. 正常右键点击Cleanup,如果只让默认值勾选,可能还是会报这个错.所以正确操作如下: 全部选中再点击OK,这样就可 ...

  5. R文件报错

    res中drawable中的资源文件进行命名时只能用0-9或者a-z或者-,其他的东西不能使用,也禁止在重命名时开头使用大写字母

  6. 蓝桥杯校内选拔赛/POJ 数独(深搜)

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14530   Accepted: 7178   Special ...

  7. VMware桥接模式选择宿主机物理网卡

    当宿主机有多块物理网卡时,VMware桥接模式也要根据情况选择使用的物理网卡. 比如宿主机有两块物理网卡,一个连外网,一个连内网,如果想与内网组成局域网就需要选择宿主机的内网网卡,反之选择外网网卡,当 ...

  8. ImportCommon

    using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using S ...

  9. AngularJS系统学习之$watch(监控)

    在scope的内置的所有函数中,用的最多的可能就是$watch函数了, 当你的数据模型中某一部分发生变化时,$watch函数可以向你发出通知. 你可以监控单个对象的属性,亦可以监控需要经过计算的结果( ...

  10. mfc给对话框添加背景

    void CMyProjetDlg::OnPaint() { CPaintDC dc(this);//用于绘制设备的上下文 CRect rect; GetClientRect(&rect); ...