cross apply giving missing keyword error

回眸只為那壹抹淺笑 提交于 2019-12-11 09:39:30

问题


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:


  1. The APPLY SQL syntax, whether it CROSS APPLY or OUTER APPLY was introduced in

    Oracle 12c version. Prior versions of Oracle RDBMS do not support APPLY SQL syntax.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!