如何在Oracle中向游标添加多行 [英] How Do I Add Multi Row To Cursor In Oracle
本文介绍了如何在Oracle中向游标添加多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在oracle中有一个FOR LOOP,在每个循环中我想添加一个记录到光标
i try
i have a FOR LOOP in oracle and in each loop i want to add an record to out cursor
i try
FOR reCord IN C
LOOP
open cur for select reCord.TONG_TIEN as "TONG TIEN", reCord.ID_PHIEUGUI as "ID PHIEU GUI", reCord.MA_BUUCUC_GOC as "MA BC GOC" from DUAL;
END LOOP;
但是最后一行是cur,我怎样才能使用循环添加更多行?
but out cur is one last row, how can i add more row using loop?
推荐答案
你不能,光标是指向结果集的只读指针,所以每次打开它时都要创建一个新光标(指向结果集的指针)
一种方法是使用联合并创建并执行它作为字符串,如:
You can't, a cursor is a read only pointer to a result set, so you're creating a new cursor (pointer to a result set) every time you open it
One way around is to use a union and create and execute it as a string like:
x := 'open cur for '
loop
x := x || 'Select something from dual '
x := x || 'Union all' --should not be added if it's the last row
End Loop
exec x
未对此语法或其他错误进行测试或检查,这仅仅是为了让您了解可能的方法这样做
This is not tested or checked for syntax or other errors, it's merely for giving you an idea on a possible way to do it
这篇关于如何在Oracle中向游标添加多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文