Oracle中合并字符串总结
在数据库中经常要合并字符串,而合并字符串的方法有很多,现在总结如下:
--创建会话级临时表
create global temporary table TMPA
(
ID INTEGER,
NAME VARCHAR2(10)
)
on commit preserve rows;
--插入记录
insert into tmpa select 1,'aa' from dual;
insert into tmpa select 1,'bb' from dual;
insert into tmpa select 1,'cc' from dual;
insert into tmpa select 2,'dd' from dual;
insert into tmpa select 2,'ee' from dual;
insert into tmpa select 3,'ff' from dual;
commit;
--1、sys_conect_by_path方法
select id,max(ltrim(sys_connect_by_path(name,','),',')) as group_name
from
(
select a.*,row_number()over(partition by id order by name) as row_num
from tmpa a
) a
group by id
start with row_num=1
connect by prior id=id and prior row_num= row_num-1
--2、wm_concat方法
select id,wm_concat(name) as group_name from tmpa
group by id;
--3、自定义函数法
--定义函数
create function group_concat(vid number)
return varchar2
as
vResult varchar2(100);
begin
for cur in (select name from tmpa where id=vid) loop
vResult := vResult||cur.name;
end loop;
return vResult;
end;
--查询
select id,group_concat(id) as group_name from tmpa
group by id;
--查询的结果
ID GROUP_NAME
1 aa,bb,cc
2 dd,ee
3 ff
相关文档:
oracle表空间操作详解
1
2
3作者: 来源: 更新日期:2006-01-04
5
6
7建立表空间
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
ORACLE没有象SQL SERVER中一样的自增加字段,要实现只能通过SEQUENCE来实现
1.创建序列:
create sequence your_seq
nocycle
maxvalue 9999999999
start with 1;
2.使用触发器实现自增:
create or replace trigger your_seq_tri
before insert on your_table1 for each row
declare
next_id number;
begin
se ......
ORACLE培训(OCA)认证介绍
Oracle10g Certified Associate (OCA) Oracle 认证专员。
考试成绩通过能获得Oracle公司为您颁发的全球认证的英文OCA证书。OCA由Oracle公司出题。
该证书可作为各企事业单位数据库管理人员上岗的依据。
目前已成为各IT公司及相关企业争相竞聘的数据库管理维护人才,是数据库维护管理人员(DBA) ......
Exam : Oracle 1Z0-051
Title : Oracle Database: SQL Fundamentals I
1. View the Exhibit to examine the description for the SALES table.
Which views can have all DML operations performed on it? (Choose all that apply.)
A. CREATE VIEW v3
AS SELECT * from SALES
WHERE cust_id = 2034
WITH CHECK OPTI ......
GROUPING函数可以接受一列,返回0或者1。如果列值为空,那么GROUPING()返回1;如果列值非空,那么返回0。GROUPING只能在使用ROLLUP或CUBE的查询中使用。当需要在返回空值的地方显示某个值时,GROUPING()就非常有用。
关于ROLLUP和CUBE函数的使用,请参见我的另一篇文章。
http://blog.csdn.net/wh62592855/archive/2009/1 ......