Bind variable problem in a procedure

Hi,
Is there any way I can pass a parameter in a procedure as we do in sql plus (for example where date = &date).
I have a procedure that is somewhat similar to this...
select (field 1, field2...
from table1, table 2....
where ....
and ..
and v_fiscal_year (here I want the bind variable)
UNION
select (field 1, field2...
from table1, table 2....
where .....
and ..
and ..
and v_fiscal_year (here I want the bind variable)
I need to register this procedure in oracle apps as a concurrent program where a user should be able to provide value for fiscal_year and then write the file out in a text file.
Thanks
A/A

What you've shown isn't a procedure, but is a query.
I assume your "field1", "field2" within the query means that you are expecting to be able to create a dynamic SQL from parameters passed into a procedure.
For that you will need to use DBMS_SQL package to create and execute a dynamic query or use the EXECUTE IMMEDIATE statemetn to execute a query built up in a string. Note however, that dynamic SQL is inherently bad practice and should only ever be used as a last resort. What exactly are you trying to achieve as there are likely to be better ways of doing it?

Similar Messages

  • Bad Bind Variable Problem

    Hi
    I am trying to create a trigger and facing Bad Bind Variable problem.
    Plz let me know, what's the problem in this trigger.
    CREATE OR REPLACE TRIGGER Tender_tax_update AFTER
    INSERT
    OR UPDATE
    OR DELETE OF ITEM_QTY,ITEM_RATE,TENDER_ACC_QTY ON TENDER_ENQUIRY_ITEM_D REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    Declare
         v_amt TENDER_VENDOR_TAX_D.TAX_AMOUNT%TYPE;
         v_tax_ty TENDER_VENDOR_TAX_D.TAX_TYPE%TYPE;
         v_tax_cd TENDER_VENDOR_TAX_D.TAX_CODE%TYPE;
         v_ven_cd TENDER_VENDOR_TAX_D.VENDOR_CODE%TYPE;     
         v_item_cd TENDER_VENDOR_TAX_D.item_cd%TYPE;     
         v_tenno TENDER_VENDOR_TAX_D.tender_enquiry_no%TYPE;
    Begin
         if inserting then
              v_tax_ty:=:new.TAX_TYPE;
              v_tax_cd:=:new.TAX_CODE;
              v_ven_cd:=:new.vendor_code;
              v_item_cd:=:new.item_cd;
              v_tenno:=:new.tender_enquiry_no;
    select TAX_AMOUNT into v_amt from TENDER_TAX_DETAILS where tender_enquiry_no=v_tenno and TAX_CODE=v_tax_cd and TAX_TYPE=v_tax_ty and item_cd=v_item_cd and vendor_code=v_ven_cd;
    update TENDER_VENDOR_TAX_D set TAX_AMOUNT=v_amt where tender_enquiry_no=v_tenno and TAX_CODE=v_tax_cd and TAX_TYPE=v_tax_ty and item_cd=v_item_cd and vendor_code=v_ven_cd;
         end if;
    End Tender_tax_update;
    Database deails are as follows:
    TENDER_VENDOR_TAX_D
    Name Null? Type
    TENDER_ENQUIRY_NO NOT NULL VARCHAR2(8)
    VENDOR_CODE NOT NULL VARCHAR2(4)
    TAX_CODE NOT NULL VARCHAR2(4)
    PERCENTAGE NUMBER(5,2)
    TAX_AMOUNT NUMBER(15,2)
    ITEM_CD NOT NULL VARCHAR2(10)
    TAX_FLAG VARCHAR2(1)
    TAX_TYPE CHAR(3)
    TENDER_TAX_DETAILS
    Name Null? Type
    TENDER_ENQUIRY_NO NOT NULL VARCHAR2(8)
    VENDOR_CODE VARCHAR2(4)
    ITEM_CD VARCHAR2(10)
    TAX_CODE NOT NULL VARCHAR2(4)
    TAX_TYPE CHAR(3)
    TAX_AMOUNT NUMBER
    Message was edited by:
    user648065

    facing Band Bind Variable problem.Doesn't the error message tell you which bind variable is the problem?

  • Query Bind Variables problem

    I have a ViewObject with bindvariable GroupnameItemname.
    In JHeadstart AppDef this item is not bound to model, but included in Quick Search and Advanced Serach, as in "7.2.5. Using Query Bind Variables in Quick or Advanced Search"
    First I get an error saying GroupnameItemname*Var* is not found on ViewObject, so I changed the bindvariables to GroupnameItemnameVar
    Is something changed here? We are using JHeadstart 10.1.3.3.75 / JDeveloper 10.1.3.4.0
    After changing the bindvariablename I have another problem:
    I get an error in JhsApplicationModuleImpl.advancedSearch on these lines:
    boolean isBindParam = !viewCriterium.isAttributeBased();
    AttributeDef ad = isBindParam ? null : vo.findAttributeDef(attribute);
    The first line returns false for my bindvariable, so the second line raises an error like "JBO-25058: Definition <attr> of type Attribute not found in <VO>".
    In QueryCondition:
    public boolean isAttributeBased()
    return def!=null; //but def is not null here, it is an instance of DCVariableImpl
    This used to work in previous versions of JHeadstart...
    Please help,
    Greetings HJH

    In my MyApplicationModuleImpl (which extends JhsApplicationModuleImpl) I did override advancedSearch.
    Copied the code from JhsApplicationModuleImpl and changed a few lines:
    After
    sLog.debug("executing advancedSearch for " + viewObjectUsage);
    ViewObject vo = getViewObject(viewObjectUsage);
    I added:
    //clear bindParams:
    String[] attrNames =
    vo.getNamedWhereClauseParams().getAttributeNames();
    for (int i = 0; i < attrNames.length; i++) {
    vo.setNamedWhereClauseParam(attrNames\[i\], null);
    sLog.debug("bindParam leeggemaakt: " + attrNames\[i\]);
    And a bit later in the method I made a changed as follows:
    // boolean isBindParam = !viewCriterium.isAttributeBased();
    boolean isBindParam = viewCriterium.getName().endsWith("Var");
    A bit crude, but worked for me...
    Cheerio,
    HJH
    Edited by: HJHorst on Mar 19, 2009 1:56 PM (had to escape square brackets...)

  • Bind variable problem in cascading LOVs

    Hi,
    after upgrade from APEX 3.0 to 3.1 all my cascading LOVs stopped working correctly. First level LOV is OK, but the second level LOV, which contains a bind variable in its SQL code, fails. Debugging shows that the bind variable referrencing to the value of the first level LOV is empty. It has worked without problems in 3.0. The bind variable format is traditional :ITEM
    This is an example of the LOV SQL:
    SELECT PSKUP_CZ display_value, ID return_value
    FROM PSKUP
    WHERE sk_id = :P1_SKUP
    ORDER BY 1
    Where :P1_SKUP refers to the vaule of the top level LOV.
    In Oracle® Database Application Express Release Notes Release 3.1 in chapter "3 Open Bugs and Known Issues", I've only found a short remark called "Problems with Queries Containing a Bind Variable and a String with Two Dashes". The recommended solution here was to use v('P18_X') instead of :P18_X
    I tried that but with no effect on my problem.
    Anybody has similar experience? Any workarounds?
    Thanks in advance,
    Zdenek

    Hi Zdenek,
    DV, NV, V are an optional component of the ApexLib framework. Actually they don't have anything to do with the framework itself.
    Because of the nature of this functions they have to have a hard coded reference to the FLOWS_XXX schema, but which causes problems if APEX is upgraded to a new version and the functions are not altered.
    I will probably removed them from the installation instructions or add a big remark that they have to be altered after an upgrade, because this kind of threads are re-occurring after each new released APEX version.
    Thanks
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com/
    The APEX Builder Plugin: http://builderplugin.oracleapex.info/ New
    The ApexLib Framework: http://apexlib.sourceforge.net/

  • Bind variable problem when renaming page items?

    APEX 2.1 on IE6.
    I'm having trouble with bind variables. I cannot reproduce this regularly, but I notice it from time to time. Basically, certain page items will simply refuse to hold their contents, even though the debug output says :
    0.03: Saving g_arg_names=P9_XYLOPHONE_XYLOPHONE and g_arg_values=hello
    0.03: ...Session State: Save "P9_XYLOPHONE_XYLOPHONE" - saving same value: "hello"
    Whenever I reference the variable (using :, V(), NV(), or &.) I get NULL. None of the output indicates that it was changed elsewhere. I've noticed that changing the name of page item influences this. Shorted names tend to cause fewer problems.
    I can't be more specific, as I can't figure out the pattern. Has anyone else noticed this?
    Cheers.

    hi dccase
    couldnt get what the documentation says with APP_SESSION to work.
    http://aae18331:8089/apex/f?p=102:3:$APP_SESSION.::3:MY_ITEM:315
    However the following which i guess assumes the default session worked
    =====================================================
    http://aae18331:8089/apex/f?p=102:3::::3:MY_ITEM:315
    cheers
    shaunak

  • User Report data bind variable problems

    Hello,
    I am trying to build a simple report in SQLDeveloper, using a DATE bind variable. But it fails with the error message:
    Inconsistent datatype, expected DATE got NUMBER
    SELECT * FROM FLOW_COMP_REC_SUMMARY_RU
    where create_date = trunc(:TARGET_DATE)
    and type = 'D'
    ORDER BY MESSAGE_FLOW_ID
    Running this query in SQLDeveloper worksheet executes properly after a dialog box pops up and I enter: current_date - 1
    SELECT * FROM FLOW_COMP_REC_SUMMARY_RU
    where create_date = trunc(&TARGET_DATE)
    and type = 'D'
    ORDER BY MESSAGE_FLOW_ID
    I've searched but no clear solutions present themselves. If you have one it would be most appreciated.
    Thanks

    You'll have to convert the input to date yourself:
    SELECT * FROM FLOW_COMP_REC_SUMMARY_RU
    where create_date = TO_DATE(:TARGET_DATE, 'DD/MM/YYYY')
    and type = 'D'
    ORDER BY MESSAGE_FLOW_ID
    Have fun,
    K.

  • Bind Variable Problem

    Hi Guys
    PLease i am really stuck
    i have a LOV which has a complex query...
    in that query there are multiple bind variables that are assigned... ie :1 , :2 and so forth
    here is the query for the LOV
    SELECT a.kri_description, a.kri_id
    FROM xx_key_result_indicators a, xx_kri_positions b
    WHERE TO_DATE (:1, 'DD-MON-YYYY') BETWEEN a.effective_from_date
    AND a.effective_to_date
    AND TO_DATE (:2, 'DD-MON-YYYY') BETWEEN b.effective_from_date
    AND b.effective_to_date
    AND a.kra_id = :3
    AND a.kri_id IN (
    SELECT c.kri_id
    FROM xx_kri_positions c
    WHERE TO_DATE (:4, 'DD-MON-YYYY')
    BETWEEN c.effective_from_date
    AND c.effective_to_date
    AND c.position_id = :5
    AND c.enable_flag = 'Y')
    AND b.position_id = :6
    AND a.enable_flag = 'Y'
    AND b.enable_flag = 'Y'
    AND a.kri_id NOT IN (SELECT NVL (g.kri_id, 1)
    FROM xx_perf_kri g
    WHERE g.perf_kra_id = :7)
    UNION
    SELECT f.kri_description, f.kri_id
    FROM xx_key_result_indicators f
    WHERE TO_DATE (:8, 'DD-MON-YYYY') BETWEEN f.effective_from_date
    AND f.effective_to_date
    AND f.kra_id = :9
    AND f.kri_id NOT IN (SELECT e.kri_id
    FROM xx_kri_positions e)
    AND f.enable_flag = 'Y'
    AND f.kri_id NOT IN (SELECT NVL (d.kri_id, 1)
    FROM xx_perf_kri d
    WHERE d.perf_kra_id = :10)
    so in theroy when i push the tourch icon next to my text field i set these bind variables...
    so in theroy that should work,,, but becuase i have a lov the framework will automatically assign extra where clause params for the filter.... and the query will look as follows
    SELECT *
    FROM (SELECT a.kri_description, a.kri_id
    FROM xx_key_result_indicators a, xx_kri_positions b
    WHERE TO_DATE (:1, 'DD-MON-YYYY') BETWEEN a.effective_from_date
    AND a.effective_to_date
    AND TO_DATE (:2, 'DD-MON-YYYY') BETWEEN b.effective_from_date
    AND b.effective_to_date
    AND a.kra_id = :3
    AND a.kri_id IN (
    SELECT c.kri_id
    FROM xx_kri_positions c
    WHERE TO_DATE (:4, 'DD-MON-YYYY')
    BETWEEN c.effective_from_date
    AND c.effective_to_date
    AND c.position_id = :5
    AND c.enable_flag = 'Y')
    AND b.position_id = :6
    AND a.enable_flag = 'Y'
    AND b.enable_flag = 'Y'
    AND a.kri_id NOT IN (SELECT NVL (g.kri_id, 1)
    FROM xx_perf_kri g
    WHERE g.perf_kra_id = :7)
    UNION
    SELECT f.kri_description, f.kri_id
    FROM xx_key_result_indicators f
    WHERE TO_DATE (:8, 'DD-MON-YYYY') BETWEEN f.effective_from_date
    AND f.effective_to_date
    AND f.kra_id = :9
    AND f.kri_id NOT IN (SELECT e.kri_id
    FROM xx_kri_positions e)
    AND f.enable_flag = 'Y'
    AND f.kri_id NOT IN (SELECT NVL (d.kri_id, 1)
    FROM xx_perf_kri d
    WHERE d.perf_kra_id = :10)) qrslt
    WHERE (( UPPER (kri_description) LIKE :1
    AND ( kri_description LIKE :2
    OR kri_description LIKE :3
    OR kri_description LIKE :4
    OR kri_description LIKE :5
    not that now there are bind variable 1 through to 10 and then 1 through to 5...
    the error i am getting is not all variables bound exception..
    please if anyone could help....
    Thanks

    I am new to OA Fwk, but I am Expert of java, J2EE.
    My solution will work fine in pure java.
    I am sure same should work in OA also.
    But I never experimented it. Give it a try
    Lets take a select query:
    select my_col from my_table where clo1 = :1 and col2 = :1
    In this query there is only one bind varible ":1" in the world of PL/SQL.
    But for there are two bind varibales you need to set them two times.
    in java you will do
    stmt.setString(1, myval);
    stmt.setString(2, myval);
    Now coming to your query.
    It has 10 +5 total 15 bind variables and you need to set 15 but not 10.
    For all practicle purposes assume that :1 or :2 or :3 is equivalent to ?
    Thus your select query is equivalent to
    SELECT *
    FROM (SELECT a.kri_description, a.kri_id
    FROM xx_key_result_indicators a, xx_kri_positions b
    WHERE TO_DATE (?, 'DD-MON-YYYY') BETWEEN a.effective_from_date
    AND a.effective_to_date
    AND TO_DATE (?, 'DD-MON-YYYY') BETWEEN b.effective_from_date
    AND b.effective_to_date
    AND a.kra_id = ?
    AND a.kri_id IN (
    SELECT c.kri_id
    FROM xx_kri_positions c
    WHERE TO_DATE (?, 'DD-MON-YYYY')
    BETWEEN c.effective_from_date
    AND c.effective_to_date
    AND c.position_id = ?
    AND c.enable_flag = 'Y')
    AND b.position_id = ?
    AND a.enable_flag = 'Y'
    AND b.enable_flag = 'Y'
    AND a.kri_id NOT IN (SELECT NVL (g.kri_id, 1)
    FROM xx_perf_kri g
    WHERE g.perf_kra_id = ?)
    UNION
    SELECT f.kri_description, f.kri_id
    FROM xx_key_result_indicators f
    WHERE TO_DATE (?, 'DD-MON-YYYY') BETWEEN f.effective_from_date
    AND f.effective_to_date
    AND f.kra_id = ?
    AND f.kri_id NOT IN (SELECT e.kri_id
    FROM xx_kri_positions e)
    AND f.enable_flag = 'Y'
    AND f.kri_id NOT IN (SELECT NVL (d.kri_id, 1)
    FROM xx_perf_kri d
    WHERE d.perf_kra_id = ?)) qrslt
    WHERE (( UPPER (kri_description) LIKE ?
    AND ( kri_description LIKE ?
    OR kri_description LIKE ?
    OR kri_description LIKE ?
    OR kri_description LIKE ?)))
    you need to set the values in the order in which bind varibale appear in select query

  • Problem binding variable to query in procedure

    Hi folks,
    I'm having an issue binding a variable to a query.  For example the following works in my procedure;
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    tempVar = select field1 from myView where Plant = :V_PLANT;
    When I debug my procedure I can see the variable V_PLANT = 'ACME' and tempVar contains 1 single value (field1) record.
    Now, alternatively, if I try passing my variable like this it is not working (get error: no data found);
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    ABCVariable NVARCHAR(45) := '';
    select field1 into ABCVariable from myView where Plant = :V_PLANT;
    However if I hard code the plant variable as a literal string like this I indeed get data;
    DECLARE V_PLANT NVARCHAR(4) := 'ACME';
    ABCVariable NVARCHAR(45) := '';
    select field1 into newVariable from myView where Plant = 'ACME';
    Result is I have a value of 'ACME' in ABCVariable.  It seems when I'm using SELECT INTO syntax I can no longer use variables in the where condition.
    Any suggestions?
    Thanks,
    -Patrick

    Hi Patrick
    I cannot reproduce this problem:
    create procedure get_article_by_label (IN v_article_label varchar)
    language sqlscript
    as
    begin
        declare v_article_id integer := -1;
        select max(article_id) into v_article_id
        from efashion.article_lookup
        where UPPER(article_label) like '%' || UPPER(:v_article_label) || '%';
        select * from efashion.article_lookup
        where article_id = :v_article_id;
    end;
    call get_article_by_label ('Leather Belt');
    ARTICLE_ID  ARTICLE_LABEL           CATEGORY            SALE_PRICE  FAMILY_NAME FAMILY_CODE
    143848      Patchwork Leather Belt  Belts,bags,wallets  88.9        Accessories F60       
    As you see I use the input variable in the WHERE condition, and reuse the found ID to select data again.
    Not sure though, why it doesn't work in your case.
    Is the target variable in your working example also ABCVariable or indeed newVariable?
    - Lars

  • Bind variables problem, very urgent

    hi,
    Oracle gurus,
    In my current project while executing the following ststement i am getting the run time error"ORA-01008: not all variables bound".
    This statement is used inside of a procedure and some bind arguments have values and some arguments have NULL values.
    EXECUTE IMMEDIATE ' insert into trn_billtask
    (area_id,
    asn_no,
    batch_no,
    cases_per_pallet,
    color_zone,
    comp_id,
    cube,
    currdate,
    eachs_per_case,
    ebiz_sku_no,
    ebiz_user_no,
    footage,
    hazmat_flag,
    home_zone,
    intf_conf_flag,
    line_no,
    location,
    lp,
    merge_flag,
    no_of_cases,
    no_of_units,
    packcode,
    po_line_no,
    po_no,
    putaway_strategy,
    qty
    ,rcv_type,
    site_id,
    sku,
    skudesc1,
    skufam,
    skugroup,
    sku_status,
    status_flag,
    task_date,
    task_desc,
    task_type,
    type_stor_equip,
    uom_id,
    wght)
    select null,
    rh.rec_no,
    p.lot,
    pr.each_qty,
    sl.color_zone,
    ''MR'',
    pr.unit_cube*(nvl(p.qty,0)/nvl(pr.each_qty,1)),
    sysdate,
    pr1.each_qty,
    p.prod_no,
    1,
    nvl(sl.wdth,0) * nvl(sl.dpth,0),
    decode(s.haz_mat_class,null,''N'',''Y''),
    sl.home_zone,
    ''N'',
    r.line_no,
    p.end_loc,
    p.lp,
    nvl(p.access_aisle,''N''),
    round(nvl(p.qty,0)/nvl(pr.each_qty,1)),
    1,
    p.pkg_no,
    r.p_line_no,
    rh.po_no,
    r.putaway_strategy,
    p.qty,
    rh.rec_type,
    ''HW'',
    s.sku,
    s.sku_desc1_35,
    s.prod_fam,
    s.prod_cat,
    p.prod_stat,
    2,
    sysdate,
    ''Handling'',
    bt.task_type,
    nvl(sl.type_stor_equip,''100''),
    p.uom,
    pr.unit_wght*(nvl(p.qty,0)/nvl(pr.each_qty,1))
         from [email protected] s,mast_abbtype bt,mast_company bc,[email protected] pr,[email protected] sl,
         [email protected] r,[email protected] rh,[email protected] p,[email protected] pr1
         where p.end_time is not null
              and decode(bt.comp_id,null,:p_comp_id,bt.comp_id)= :p_comp_id
              and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
              and bt.task_type = :p_task_type
              and bc.comp_id = :p_comp_id
              and p.proc_cntrl_no =r.rec_cntrl_no
              and bc.ebiz_appown_no= 40
              and bt.delete_flag=''N''
              and r.rec_cntrl_no = rh.rec_cntrl_no
              and p.proc_cntrl_no = nvl(:p_po_no,p.proc_cntrl_no)
              and p.prod_no = nvl(:p_ebiz_sku_no, p.prod_no)
              and nvl(p.prod_stat, ''~'') =nvl(:p_sku_status, nvl(p.prod_stat, ''~''))
              and p.lp = nvl(:p_lp, p.lp)
              and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
              and r.lp = p.lp
              and p.prod_no = s.prod_no
              and p.prod_no = pr.prod_no
              and p.pkg_no = pr.pkg_no
              and pr.logical_case_flg = ''Y''
              and p.end_loc = sl.loc
              and nvl(p.sku_key3,''A'') != ''1''
              and decode(''COMP'',''BYID'',s.buyer_id,s.comp_code) = bc.comp_id
              and bc.comp_id =:p_comp_id
              and r.cart_lp is null
              and trunc(p.date_time_created) between trunc(nvl(SYSDATE-10000,p.date_time_created))
              and trunc(nvl(SYSDATE,p.date_time_created))
              and trunc(p.date_time_created) >= trunc(bc.effective_date)
              and pr.prod_no = pr1.prod_no and pr.pkg_no = pr1.pkg_no and pr1.logical_plt_flg = ''Y'' '
         using p_comp_id,p_site_id,p_task_type,p_po_no,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
    ur suggestions r most welcome
    thanks
    RR

    Placeholders (:name) are bound by position in EXECUTE IMMEDIATE SQL statement. Hence Oracle does not consider multiple :p_comp_id in your statement to be the same thing. You would need to repeatedly bind them for each occurrence, or use an approach (DBMS_SQL.BIND_VARIABLE or EXECUTE IMMEDIATE PL/SQL block) which binds by name or position / name.
    In the case of the above example you would have a USING clause similar to the below (Note that I am unable to test this).
    EXECUTE IMMEDIATE sql_statement
       USING p_comp_id, p_comp_id, p_site_id,
          p_site_id, p_task_type, p_comp_id,
          p_po_no, p_ebiz_sku_no, p_sku_status,
          p_lp, p_batch_no, p_comp_id;

  • How to catch possible bind variable performance impact during development?

    Since producing load is a problem on development environment and the technics provided with Oracle can capture a parsing problem caused by a bind variable problem only after execution we are looking for pro-active solution like 10g compile time warnings stuff.
    Using binds can have impact on indexed skewed data columns and paritioned tables, so lets just think about a typical oltp environment with always same access path results for similar queries using bind variables.
    Using v$ views or even better dba_hist after 10g or 10046 trace are considered as re-active approaches since they can only be examined on a pre-production loaded environment.
    Is there any tool or approach you are using or may suggest?
    Thank you, best regards.
    Tonguc

    Are you using PL/SQL only?
    If so, I'd look at all the EXECUTE IMMEDIATE's and DBMS_SQL calls throughout the code and determine one by one if they pose a threat. They should be rare, so a simple search against the USER_SOURCE could be sufficient.
    Other programming languages will have different statements to watch out for.
    I am not aware of any tool that does this for you.
    Hope this helps.
    Regards,
    Rob.

  • How to pass a value to a bind variable in a query report in oracle apex

    Hi Guys,
    I have requirement to send weekly reports via email to some users. The users should receive their own records in the report. The user details is stored in a table. What I am planning to do is to create a report query in oracle apex to generate the report and then run a function/procedure via a scheduler to email the report to respective users. Now my query is ............. is it possible to pass a value (user name) to the report query to pull records of only that user? I know we can have bind variables in the report query but I have no idea how to pass a value for bind variables from a function/procedure.
    Can anyone help me on this issue or suggest a better approach?
    Thanks,
    San

    You need to use dynamic sql
    But please keep in mind that since you're using Oracle you may be better off posting this in some Oracle forums
    This forum is specifically for SQL Server
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Bind Variable

    Is the bind variable syntax supported in procedure? The following produces error:
    VARIABLE salary number
    CREATE OR REPLACE PROCEDURE bindvar
    is
    eid employees.employee_id%type;
    BEGIN
    SELECT employee_id INTO eid FROM EMPLOYEES
    WHERE employee_id > :salary and rownum=1;
    DBMS_OUTPUT.PUT_LINE(:salary);
    END;
    LINE/COL ERROR
    6/26 PLS-00049: bad bind variable 'SALARY'
    7/24 PLS-00049: bad bind variable 'SALARY'
    But if I change the procedure to an anonymous block, everything works fine!

    your variable salary declaration exists only in the current SQL*Plus session. It is not going to be existing in all the environments from where this stored procedure can be called and certainly not on the server where the code is stored in the database.
    The reference can be used in an anonymous block run from the same SQL*Plus session, since it is one time execution. Not in a stored procedure like the way you intend.
    You could have the stored procedure take a number as input and use that parameter in your sql. then at SQL*Plus prompt call the procedure passing the value in :salary variable to get the results.

  • Bind variable inside a package

    Can we declare a bind variable inside a package specification?
    CREATE OR REPLACE PACKAGE GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE);
    VARIABLE O VARCHAR2(20);
    END GET_EMPLOYEEDETAILS ;
    CREATE OR REPLACE PACKAGE BODY GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE)
    IS
    BEGIN
    SELECT FIRST_NAME INTO F_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID = E_ID;
    DBMS_OUTPUT.PUT_LINE(F_NAME);
    END;
    END GET_EMPLOYEEDETAILS;
    Output:
    ERROR at line 4: PLS-00103: Encountered the symbol "VARCHAR2" when expecting one of the following:
      := . ( @ % ; not null range default character
    The symbol ":=" was substituted for "VARCHAR2" to continue.
    2. IS
    3. PROCEDURE GET_FIRSTNAME(E_ID IN EMPLOYEES.EMPLOYEE_ID%TYPE, F_NAME OUT EMPLOYEES.FIRST_NAME%TYPE);
    4. VARIABLE O VARCHAR2(20);
    5. END GET_EMPLOYEEDETAILS ;
    6. /
    or is there any alternative for bind variables inside an package
    Thanks in advance
    Message was edited by: 1009739

    The "VARIABLE O VARCHAR2(20);" syntax is the way SQLPlus declared bind variables - it is specific to the client. Because PL/SQL packages and procedures are server code that continue past sessions, its only access to the client environment is what the client gives it - it can't go and create a bind variable in the client.
    PL/SQL procedures, functions and packages run from lots of environments, so they cannot access bind variables inside their body - you have to pass any external variables as parameters.
    Anonymous PL/SQL blocks can access bind variables.
    You can declare package public global variables - just leave out that "VARIABLE". E.g.
    CREATE OR REPLACE PACKAGE GET_EMPLOYEEDETAILS
    IS
    PROCEDURE GET_FIRSTNAME(E_ID IN EMP.EMPNO%TYPE, F_NAME OUT EMP.ENAME%TYPE);
    O VARCHAR2(20);
    END GET_EMPLOYEEDETAILS ;
    For local variables in your procedure, just put them between the IS and BEGIN. Using them in SQL inside the PL/SQL automatically uses them as a bind variable.
    create or replace PROCEDURE GET_FIRSTNAME(E_ID IN EMP.EMPNO%TYPE, F_NAME OUT EMP.ENAME%TYPE)
    IS
      O VARCHAR2(20);
      O2 VARCHAR2(21);
    BEGIN
      O := 'FR%';
    SELECT ENAME INTO F_NAME FROM EMP WHERE EMPNO = E_ID and ENAME like O;
    O2 := F_NAME || '2';
    DBMS_OUTPUT.PUT_LINE(F_NAME);
    END;
    O is bound in the query.
    To access bind variables from anonymous PL/SQL, first declare them in the calling environment. In SQL Plus that's
    VARIABLE O VARCHAR2(20);
    In Pro*C it's
    EXEC SQL BEGIN DECLARE SECTION;
      char[21] O
    EXEC SQL END DECLARE SECTION;
    Then reference it in anonymous PL/SQL with a colon as prefix:
    BEGIN
    SELECT FIRST_NAME INTO :O FROM EMPLOYEES WHERE EMPLOYEE_ID = E_ID;
    END;
    This only works for anonymous blocks (starting with BEGIN or DECLARE). As I said, PL/SQL procedures, functions and packages cannot see bind variables from the calling environment

  • Problem with bind variable in a procedure

    Hi Experts,
    I'm migrating forms from 5 to 6i. And in most of the forms I'm getting the error in the procedure "G$_KEY_OPT_MENU".
    This is the most common error I'm getting in almost like 30 forms.
    The error is:
    Error 49 at line 21, column 3
    bad bind variable "SELECT_ITEM"
    Error 49 at line 22, column 3
    bad bind variable "SELECT_ITEM"
    Error 49 at line 21, column 3
    bad bind variable "OPT_SEL"
    Error 49 at line 21, column 3
    bad bind variable "OPT_SEL"
    Error 49 at line 50, column 3
    bad bind variable "SELECT_ITEM"
    PROCEDURE G$_KEY_OPT_MENU (ITEM_NAME_IN IN CHAR,
                               SEL_A_DESC IN CHAR,SEL_A_KEY IN CHAR,
                               SEL_B_DESC IN CHAR,SEL_B_KEY IN CHAR,
                               SEL_C_DESC IN CHAR,SEL_C_KEY IN CHAR,
                               SEL_D_DESC IN CHAR,SEL_D_KEY IN CHAR) IS
         ITM          VARCHAR2(1);
         DESC_VAR     VARCHAR2(36);
         KEY_VAR      VARCHAR2(30);
         ITEM_ID      ITEM;
    BEGIN
      ITEM_ID := FIND_ITEM(NAME_IN('SYSTEM.CURSOR_BLOCK')||
                   SUBSTR(NAME_IN('SYSTEM.TRIGGER_ITEM'),
                   INSTR(NAME_IN('SYSTEM.TRIGGER_ITEM'),'.'),
                   INSTR(NAME_IN('SYSTEM.TRIGGER_ITEM'),'_LBT')-1 -
                   INSTR(NAME_IN('SYSTEM.TRIGGER_ITEM'),'.')+1));
      IF ID_NULL(ITEM_ID) THEN
         IF G$_DISPLAY_ALERT('','The Button you pressed is outside the current block') IS NOT NULL
            THEN RAISE FORM_TRIGGER_FAILURE;
         END IF;
      END IF;
      :SELECT_ITEM := '';
      :OPT_SEL := '';
      For Loop and some conditions, setting properties.
      GO_ITEM('G$_OPT_BLOCK.OPT_SEL');
      :SELECT_ITEM := ITEM_NAME_IN;
    END;Edited by: user12290512 on Mar 14, 2011 2:16 PM

    FRM-18108: Failed to load the following objects.Source Module:GOQOLIB
    Source Object: G$_WARNING_ALERT
    Source Module:GOQOLIB
    Source Object: G$_OPT_BLOCK
    Source Module:GOQOLIB
    Source Object: G$_OPT_CANVAS
    Source Module:COQOLIB
    Source Object: CTRDETC_CHG_LOV
    Source Module:GOQOLIB
    Source Object: GUROPTM_LOV
    Source Module:COQOLIB
    Source Object: CTRDETC_PMT_LOV
    Source Module:COQOLIB
    Source Object: CBBDACC_ACCOUNT_ID_LOV
    Source Module:COQOLIB
    Source Object: CBBDACC_ACCOUNT_ID_RG
    Source Module:COQOLIB
    Source Object: CTRDETC_PMT_RG
    Source Module:COQOLIB
    Source Object: CTRDETC_CHG_RG
    Source Module:GOQOLIB
    Source Object: GUROPTM_RG
    Source Module:GOQOLIB
    Source Object: G$_NVA_LOV
    Source Module:GOQOLIB
    Source Object: G$_NVA_BUTTON_ITEM
    Source Module:GOQOLIB
    Source Object: G$_NVA_TEXT_ITEM
    Source Module:GOQOLIB
    Source Object: G$_OPT_WINDOW
    And all the source objects listed above are in GOQOLIB form. >
    This is "KEY" piece of information that should have been included in your original post. As you are fairly new to the Oracle Forums, you might want to take a few minutes to review the following:
    <ul>
    <li>Before posting on this forum please read
    <li>10 Commandments for the OTN Forums Member
    <li>Announcement: Forums Etiquette / Reward Points
    </ul>
    These threads will help you ask more thorough questions! The more information you can provide about the issue you are having the better able we (the community) are to give you a solution. ;-)
    Craig B-)
    Edited by: CraigB on Mar 15, 2011 9:27 AM

  • Problems with Date bind variable

    I'm trying to use a Date as a bind variable in a View Object, and I'm running into difficulties. I've got the bind variable type set to date, and the control hints for Format Type and Format set to "Simple Date" and "yyyy-MM-dd" respectively. When I run the application module test and enter the date in the correct format, the View Object returns the expected results. However, when I try to set a Query Bind Parameters property for a JHeadstart group in my application definition in order to set the bind variable's value from an dateField input control, I get the following exception:
    30-Jan 08:49:56 ERROR (ErrorReportingUtils) -java.lang.IllegalArgumentException
    at java.sql.Date.valueOf(Date.java:104)
    at oracle.jbo.domain.Date.toDate(Date.java:348)
    at oracle.jbo.domain.Date.<init>(Date.java:279)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    at oracle.jbo.domain.TypeConvMapEntry.convert(TypeConvMapEntry.java:73)
    at oracle.jbo.domain.TypeFactory.get(TypeFactory.java:739)
    at oracle.jbo.domain.TypeFactory.getInstance(TypeFactory.java:90)
    at oracle.jbo.common.VariableImpl.convertToJava(VariableImpl.java:546)
    at oracle.jbo.common.VariableValueManagerImpl.doSetVariableValue(VariableValueManagerImpl.java:182)
    at oracle.jbo.common.VariableValueManagerImpl.setVariableValue(VariableValueManagerImpl.java:223)
    at oracle.jbo.common.VariableValueManagerImpl.setVariableValue(VariableValueManagerImpl.java:229)
    at oracle.jheadstart.model.adfbc.v2.JhsApplicationModuleImpl.applyBindParams(JhsApplicationModuleImpl.java:173)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at oracle.adf.model.binding.DCInvokeMethod.invokeMethod(DCInvokeMethod.java:507)
    at oracle.adf.model.binding.DCDataControl.invokeMethod(DCDataControl.java:1795)
    at oracle.adf.model.bc4j.DCJboDataControl.invokeMethod(DCJboDataControl.java:1989)
    at oracle.adf.model.binding.DCInvokeMethod.callMethod(DCInvokeMethod.java:219)
    at oracle.jbo.uicli.binding.JUCtrlActionBinding.doIt(JUCtrlActionBinding.java:1289)
    at oracle.adf.model.binding.DCDataControl.invokeOperation(DCDataControl.java:1802)
    at oracle.jbo.uicli.binding.JUCtrlActionBinding.invoke(JUCtrlActionBinding.java:627)
    at oracle.adf.model.binding.DCInvokeActionDef$DCInvokeAction.refresh(DCInvokeActionDef.java:140)
    at oracle.adf.model.binding.DCBindingContainer.internalRefreshControl(DCBindingContainer.java:2521)
    at oracle.adf.model.binding.DCBindingContainer.refresh(DCBindingContainer.java:2260)
    at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.prepareRender(PageLifecycleImpl.java:534)
    at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.prepareRender(FacesPageLifecycle.java:98)
    at oracle.jheadstart.controller.jsf.lifecycle.JhsPageLifecycle.prepareRender(JhsPageLifecycle.java:1155)
    at oracle.adf.controller.v2.lifecycle.Lifecycle$1.execute(Lifecycle.java:297)
    at oracle.adf.controller.v2.lifecycle.Lifecycle.executePhase(Lifecycle.java:116)
    at oracle.adf.controller.faces.lifecycle.ADFPhaseListener.mav$executePhase(ADFPhaseListener.java:29)
    at oracle.adf.controller.faces.lifecycle.ADFPhaseListener$1.before(ADFPhaseListener.java:426)
    at oracle.adf.controller.faces.lifecycle.ADFPhaseListener.beforePhase(ADFPhaseListener.java:77)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:228)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:137)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:214)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:162)
    at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:228)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:197)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:123)
    at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:103)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    However, it seems that the value of the bind parameter did in fact change, according to the debug message issued by the JhsApplicationModuleImpl.applyBindParams(...) procedure:
    30-Jan 08:46:23 DEBUG (JhsApplicationModuleImpl) -ViewObject ViewObj: value of bind param move_date has changed: old value=null ,new value=Wed Jan 07 00:00:00 CST 2009
    One thing I have noticed that may be of interest - if I run the debugger into the JhsApplicationModuleImpl.applyBindParams(...) procedure, a default date in my bind variable shows up as an oracle.jbo.domain.Date object when it comes out of the following line:
    Object oldValue = vo.ensureVariableManager().getVariableValue(key);
    as opposed to the new value that gets sent from the input value of the dateField control, which shows up as a java.util.Date in the following line:
    Object value = args.get(key);
    In the string of functions leading up to the following in the stack trace:
                   at java.sql.Date.valueOf(Date.java:104)
    at oracle.jbo.domain.Date.toDate(Date.java:348)
    at oracle.jbo.domain.Date.<init>(Date.java:279)
    it looks like the value of the java.util.Date is converted to a string, then passed to these functions to be turned into a java.sql.Date object. However, according to the java.sql.Date.valueOf(...) function, it's expecting date in "yyyy-mm-dd" format, per the header comments:
    * Converts a string in JDBC date escape format to
    * a <code>Date</code> value.
    * @param s a <code>String</code> object representing a date in
    * in the format "yyyy-mm-dd"
    * @return a <code>java.sql.Date</code> object representing the
    * given date
    * @throws IllegalArgumentException if the date given is not in the
    * JDBC date escape format (yyyy-mm-dd)
    When the input value from the dateField input control is added as a java.util.Date, the toString() is producing the wrong date format, which could be seen in the debug output I included above that said the bind variable has changed.
    Has anyone done this before that can let me know what I am missing and how to fix this? I've search all over the web, and all the articles I've seen relating to bind variables only refer to those of numeric or string types, which aren't giving me any trouble. Even the Developer's Guide (http://database.in2p3.fr/doc/oracle/Oracle_Application_Server_10_Release_3/web.1013/b25947/bcquerying009.htm) article "5.9 Using Named Bind Variables" doesn't reference using a Date type.

    I had the same problem about a year ago (using JHeadstart 10.1.3.2.52):
    15-feb 14:10:31 DEBUG (JhsApplicationModuleImpl) -Search item matches query bind param SubjectenKernPeildatum, value set to 2000-01-01
    15-feb 14:10:33 DEBUG (JhsApplicationModuleImpl) -Executing applyBindParams for BasServiceKern.AdresRollenSubjecten
    15-feb 14:10:33 DEBUG (JhsApplicationModuleImpl) -ViewObject AdresRollenSubjecten: value of bind param peildatum has changed: old value=null ,new value=Sat Jan 01 00:00:00 CET 2000
    15-feb 14:10:33 ERROR (ErrorReportingUtils) -java.lang.IllegalArgumentException
    at java.sql.Date.valueOf(Date.java:104)
    at oracle.jbo.domain.Date.toDate(Date.java:348)
    It appears a java.util.Date gets put on the criteria Map in the searchBean, this can't be used as input for a jbo.Date bindvariable.
    My ugly solution was to override public void applyBindParams(String voUsage,HashMap args)
    in MyProjectApplicationModuleImp (which extends JhsApplicationModuleImpl of course),
    check if value is a java.util.Date, and then
    value = new java.sql.Date(((java.util.Date)value).getTime());
    Greetings, HJ
    Edited by: HJHorst on Feb 6, 2009 12:22 AM

Maybe you are looking for