在存储过程中要完成如下操作:
1,建一个临时表
2,相表中添加一些记录
3,返回查询临时表的记录集
4,删除临时表
我做了一个过程,但是不能执行,不知道为什么,请大家帮帮忙!
procedure nt(a in int, b in varchar2, c in varchar2, retcur out curtype) is
strsql varchar2(1000);
begin
strsql :=' CREATE GLOBAL TEMPORARY TABLE tmp
(
id int;
name char(8);
)ON COMMIT DELETE ROWS';
execute immediate strsql;strsql := 'insert into tmp(id,name) values('|| to_char(a)||','''||b||''')';
execute immediate strsql;
open retcur for
select * from tmp where tmp.id = a;
strsql :='drop table tmp';
execute immediate strsql;
end nt;
错误提示是ORA-06508: PL/SQL: could not find program unit being called
请问如何解决这个问题呢?
1,建一个临时表
2,相表中添加一些记录
3,返回查询临时表的记录集
4,删除临时表
我做了一个过程,但是不能执行,不知道为什么,请大家帮帮忙!
procedure nt(a in int, b in varchar2, c in varchar2, retcur out curtype) is
strsql varchar2(1000);
begin
strsql :=' CREATE GLOBAL TEMPORARY TABLE tmp
(
id int;
name char(8);
)ON COMMIT DELETE ROWS';
execute immediate strsql;strsql := 'insert into tmp(id,name) values('|| to_char(a)||','''||b||''')';
execute immediate strsql;
open retcur for
select * from tmp where tmp.id = a;
strsql :='drop table tmp';
execute immediate strsql;
end nt;
错误提示是ORA-06508: PL/SQL: could not find program unit being called
请问如何解决这个问题呢?
解决方案 »
- 请教:A库imp到新库B的准备工作
- 求助!存储过程中没有参数时怎么写?
- linux 安装oracle10g 写入目录/tmp 时出错
- 提取个日期吧?
- 如何在存储过程中使用dbms_output.put_line输出出错的sql语句!!
- SQL语法问题
- TNSNAMES.ORA里的SERVICE_NAME到底是数据库中哪里设置的啊,服务名是指什么
- vc ado + oracle 开发 ,一次入2G 数据到一半数据量时客户端cpu利用率100% 就不再入数据了,在线等。。急。。。
- 安装oracle总是报错,我想这个错误大家都没见过
- 如何通过oci调用带ref cursor类型参数的函数?
- 如何编写触发器向另外一个数据库写数据
- 关于中间层如何编写,思路如何,涉及哪些知识!
14:48:16 2 c in varchar2, retcur out curtype) is
14:48:16 3 strsql varchar2(1000);
14:48:16 4 begin
14:48:16 5 strsql :=' CREATE GLOBAL TEMPORARY TABLE tmp(id int,name char(8)) ON COMMIT DELETE ROW
S';
14:48:16 6 execute immediate strsql;
14:48:16 7
14:48:16 8 strsql := 'insert into tmp(id,name) values('|| to_char(a)||','''||b||''')';
14:48:16 9 execute immediate strsql;
14:48:16 10 open retcur for
14:48:16 11 select * from tmp where tmp.id = a;
14:48:16 12 strsql :='drop table tmp';
14:48:16 13 execute immediate strsql;
14:48:16 14 end;
14:48:16 15 /警告: 创建的过程带有编译错误。已用时间: 00: 00: 00.01
14:48:18 jlanzpa817>sho err
PROCEDURE NT 出现错误:LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
2/27 PLS-00201: 必须说明标识符 'CURTYPE'
create or replace package ntest is
type curtype is ref cursor;
procedure nt(a in int, b in varchar2, c in varchar2, retcur out curtype);
end ntest;
/
create or replace package body ntest is
procedure nt(a in int, b in varchar2, c in varchar2, retcur out curtype) is
strsql varchar2(1000);
begin
strsql :=' CREATE GLOBAL TEMPORARY TABLE tmp
(
id int;
name char(8);
)ON COMMIT DELETE ROWS';
execute immediate strsql;strsql := 'insert into tmp(id,name) values('|| to_char(a)||','''||b||''')';
execute immediate strsql;
open retcur for
select * from tmp where tmp.id = a;
strsql :='drop table tmp';
execute immediate strsql;
end nt;
end ntest;
retcur out curtype 有和错误?我觉得错误应在临时表上,是不是临时表被删除之后,就不能返回基于他的查询的记录集?
(
id int;
name char(8);
)ON COMMIT DELETE ROWS';
execute immediate strsql;语法不对,不能多行写.临时表被删除之后,就不能返回基于他的查询的记录集了.
说举公道话,
您这种做法
1,建一个临时表
2,相表中添加一些记录
3,返回查询临时表的记录集
4,删除临时表
不合适,您是受了SYBASE
SQLSERVER
等数据库的影响了
在ORACLE
中临时表想永久表一样创建,
您在过程中只需2,3步就可以了
不知道能不能动态open cursor.
我是一个初学者,你说临时表没有创建,那就是说这句话没有执行:
strsql :=' CREATE GLOBAL TEMPORARY TABLE tmp
(
id int;
name char(8);
)ON COMMIT DELETE ROWS';
execute immediate strsql;
为什么没有执行呢?那如何能创建临时表呢?
我觉得楼主应该想点其他的方法,比如说事先把需要的表建好,用前用后都倾空表,不就OK了。方法太笨了,想点其他方法也行,条条大路同罗马嘛!
说举公道话,
您这种做法
1,建一个临时表
2,相表中添加一些记录
3,返回查询临时表的记录集
4,删除临时表
不合适,您是受了SYBASE
SQLSERVER
等数据库的影响了
在ORACLE
中临时表想永久表一样创建,
您在过程中只需2,3步就可以了