易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

Exam : Oracle 1Z0 051

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 ......

ORACLE GROUPING函数的使用

GROUPING函数可以接受一列,返回0或者1。如果列值为空,那么GROUPING()返回1;如果列值非空,那么返回0。GROUPING只能在使用ROLLUP或CUBE的查询中使用。当需要在返回空值的地方显示某个值时,GROUPING()就非常有用。
关于ROLLUP和CUBE函数的使用,请参见我的另一篇文章。
http://blog.csdn.net/wh62592855/archive/2009/1 ......

Oracle 11g 忘记用户名密码解决办法(转)

情况描述:安装时选择的自动安装,由于时间久远忘记用户名、密码了,导致现在试了几个默认的用户名密码后,都提示无效的用户名、密码。
解决方法:启动SQLPLUS,提示输入用户名,然后输入sqlplus/as sysdba,密码为空。提示连接到信息,连接成功!
执行alter user sys identified by 密码;
设置成功!
现在可以从Enterp ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号