2个sql 函数dbms_lob.substr 和 wm_concat
转自:
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
######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
- SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmctab.plb;
- SQL>@$ORACLE_HOME\RDBMS\ADMIN\owmaggrs.plb
- 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的更多相关文章
- Oracle 中的sql函数以及分页
SELECT LPAD(,'*.') "LPAD example" FROM DUAL; 1.分页查询 (1)方法一:使用 between and 来实现分页 select * ...
- Oracle 内置sql函数大全
F.1字符函数--返回字符值 这些函数全都接收的是字符族类型的参数(CHR除外)并且返回字符值.除了特别说明的之外,这些函数大部分返回VARCHAR2类型的数值.字符函数的返回类型所受的限制和基本数据 ...
- oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数
花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...
- Oracle数据库--SQL函数
Oracle SQL函数 1.ASCII返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii( ...
- 常用的sql函数
常用的sql函数 concat('hello','world') 结果:helloworld 作用:拼接 substr('helloworld',1,5) hello ...
- oracle内置sql函数(转)
转自:http://www.cnblogs.com/yening10000/archive/2009/07/02/1515284.html F.1字符函数——返回字符值 这些函数全都接收的是字符族类型 ...
- oracle的sql函数
只读事务set transaction read only当一个用户添加了只读事务,则查询时只会查到设置只读事务之前的内容,在并发量大的系统中,通过设置只读事务 便于统计 oracle的sql函数的使 ...
- Oracle SQL函数之字符串函数
1.SQL> ) from dual; --ASCLL(x)返回x的ASCLL码,CHR(x)返回ASCLL码为x的字符 ASCII() ---------- ---------- ------ ...
- DB2开发系列之三——SQL函数
1.内置函数分类(SYSIBM模式内) 1)标量函数:返回一个标量值的函数: 2)聚合函数:也叫列函数,也返回一个标量值,这个值是一组输入值的计算结果:3)表函数:向引用它的 SQL 语句返回一个表: ...
随机推荐
- 数据结构之 图论---最小生成树(prim + kruskal)
图结构练习——最小生成树 Time Limit: 1000MS Memory limit: 65536K 题目描述 有n个城市,其中有些城市之间可以修建公路,修建不同的公路费用是不同的.现在我们想知 ...
- BZOJ_1671_[Usaco2005 Dec]Knights of Ni 骑士_BFS
Description Bessie is in Camelot and has encountered a sticky situation: she needs to pass through t ...
- OTL之Oracle开发总结《转》
OTL之Oracle开发总结---转 关 于OTL,网上介绍的也不少,但看来看去也只是官方的那些文档.OTL很好用,结合官方提供的一些例子,多多尝试才能领悟.经过一个月左右的项目开发,对 OTL也 ...
- bzoj 4589 Hard Nim —— FWT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4589 先手必败,是一开始所有石子的异或和为0: 生成函数 (xpri[1] + xpri[2 ...
- This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended
VS2005转换成VS2010时出现的问题: This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x05 ...
- cobbler api
try: import xmlrpclib except ImportError as e: import xmlrpc.client SERVER_IP = '192.168.144.11' try ...
- 简单易用"里程碑"、"时间轴"<iOS小组件>
非常感谢,帮助我的朋友们,谢谢你们.上次我的好朋友指出了我编码上(jwTextFiled工具组件)存在一些不规范问题,这次注意提高. 呆毛地址:https://github.com/NIUXINGJI ...
- 1.5 Hive初步使用和安装MySQL
一.HQL初步试用 1.创建一个student表 #创建一个student表 hive> create table student(id int, name string) ROW FORMAT ...
- appium版本之谜
关于appium网上提到的版本是一头雾水,现解释如下: 首先,官网下载的 appium-desktop-Setup-1.3.1.exe是appium桌面版,将appium服务器配置可视化. 而网上提到 ...
- python--flask学习1
1 windows/unix得安装 http://www.pythondoc.com/flask-mega-tutorial/helloworld.html http://www.pythondoc. ...