1. Oracle自带列转行函数listagg: 实例: with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nation ,'New York
转自:http://bbs.csdn.net/topics/370033478 对于Oracle中分页排序查询语句执行效率的比较分析 作者:lzgame 在工作中我们经常遇到需要在Oracle中进行分页.排序.查询的组合SQL语句,举例来说,通常我们会这样写:(假定表test中id是主键,并且id从1开始没有间断顺序排列) 1. SELECT * FROM ( SELECT id,a1,a2,a3,a4,a5,a6,a7,a8,a9, ROWNUM AS rn FROM test
查询条件: 1)LIKE:模糊查询,需要借助两个通配符,%:表示0到多个字符:_:标识单个字符. 2)IN(list):用来取出符合列表范围中的数据. 3)NOT IN(list): 取出不符合此列表中的数据记录. 4)BETWEEN…AND…:用来查询符合某个值域范围条件的数据,最常见的是使用在数字类型的数据范围上,但对字符类型和日期类型数据也同样适用.for example: SELECT ename, sal FROM emp WHERE sal BETWEEN 1500 AND 3000
通常情况下,Oracle数据库禁止在行级触发器或行级触发器所调用的子程序中使用查询语句.但是,面对复杂的业务逻辑,不可避免的要使用查询语句. 当在行级触发器中使用查询语句时,Oracle数据库会抛出ORA-04091异常. Oracle官方文档中对ORA-04091异常的说明如下: ORA-04091: table string.string is mutating, trigger/function may not see it Cause: A trigger (or a user defi
sqlplus / as sysdbaSQL>select status from v$instance;1.查看最大连接数show parameter processes;2.查询oracle的连接数select count(*) from v$session;2.查询oracle的并发连接数select count(*) from v$session where status='ACTIVE';3.查看不同用户的连接数select username,count(username) from
最近编码过程中出现了group by后,某些列会有多个值,而我需要把这些多个值的列进行拼接的情况,和大家分享一下. 有如下表student: 我们希望以class分组,每组的信息平铺,效果如下 分组首先想到的肯定是group by: select * from student s group by s.class; 我们会发现这样会报错,因为name和age有多个值,这个时候我们就可以使用wm_concat()方法来解决. select wm_concat(s.name),wm_concat(s
查看所有数据文件(dbf文件)的存放位置 SQL> select name from v$datafile; 标红色的为默认表空间文件 SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- /home/oracle/app/oracle/oradata/helowin/system01.dbf /home/or
WITH L AS ( ), m AS ( SELECT A.LV AS LV_A, B.LV AS LV_B, TO_CHAR(B.LV) || 'x' || TO_CHAR(A.LV) || '=' || RPAD(TO_CHAR(A.LV , ' ') AS TEXT FROM L A, L B WHERE b.LV <= a.LV ) SELECT listagg( m.text,' ') WITHIN GROUP (ORDER BY m.lv_b ) AS 九九表 FROM m GRO
例子原型: ' ; 运行结果如下: 一.多字段的拼接 将两个或者多个字段拼接成一个字段: ' ; 运行结果: 二.行转列 将某个字段的多行结果,拼接成一个字段,获取拼接的字符串[默认逗号隔开] ' ; 运行结果: , 开拓:如果不想用逗号隔开,可以进行替换: select replace(wm_concat(bkg_num),',','|') from test; 也可以进行分组的拼接: select id,wm_concat(bkg_num) name from test group by i
select B.enterprise_code, B.enterprise_name, sum(B.h0_overnum) AS over00, sum(B.h1_overnum) AS over01, sum(B.h2_overnum) AS over02, sum(B.h3_overnum) AS over03, sum(B.h4_overnum) AS over04, sum(B.h5_overnum) AS over05, sum(B.h6_overnum) AS over06, su