在托管变量中使用提示?

时间:2015-05-26 16:07:57

标签: oracle oracle11g hints query-hints

所有

我想在托管变量中使用提示;实际上,我们需要使用提示的动态值(提示应该在运行时估值)。我们可以写一个sql语句:

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 

到:

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包含我们在运行时需要的提示值。

感谢

1 个答案:

答案 0 :(得分:1)

您的查询必须使用动态SQL执行。 像这样:

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;
/