步骤一:建立临时表
create global temporary table t_temp
(COL varchar2(30))
on commit preserve rows;执行该语句;步骤二:建procedure(在包体里面,定义就不写了),调用若满足function check_st_cursor_status,则给临时表赋值
procedure init_temp_table as
cursor st_cursor is
select * from st_table;
begin
for cur in st_cursor loop
if (check_st_cursor_status(cur.stid)) then
insert into t_temp (COL) values (cur.stid);
commit;
end if;
end loop;
EXCEPTION
when others THEN
dbms_output.put_line(Sqlerrm);
rollback;
end init_temp_table;步骤三:
通过调用function,返回临时表里的数据集在执行到加红语句时,cur.stid确实有值,可是,读临时表,里面却没有数据???
请大家帮忙,如何在临时表里赋值。我的分比较少,不好意思。
谢谢:)
create global temporary table t_temp
(COL varchar2(30))
on commit preserve rows;执行该语句;步骤二:建procedure(在包体里面,定义就不写了),调用若满足function check_st_cursor_status,则给临时表赋值
procedure init_temp_table as
cursor st_cursor is
select * from st_table;
begin
for cur in st_cursor loop
if (check_st_cursor_status(cur.stid)) then
insert into t_temp (COL) values (cur.stid);
commit;
end if;
end loop;
EXCEPTION
when others THEN
dbms_output.put_line(Sqlerrm);
rollback;
end init_temp_table;步骤三:
通过调用function,返回临时表里的数据集在执行到加红语句时,cur.stid确实有值,可是,读临时表,里面却没有数据???
请大家帮忙,如何在临时表里赋值。我的分比较少,不好意思。
谢谢:)
解决方案 »
- oracle 11g 插入数据,查询数据很慢,该如何查看,在线等。
- oracle的问题
- pl/sql如何导出/导入表数据,
- 数据库崩溃恢复后报错:ORA-01086 savepoint 'beginaction' never established
- oracle subpartiton 问题
- 如何在数据库里保存回车啊?
- 用IMP导入DMP文件,到导入某一个表时不再有响应,CPU消耗70%以上,内存消耗50%以上,是什么原因?
- 导出问题
- 征集oracle面试题
- 我是新手,问几个概念:表空间、回滚段、数据库!
- 开发oracle10登录存储过程,对用户名、密码等判断是否存在(游标)
- 从TXT导入到ORACLE的CTL有问题,请帮忙解决!
cursor st_cursor is
select * from st_table;
begin
for cur in st_cursor loop
if (check_st_cursor_status(cur.stid)) then
insert into t_temp (COL) values (cur.stid);
dbms_output.put_line(cur.stid);
commit;
end if;
end loop;
EXCEPTION
when others THEN
dbms_output.put_line(Sqlerrm);
rollback;
end init_temp_table; 执行上面的存储过程后,查询一个临时表SELECT * FROM t_temp;
我是想把符合条件的数据(而不是所有数据)放在一个表里,然后返回它们(通过cursor),
难道使用临时表这样行不通??
如果行不通,给个其他方法。谢谢
你应该是在存储过程执行完,在sql命令窗口 select * 吧???
这样的话是不能查到的,因为你的session已经断掉了,临时表的数据就被清空了。
可以这样:procedure init_temp_table
(
p_cursor out cursor;
)as
cursor st_cursor is
select * from st_table;
begin
for cur in st_cursor loop
if (check_st_cursor_status(cur.stid)) then
insert into t_temp (COL) values (cur.stid);
commit;
end if;
end loop;
open p_cursor for select * from t_temp ; EXCEPTION
when others THEN
dbms_output.put_line(Sqlerrm);
rollback;
end init_temp_table;
这样在执行完存储过程后,打开返回的游标就能看到结果了。
以前没有搞懂session的具体含义。
同样谢谢zcs_1
谢谢两位啊。