简体   繁体   中英

using Hint in a hosted variable?

All,

I want to use a hint in a hosted variable; in fact, we need to use a dynamic value of the hint (Hint should be valued at runtime). can we write an sql statement from this:

SELECT /*+ ORDERED INDEX (b, jl_br_balances_n1) USE_NL (j b) 
           USE_NL (glcc glf) USE_MERGE (gp gsb) */
 b.application_id ,
 b.set_of_books_id ,
 b.personnel_id,
 p.vendor_id Personnel,
 p.segment1 PersonnelNumber,
 p.vendor_name Name
FROM  jl_br_journals j,
      jl_br_balances b,
      gl_code_combinations glcc,
      fnd_flex_values_vl glf,
      gl_periods gp,
      gl_sets_of_books gsb,
      po_vendors p
WHERE 

to :

SELECT /*+ :hosted_hintp */
 b.application_id ,
 b.set_of_books_id ,
 b.personnel_id,
 p.vendor_id Personnel,
 p.segment1 PersonnelNumber,
 p.vendor_name Name
FROM  jl_br_journals j,
      jl_br_balances b,
      gl_code_combinations glcc,
      fnd_flex_values_vl glf,
      gl_periods gp,
      gl_sets_of_books gsb,
      po_vendors p
WHERE 

hosted_hintp contain the value of hint we need at runtime.

thanks

Your query must be executed using dynamic SQL. Something like this:

CREATE OR REPLACE PROCEDURE query_emp (a_hint VARCHAR2)
AS
    TYPE cur_typ IS REF CURSOR; c cur_typ;
BEGIN
    OPEN c FOR 'SELECT ' || a_hint || ' empno, ename, sal, job
                FROM emp WHERE empno = 7566';

    -- process
END;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM