0

我有一个如下示例查询:

INSERT INTO my_gtt_1 (fname, lname) (select fname, lname from users)

为了摆脱临时表,我创建了一个包:

create or replace package fname_lname AS

Type fname_lname_rec_type is record (
fname varchar(10),
lname varchar(10)
);

fname_lname_rec fname_lname_rec_type

Type fname_lname_tbl_type is table of fname_lname_rec_type;

function fname_lname_func
(
   v_fnam in varchar2, 
   v_lname in varchar2
)return fname_lname_tbl_type pipelined;

作为 Oracle 的新手……创建这个包需要很长时间。但现在我不知道如何摆脱my_gtt_1

我怎么能说...

INSERT INTO <newly created package> (select fnma, name from users)
4

2 回答 2

0

You don't select into packages. You could declare a variable of your table type and bulk collect into that, if you intend to use it in code. I also question your need for a pipelined function. If you're just using the global-temporary table as a springboard for another query, you could probably just use a WITH clause instead. We need a better idea of the bigger picture to recommend a particular technique. Global temporary tables are not inherently bad, either.

于 2010-07-13T19:54:38.203 回答
0

您需要使用 TABLE() 语法调用流水线函数:

select * 
from table (select fname_lname.fname_lname_func(fnma, name) 
            from users
            where user_id = 123 )
/

请注意,对 USERS 的子查询必须从该表返回单行。

于 2010-06-13T20:01:56.253 回答