declare
sql string(8000);
begin
sql:='select pid,max(case id when '''||id||''' then name else '''' end)'
||' as [''||id||'] from (select distinct id from test) as a'
||' from test group by pid';
end;
sql string(8000);
begin
sql:='select pid,max(case id when '''||id||''' then name else '''' end)'
||' as [''||id||'] from (select distinct id from test) as a'
||' from test group by pid';
end;
解决方案 »
- oracle表的更新时间。
- mount.ocfs2: Device name specified was not found while opening device /dev/sdb2
- oracledbconsoleorcl 不能启动
- oracle里用什么工具可以导入SQL SERVER的数据库?
- 帮我看看这个oracle的sql语句有什么问题??。。。。在线等。。。。。不好意思实在没分了。。。。
- 请问一个插入一行后,自动添加一列的触发器问题,谢谢
- 高分求助,求最大植
- 庆祝论坛重新开放放分,另外问一个Oracle的简单问题。
- 关于ASP+ORACLE FOR OLEDB,能解决问题,给500分也无所谓
- 可以不重装吗?
- oracle数据库打开问题(在线等待)
- 创建新库的问题,大家来看看!!!
create or replace function yzw_sql(
ID varchar2
) return varchar2
is
str_SQL varchar2(8000);
begin
str_SQL := 'select pid,max(decode(id,''' || id || ''',name,''''))'
||' as [' || id ||'] from (select distinct id from test) a'
||' from test group by pid';
return str_SQL;
end;调试:
declare
a varchar2(200);
begin
a := yzw_sql('try');
dbms_output.put_line(a);
end;结果:
select pid,max(decode(id,'try',name,'')) as [try] from (select distinct id from test) a from test group by pid
现有下列记录:
11,AA,100
22, BB,200
33, CC,400
44, DD,500
55, AA,200
66, BB,300
77, EE,800
要得到
ID, AA, BB, CC, DD, EE,合计
11 100 100
22 200 200
33 400 400
44 500 500
55 200 200
66 300 300
77 800 800
请问该语句如何写谢谢