create type ci is record { empno emp.empno% TYPE; ename emp.ename% TYPE; job emp.job% TYPE; mgr emp.mgr% TYPE; hiredate emp.hiredate% TYPE; sal emp.sal% TYPE; comm emp.comm% TYPE; deptno emp.deptno% TYPE; } create type tt is table of ci; commit; declare type tttt is table of ci; ttt tttt; t tt; i int; begin select * BULK COLLECT into ttt from emp; i:=ttt.first; while ttt.exists(i) loop dbms_output.put_line('查找出来的学号empno为:'||ttt(i).empno); i:=ttt.next(i); end LOOP; end; / 我想用oracle的记录表来存储中间结果,但是创建的记录以及记录表在PL/SQL块中无法引用,这让我没法声明函数的返回类型,是不是在PL/SQL里面引用人工创建的object时候要作适当的声明????编译错误如下 错误报告: ORA-06550: 第 2 行, 第 23 列: PLS-00905: 对象 SCOTT.CI 无效 ORA-06550: 第 2 行, 第 1 列: PL/SQL: Item ignored ORA-06550: 第 4 行, 第 3 列: PLS-00905: 对象 SCOTT.TT 无效 ORA-06550: 第 4 行, 第 3 列: PL/SQL: Item ignored ORA-06550: 第 7 行, 第 28 列: PLS-00382: 表达式类型错误 ORA-06550: 第 7 行, 第 32 列: PL/SQL: ORA-00947: 没有足够的值 ORA-06550: 第 7 行, 第 1 列: PL/SQL: SQL Statement ignored ORA-06550: 第 10 行, 第 55 列: PLS-00487: 对变量 'CI' 的引用无效 ORA-06550: 第 10 行, 第 1 列: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: select * from user_types里面可以查到tt,ci对象
create ci as object( 不用%type ); create type ci_list as table of ci; CREATE PROCEDURE myobj_list_test(recs in ci_list, outs out ci_list) IS list ci_list := ci_list(); begin .... end;
Connection con=new OracleConncection().getConnection();
con.setAutoCommit(false);
CallableStatement cs =null;
System.out.println(con==null);
cs = con.prepareCall("{? = call PAC_TEST.FUN_TEST('abc')}");
cs.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
ResultSet rs=(ResultSet) cs.getObject(1);
while (rs.next()){
System.out.println(rs.getString(1));
}
con.commit();
rs.close();
cs.close();
con.close();SQL:
function FUN_TEST(ABC VARCHAR2) return CUR_RS IS
CURR CUR_RS;
begin
INSERT INTO QBTB_XT_HS(C_SYS_TYPE) VALUES(ABC);
OPEN CURR FOR SELECT * FROM QBTB_XT_HS;
RETURN CURR;
end FUN_TEST;
create global temporary table QBTB_XT_HS
(
C_SYS_TYPE VARCHAR2(30)
)on commit delete rows;
{
empno emp.empno% TYPE;
ename emp.ename% TYPE;
job emp.job% TYPE;
mgr emp.mgr% TYPE;
hiredate emp.hiredate% TYPE;
sal emp.sal% TYPE;
comm emp.comm% TYPE;
deptno emp.deptno% TYPE;
}
create type tt is table of ci;
commit;
declare
type tttt is table of ci;
ttt tttt;
t tt;
i int;
begin
select * BULK COLLECT into ttt from emp;
i:=ttt.first;
while ttt.exists(i) loop
dbms_output.put_line('查找出来的学号empno为:'||ttt(i).empno);
i:=ttt.next(i);
end LOOP;
end;
/
我想用oracle的记录表来存储中间结果,但是创建的记录以及记录表在PL/SQL块中无法引用,这让我没法声明函数的返回类型,是不是在PL/SQL里面引用人工创建的object时候要作适当的声明????编译错误如下
错误报告:
ORA-06550: 第 2 行, 第 23 列:
PLS-00905: 对象 SCOTT.CI 无效
ORA-06550: 第 2 行, 第 1 列:
PL/SQL: Item ignored
ORA-06550: 第 4 行, 第 3 列:
PLS-00905: 对象 SCOTT.TT 无效
ORA-06550: 第 4 行, 第 3 列:
PL/SQL: Item ignored
ORA-06550: 第 7 行, 第 28 列:
PLS-00382: 表达式类型错误
ORA-06550: 第 7 行, 第 32 列:
PL/SQL: ORA-00947: 没有足够的值
ORA-06550: 第 7 行, 第 1 列:
PL/SQL: SQL Statement ignored
ORA-06550: 第 10 行, 第 55 列:
PLS-00487: 对变量 'CI' 的引用无效
ORA-06550: 第 10 行, 第 1 列:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
select * from user_types里面可以查到tt,ci对象
create type ci_list as table of ci;
CREATE PROCEDURE myobj_list_test(recs in ci_list, outs out ci_list) IS
list ci_list := ci_list();
begin
....
end;