Create or Replace package ref_types
AS
TYPE ref_cursor is REF CURSOR;
End;
/
Create or Replace package userinfo as
procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
);
/Create or Replace package body userinfo as
procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
) is
v_sqltext varchar2(100);
v_sql varchar2(300);
begin
baduser:=FALSE;
v_sqltext:='''A001'',''A002'',''A003''';
v_sql:='select MENUID,P_NAME from MENU_LIST
where MENUID in (';
v_sql:=v_sql||v_sqltext||') order by MENUID asc';
--注:v_sqltext本来是要经过一个过程计算出来的
open t_menu FOR v_sql;
end;
end;
/
AS
TYPE ref_cursor is REF CURSOR;
End;
/
Create or Replace package userinfo as
procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
);
/Create or Replace package body userinfo as
procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
) is
v_sqltext varchar2(100);
v_sql varchar2(300);
begin
baduser:=FALSE;
v_sqltext:='''A001'',''A002'',''A003''';
v_sql:='select MENUID,P_NAME from MENU_LIST
where MENUID in (';
v_sql:=v_sql||v_sqltext||') order by MENUID asc';
--注:v_sqltext本来是要经过一个过程计算出来的
open t_menu FOR v_sql;
end;
end;
/
解决方案 »
- 起机器都出现下列这个问题提示?
- 如何将一行数据从最后一个datablock移到第一个datablock
- 问一个oracle查询语句~
- 一个关于安装orache9i的问题!
- 用OEM进行数据导出时出现下列错误"couldn't open "D:/ORACLE/ORADATA/ORCL/EXPORT.LOG": no such file or directory",why?有些配置都配了
- PB与Oracle的连接问题
- 一个sql算法问题
- 字符集us7ascii和zhs16gbk(在线)
- win2000下和Oracle8.17下,SQLLDR能用,为什么在win98和Oracle8。05下不能使用。在线等待!
- 存储过程怎么判断执行成功??
- 请问如何查看Oracle的SQL语句操作提示?
- 表 t1 ,字段 c1 ,c1不是主键所以值有重复。要选择c1的值(不重复),SQL语句如何写?拜托!
procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
);
End;
/--少写了一个End,是笔误
AS
TYPE ref_cursor is REF CURSOR;
End;
/create or replace procedure Get_usermenu (baduser out boolean,
t_menu out ref_types.ref_cursor
) is
v_sqltext varchar2(100);
v_sql varchar2(300);
begin
baduser:=FALSE;
v_sqltext:='''A001'',''A002'',''A003''';
v_sql:='select MENUID,P_NAME from MENU_LIST
where MENUID in (';
v_sql:=v_sql||v_sqltext||') order by MENUID asc';
--注:v_sqltext本来是要经过一个过程计算出来的
open t_menu FOR v_sql;
end Get_usermenu;
我的理解是:
你将我的Package改写为Procedure,
但是执行时还是在
open t_menu FOR v_sql;
处报错。
这样吧:
v_sqltext:='(''A001'',''A002'',''A003'')';
v_sql:='select MENUID,P_NAME from MENU_LIST
where MENUID in ';
v_sql:=v_sql||v_sqltext||'order by MENUID asc';
我本意是希望可以同时使用游标指针和动态SQL,可能是没有找到正确的途径,以上的open t_menu FOR v_sql;根本无法执行,
即使是我直接这样写:
v_sql:='……';
open t_menu FOR v_sql;
也不行。
不知道该怎样写,我在OTN上还是没有找到相关的资料。
rem 动态SQL的例子
CREATE OR REPLACE PROCEDURE "SYS"."STATS_TABLE" (schema_name
char,table_name char,cursor_num integer)is
v_rownum number;
begin
if dbms_sql.is_open(cursor_num) then
dbms_sql.parse(cursor_num,'alter table '||schema_name||'.'||table_name||' move tablespace',dbms_sql.native);
v_rownum := dbms_sql.execute(cursor_num);
end if;
exception when others then
dbms_output.put_line('表:'||schema_name||'.'||table_name||' 不存在');
end;
/
CREATE OR REPLACE PROCEDURE "SYS"."STATS" (schema_name char)is
v_cursor integer;--to execute dynamic sqlcursor c_table_name is--get all table names owned by schema
select table_name from dba_tables
where owner=schema_name;v_table_name c_table_name%ROWTYPE;cursor c_index_name is--get all index names owned by schema
select index_name from dba_indexes
where owner=schema_name;v_index_name c_index_name%ROWTYPE;begin
v_cursor:=dbms_sql.open_cursor;--create the cursor
dbms_output.put_line('打开了公共游标');
open c_table_name;--get tables
loop
FETCH c_table_name into v_table_name;
exit when c_table_name%NOTFOUND;
--do something
end loop;
close c_table_name; open c_index_name;--get indexs
loop
FETCH c_index_name into v_index_name;
exit when c_index_name%NOTFOUND;
--do something
end loop;
close c_index_name; dbms_sql.close_cursor(v_cursor);
dbms_output.put_line('关闭了公共游标');
dbms_output.put_line('完成了分析过程');
exception
when others then
if dbms_sql.is_open(v_cursor) then
dbms_sql.close_cursor(v_cursor);
end if;end;
如:v_sql:='select MENUID,P_NAME from MENU_LIST'
v_sql:='select MENUID,P_NAME from MENU_LIST';
然后再使用
open t_menu FOR v_sql;
调用也不行,也是Ora-01001的错误,
除非我这样写:
open t_menu FOR select MENUID,P_NAME from MENU_LIST;
这样可以得到正确的结果。这样看来,似乎是open t_menu FOR v_sql;这一句没有正确的解析。
我的数据库版本是 Oracle 8i (8.1.7.4.0)
按道理来讲应该是可以的……
Cause: Either a host language program call specified an invalid cursor or the value of the MAXOPENCURSORS option in the precompiler command were too small. All cursors must be opened using the OOPEN call before being referenced in any of the following calls: SQL, DESCRIBE, NAME, DEFINE, BIND, EXEC, FETCH, and CLOSE. The Logon Data Area (LDA) must be defined by using OLON or OLOGON. If the LDA is not defined, this message is issued for the following calls: OPEN, COM, CON, ROL, and LOGOFF.Action: Check the erroneous call statement. Specify a correct LDA area or open the cursor as required. If there is no problem with the cursor, it may be necessary to increase the MAXOPENCURSORS option value before precompiling.
而且现在就我在使用。