问题
Below query is giving missing keyword error..
select *
from its_account aac
CROSS APPLY its.fnGetAccountIdentifier(aac.account_key) ;
here is my function:
create or replace FUNCTION fnGetAccountIdentifier
(
v_AccountKey IN NUMBER
)
RETURN fnGetAccountIdentifier_pkg.tt_fnGetAccountIdentifier_type PIPELINED
AS
v_temp SYS_REFCURSOR;
v_temp_1 TT_FNGETACCOUNTIDENTIFIER%ROWTYPE;
BEGIN
OPEN v_temp FOR
SELECT *
FROM tt_fnGetAccountIdentifier;
LOOP
FETCH v_temp INTO v_temp_1;
EXIT WHEN v_temp%NOTFOUND;
PIPE ROW ( v_temp_1 );
END LOOP;
END;
I do not know where I am doing wrong. I am really new to this.
回答1:
The
APPLY
SQL syntax, whether itCROSS APPLY
orOUTER APPLY
was introduced inOracle 12c version. Prior versions of Oracle RDBMS do not support
APPLY
SQL syntax.- When selecting from table function you need to use
TABLE()
function:
Having said that, you could rewrite your query as follows:
For 12c using cross apply
.
select *
from its_account aac
cross apply TABLE(fnGetAccountIdentifier(aac.account_key)) ;
For 9i and up using cross join
.
select *
from its_account aac
cross join TABLE(fnGetAccountIdentifier(aac.account_key)) ;
In your case there is no difference - you will get the same result using cross join
as you would using cross apply
.
回答2:
I'm not sure if you want a cross join, as I think you're expecting the table to be effectively joined to the results of the pipelined function based on the account_key
. But that's also assuming that column exists in both tables. It's a bit unclear, not least because you aren't using the account_key
you're passing to the function.
So I think you want a normal inner join, using the table
operator to treat your pipelined function results as a table:
select *
from its_account aac
JOIN table(fnGetAccountIdentifier(aac.account_key)) t
ON t.account_key = aac.account_key ;
But there's a lot of speculation in there. Here's an SQL Fiddle showing the results of that join and a cross join; the cross join output doesn't look useful, but only you can really know that, since I've made the data up.
来源:https://stackoverflow.com/questions/18270543/cross-apply-giving-missing-keyword-error