1

我有一个返回多个值的选择查询。我必须将它存储在一个变量中并在游标创建的 where 子句中使用它。我的变量应该是什么类型?

4

2 回答 2

0

As stated earlier, you should combine the two queries (the query for CURSOR and the query to act as its WHERE clause) into a single query. However, if you must store data into variables before passing it to WHERE clause of CURSOR, you can define variable as follows:

Let's say your source table is TAB_SOURCE and you want to select columns COL1, COL2, and COL3 from it. Variable definition would be:

V_COL1 TAB_SOURCE.COL1%TYPE;
V_COL2 TAB_SOURCE.COL2%TYPE;
V_COL3 TAB_SOURCE.COL3%TYPE;

This way, you do not need to write data types explicitly while defining variables. DBMS automatically picks data type of source columns and assigns it to respective variables.

于 2013-10-01T04:34:56.443 回答
0

首先,您应该尽量不要存储它,因为将两个查询合并为一个会更容易和更有效。

除此之外,类型应该与您正在读取的列相同。

于 2012-12-01T09:51:55.987 回答