http://topic.csdn.net/u/20080416/11/910e40c1-60f1-441f-8b0f-19a969d30f77.html
这个里面,你的例子是可用的。
我想问下返回游标不定列的时候,
PL/SQL中如何把值显式出来?
JAVA中如何显式出来?
我只会写固定列的。
下面是我写的。我把你例子改成只出来2列的了,1列是XH,1列是剩下的
declare
id VARCHAR2(10);
id2 varchar2(100);
cursor1 sp_test.ResultData ;
begin
sp_test.getRstData (cursor1);
loop
fetch cursor1 into id,id2;
exit when cursor1%notfound;
dbms_output.put_line(id||'---'||id2);
end loop;
end;
这个里面,你的例子是可用的。
我想问下返回游标不定列的时候,
PL/SQL中如何把值显式出来?
JAVA中如何显式出来?
我只会写固定列的。
下面是我写的。我把你例子改成只出来2列的了,1列是XH,1列是剩下的
declare
id VARCHAR2(10);
id2 varchar2(100);
cursor1 sp_test.ResultData ;
begin
sp_test.getRstData (cursor1);
loop
fetch cursor1 into id,id2;
exit when cursor1%notfound;
dbms_output.put_line(id||'---'||id2);
end loop;
end;
解决方案 »
- sql命令连接符??
- 备份system表空间的问题
- 两表组合查询
- PL/SQL 用其自带的PL/SQL DEVELOPER 导入dmp文件时发现数据丢失
- 9i用Enterprise Manager Console导出数据库出现"ora-00972 标识过长"问题,求救!
- 在windows下 如何用rman 进行自动定时备份??
- 求行列转化sql语句?
- oracle数据库如何生成sql语句?
- 创建数据库的时候,创建到60%的时候出现ORA-02084????这样错误提示(急啊,在线)
- 为什么不能登陆ORACLE Manage Server
- 数据库标志位字段用CHAR(2)还是INT的困惑?
- 帮忙
确切的将是一个分组变幻的问题。
思路
CURSOR CSR IS select distinct course from 成绩表 order by course ;
动态创建临时表
loop
colstr := 'sid varchar2(10)';
loop
fetch CSR into tmpstr;
exit when csr%notfound;
colstr := colstr || temstr ||', varchar2(50) ';
end loop;
execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (' ||
colstr || ')ON COMMIT delete ROWS';
重新按照分组查询成绩表
rlt 成绩表%rowtype;
type Crd is record (ky varchar2(10),val varchar2(100));
rd Crd;
type tmprt is table of varchar2(10) index by binary_integer;
tt tmprt;
sssid varchar2(10);
sqltmp varchar2(4000);
coltmp varchar2(4000);
valtmp varchar2(4000);
lp number;
cursor C1 is select id,sid,course,result from 成绩表 order by sid,course ;
loop
fetch c1 into rlt;
exit when c1%notfound;
if sssid is null then
sssid:=rlt.sid;
lp :=0;
else
if sssid <> rlt.sid then
sqltmp := 'insert into T_TEMP(';
coltmp :='sid';
valtmp := ' values ( ' || sssid;
loop
exit when loop < 0;
coltmp := coltmp || ', ' || rd(lp).ky;
valtmp := valtmp || ', ' || rd(lp).val;
lp := lp -1;
end loop;
sqltmp = sqltmp || coltmp || ') ' || valtmp || ' ) ';
execute immediate sqltmp;
lp:=0;
else
rd(lp).ky := course;
rd(lp).val := result;
lp := lp +1;
end if
end if;
end loop;
显式出来那个结果我在procedure 建表,怎么没权限?直接建表是可以的,缺什么权限啊?
--(C) 版权所有 1985-2001 Microsoft Corp.C:\Documents and Settings\molanzhou>sqlplus/nolog--SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 4月 17 16:54:31 2008--Copyright (c) 1982, 2005, Oracle. All rights reserved.SQL> conn okiwmshistory/okiwmshistory@mytmsdb
--已连接。
SQL> var cur refcursor;
SQL> begin
2 sp_test.getrstdata(:cur);
3 end;
4 /--PL/SQL 过程已成功完成。SQL> print :cur;XH 20080417 20080418 20080419
---------- ---------- ---------- ----------
1 10 14 23
2 21 24 0
3 13 22 0SQL>
我一直用的是pl/sql dev的command命令窗口写的,换成sqlplus就好了.
我用pl/sql dev的command,有错 Cursor variable :CUR cannot be nil我以前一直认为这2个是一样的,今天才发现这个区别。那我想把值用java取出来怎么写?
类似的例子倒是知道不少。
PL/SQL 我也用过了,没有发现异常.
应该是一样的.SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 4月 17 17:41:02 2008Copyright (c) 1982, 2005, Oracle. All rights reserved.
连接到:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - ProductionSQL> var cur refcursor;
SQL> begin
2 sp_test.getrstdata(:cur);
3 end;
4 /PL/SQL 过程已成功完成。SQL> print :cur;XH 20080417 20080418 20080419
---------- ---------- ---------- ----------
1 10 14 23
2 21 24 0
3 13 22 0SQL>
REFCURSOR not supported
游标就定义不起来,非要在sqlplus里面
这个原因是什么?
create table curTest(i number);
--测试数据
insert into curTest select 1 from dual union all select 2 from dual;
--测试包
create or replace package sp_test is
type ResultData is ref cursor;
procedure getcurTest(rst out ResultData);
end sp_test;
/
create or replace package body sp_test is
procedure getcurTest(rst out ResultData) is
begin
open rst for select * from curTest;--返回curTest的内容
end;
end sp_test;
/
--调试包中的getcurTest
declare
cur sp_test.ResultData;
i number;
begin
sp_test.getcurTest(cur);
loop
fetch cur into i;
exit when cur%notfound;
dbms_output.put_line(i);
end loop;
end;
--输出结果
1
2
一起研究下
declare
l_cur number;
l_stmt varchar2(2000);
l_dtbl dbms_sql.desc_tab;
l_cnt number;
l_status number;
l_val varchar2(200);
begin
l_cur := dbms_sql.open_cursor;
l_stmt := 'select * from curTest';
dbms_sql.parse(l_cur,'select * from curTest',dbms_sql.native);
dbms_sql.describe_columns(l_cur,l_cnt,l_dtbl);
for i in 1..l_cnt loop
dbms_sql.define_column(l_cur,i,l_val,30);
end loop;
l_status := dbms_sql.execute(l_cur);
while ( dbms_sql.fetch_rows(l_cur) > 0 ) loop
for i in 1..l_cnt loop
dbms_sql.column_value(l_cur,i,l_val);
dbms_output.put_line(l_dtbl(i).col_name||' --> '||l_val);
end loop;
end loop;
dbms_sql.close_cursor(l_cur);
end;
http://www.oracle.com/technology/oramag/code/tips2003/042003.html
我英文不好,看不懂那东西....还有就是
还有就是sqlplus和pl/sql dev有区别吗?
区别在哪?因为我以前认为没区别
还有就是sqlplus和pl/sql dev的command window有区别吗? 我在sqlplus可以var cur refcursor;
在pl/sql dev的command window可以