我有一个select语句返回0或更多行。oracle plsql分块行
我想用一个游标想出一个plsql proc来产生xml输出,所有行一次返回100行。我这样做是为了根据需求在一段时间内分块排列。
所以基本上我的程序应遵循以下逻辑
cursor c1 is select id,code_id,code_desc from table order by id; --returns some rows
if c1%notfound
then return;` -- exit from procedure
else
loop
grab first 100 rows from select and append to a variable
and assign it to a variable;
update this variable into a clob field in a table.
grab next 100 rows and append into a variable
update this variable into a clob field in a table in another row;see below
table data
and so on
and grab remaining rows and append into a variable
print the variable;
until no data found;
exit
我试图做的SELECT语句的输出转换成XML文本。
输出应该类似于下面:
表:STG_XML_DATA
LOOP_NO(NUMBER), XML_TEXT(CLOB), ROWS_PROCESSED
1 <XML><id>1</ID><id>2</ID>..<ID>100</ID></XML> 100
2 <XML><id>101</ID><id>102</ID>..<ID>200</ID></XML> 200
3 <XML><id>301</ID><id>102</ID>..<ID>320</ID></XML> 20
能有人帮
你为什么在同一时间试图只处理100行?你能澄清你的行看起来像什么,或“追加到变量”看起来像什么?例如,您可以将行存储在PL/SQL集合中,但这并不能让它们更容易打印。 – kfinity
我只是试图将行100分段,并将其追加到可以存储到表中的变量中,而不一定要打印。我工作生成一些XML模式文本。从这个select语句返回的值将被用于将其追加到clob_column中。 – user1751356
在这里阅读一些关于使用游标的非常有用的信息,特别是限制您想要执行的检索行以及如何正确知道何时到达结尾(而不是使用NOTFOUND!):http:// www。 oracle.com/technetwork/issue-archive/2008/08-mar/o28plsql-095155.html –