Using a Bind Variable in the FROM part of a SQL Statement?

Hello Everyone,
I have a problem, I am trying to run an SQL statement. However I need the FROM part of the SQL statement to be a bind variable. This is because the end user will need to select between 2 database views.
I have tried this:
select CON_ID from :P23_DB_NAME where CON_LEGACY_ID=:P23_CONLEG_NO
I had no luck. The error i got was,
"+Query cannot be parsed within the Builder. If you believe your query is
syntactically correct, check the ''generic columns'' checkbox below the
region source to proceed without parsing.
ORA-00903: invalid table name+"
Which makes sence, but now I am a bit stuck.
Does anyone have any ideas as to get around this problem?
Thanks in Advance.
-N.S.N.O.

The example I gave you is quite simple. You need to take some time to study it to see where you need be carefull what you put where. Now, your example of course doesn't work becaues you have several errors. This will work for you:
DECLARE
   x   VARCHAR2 (4000);
BEGIN
   x := x || 'SELECT CON_ID FROM ';
   x := x || :p23_db_name;
   x := x || ' WHERE CON_LEGACY_ID = ' || :p23_conleg_no;
   RETURN (x);
END;Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
-------------------------------------------------------------------

Similar Messages

  • Use of bind variables with the oracle db - to improve library cache perform

    Dear Friends,
    We are using oracle 9.0.1.1.1 db server - the performance of the db was pathetic and upon investigation it was revealed that the library cache was over loaded with sql hard parses generated by not using bind variables. We are using vb as a front end with oracle and our connection object in vb is created using ole db for oracle provided by oracle (installed from oracle client custom - programmer option).
    I would appreciate if any body can tell how can we use bind variables in vb to connect to oracle such that the hard parses can be changed into soft parses.
    Your effort to bring some peace in my life is worth comendable and I would be very obliged for your time and help.
    Thanks a lot.
    Bye
    Take care.
    qj

    Generally, you would use bind variables by changing statements that are written like this
    select * from emp where empno=6678 and ename='Jones'
    so that they're written like
    select * from emp where empno=? and ename=?
    How you then bind these question marks to the particular values you want depends on the API you're using (ADO? OLE DB directly?, etc). If you have a support contract, there are plenty of examples for any API on metalink.oracle.com
    Justin

  • Use of Bind Variable in the Query of view object giving null pointer excep

    I am using this code in the backing bean of my page to set the value of the bind variable 'cmdID' in the view object.
    String AM = "model.UnixCommandsAppMod";
    String CF = "UnixCommandsAppModLocal";
    ApplicationModule am = Configuration.createRootApplicationModule(AM, CF);
    ViewObject vo = am.findViewObject("Command_options_view");
    vo.setNamedWhereClauseParam("cmdID", 1);
    vo.executeQuery();
    On the fifth line it is giving NullPointer exception.
    I am not being able to figure out the reason.

    User,
    a). Don't keep posting new questions in the same thread. It really does decrease the usability of the forum. Now, if someone searches for "INFO: ADF Faces is running with time-stamp checking enabled," they will find a post about null pointer exception in a bind variable and think, "oh, that doesn't apply to me." If your question is answered, mark the answer as correct. New questions go into a new thread. Kind of funny that the thread I pointed you to with the answer to your question also has this same admonishment.. ;)
    b). I'll relent and answer your new question. Ignore that INFO message. It is not an error. It will ALWAYS ALWAYS appear when you run your application in the embedded OC4J with JDeveloper. Had you searched the forum for "INFO: ADF Faces is running with time-stamp checking enabled" you would find that the first hit (among some others) has this same answer
    John

  • Bind variables improve the performence of  query??

    Hi,
    Bind variables improve the performence of program or SQL Query.
    Select empno,ename,sal from emp where empno=:eno;
    select sal into :vno from emp;
    According to these queries i am asking performence of bind variables to learn more from you.
    Regards,
    Venkat.
    Edited by: Venkata2 on Sep 16, 2008 6:40 PM

    Karthick_Arp wrote:
    any variable inside a stored procedure is a bind variable.
    using bind variables can help you avoid hard parse. which leads to performance improvement.
    Well, you mentioned pros and I will mention cons. Since bind variable value is not known until execution time optimizer can not select best plan. So Oracle introduced bind variable peeking where plan is deferred until first execution. With bind variable peeking optimizer costructs plan using bind variable values at the first execution. However, if first execution has "not typical" bind variable values we end up with sub-optimal plan.
    SY.
    P.S. Please do not consider my reply as "we should not use bind variables".

  • Using bind variables in the model view for master detail

    Hi all,
    I have a master-detail views setup on the following two queries.
    In the first query below - I use two bind variables to collect the start and end date.
    you have to add (and :startDate = :startDate and :endDate = :endDate) or you will get errors - bind not defined in sql
    I then use the viewQueryCriteria to collect the data on a search panel - so far so good. (Make the bind variables required) along with the other criteria.
    The bind variables are displayed in the search panel and the data is entered correctly.
    The query executes and all is happy.
    VIEWOBJECT1
    SELECT DepositAccounts.COA_ID,
    ... ChartOfAccounts.ACCOUNT_CODE || ' ' || ChartOfAccounts.ACCOUNT_TITLE as description
    FROM DEPOSIT_ACCOUNTS DepositAccounts, DEPOSIT_ACCOUNT_DETAILS DepositAccountDetails, CHART_OF_ACCOUNTS ChartOfAccounts
    WHERE DepositAccounts.ID = DepositAccountDetails.DEP_ACC_ID
    and ChartOfAccounts.id = DepositAccountDetails.COA_ID
    and :startDate = :startDate and :endDate = :endDate
    Now I add the summation of a value (AMOUNT) to the view object (java - create view impl) to the VOViewRowImpl
    and everything works - the value is shown in the transient attribute formatted and looking nice.
    VIEWOBJECT2
    SELECT PostingBatchAccounts.AMOUNT,
    FROM POSTING_BATCH_ACCOUNTS PostingBatchAccounts, POSTING_BATCHES PostingBatches
    where PostingBatchAccounts.PB_ID = PostingBatches.ID
    and PostingBatches.SOURCE_DATE between :startDate and :endDate
    Now I need to add the start date and end date to the child query - before the view executes (or the summation is calculated).
    The attributes are in the where clause (PostingBatches.SOURCE_DATE between :startDate and :endDate) in VIEWOBJECT2 which is the child.
    I need the child records and the summation to work with the date restrictions.
    I would assume you could get access to the child view in the VOViewImpl file and set the bind variables there.
    Everything I find is based on the JSF - not the model layer - this should be fairly easy (and common). can anyone give me a hand on this?

    Hi all,
    I have a master-detail views setup on the following two queries.
    In the first query below - I use two bind variables to collect the start and end date.
    you have to add (and :startDate = :startDate and :endDate = :endDate) or you will get errors - bind not defined in sql
    I then use the viewQueryCriteria to collect the data on a search panel - so far so good. (Make the bind variables required) along with the other criteria.
    The bind variables are displayed in the search panel and the data is entered correctly.
    The query executes and all is happy.
    VIEWOBJECT1
    SELECT DepositAccounts.COA_ID,
    ... ChartOfAccounts.ACCOUNT_CODE || ' ' || ChartOfAccounts.ACCOUNT_TITLE as description
    FROM DEPOSIT_ACCOUNTS DepositAccounts, DEPOSIT_ACCOUNT_DETAILS DepositAccountDetails, CHART_OF_ACCOUNTS ChartOfAccounts
    WHERE DepositAccounts.ID = DepositAccountDetails.DEP_ACC_ID
    and ChartOfAccounts.id = DepositAccountDetails.COA_ID
    and :startDate = :startDate and :endDate = :endDate
    Now I add the summation of a value (AMOUNT) to the view object (java - create view impl) to the VOViewRowImpl
    and everything works - the value is shown in the transient attribute formatted and looking nice.
    VIEWOBJECT2
    SELECT PostingBatchAccounts.AMOUNT,
    FROM POSTING_BATCH_ACCOUNTS PostingBatchAccounts, POSTING_BATCHES PostingBatches
    where PostingBatchAccounts.PB_ID = PostingBatches.ID
    and PostingBatches.SOURCE_DATE between :startDate and :endDate
    Now I need to add the start date and end date to the child query - before the view executes (or the summation is calculated).
    The attributes are in the where clause (PostingBatches.SOURCE_DATE between :startDate and :endDate) in VIEWOBJECT2 which is the child.
    I need the child records and the summation to work with the date restrictions.
    I would assume you could get access to the child view in the VOViewImpl file and set the bind variables there.
    Everything I find is based on the JSF - not the model layer - this should be fairly easy (and common). can anyone give me a hand on this?

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • How to use bind variable in the query to avoid hard parsing

    Hi,
    I have a query which is using literals
    strquery:='SELECT SUMTOTAL FROM tab1 WHERE BATCHNO = '''
          || gBNo
          || ''' AND A_ID = '''
          || g_id
          || ''' AND L_ID = '''
          || g_LId
          || '''  AND S_Code = ''C_3'' ';
    execute immediate strquery;I have been asked to use a bind variable to avoid hard parsing.
    How do i do it?
    Edited by: user8731258 on Jul 27, 2012 5:07 AM
    Edited by: user8731258 on Jul 27, 2012 5:08 AM

    You dont need Dynamic SQL. Your Table and Column Name are static in that query. Just use Static SQL
    SELECT SUMTOTAL
      INTO lSumTotal
      FROM tab1
    WHERE BATCHNO = gBatchNo
       AND ATM_ID  = gAtm_id
       AND LOAD_ID = gLoadId
       AND STEP_CODE = 'C_3';

  • How do I use an array variable in the assignment target?

    Hi,
    I am creating a BPEL process in which I have to use an array variable. The array variable needs to be initialized based on some condition.
    The issue is I cannot find a way to set the value of the array variable. There are ways to GET the value of an array variable indexing into it.
    But how do I set the value by using the Array variable in the <to> tag?
    Any help is appreciated. I am using BPEL 10.1.2.0.2.
    Thanks.

    You can declare a variable of type integer which will server as your index. Figure out based on some condition in your process which index of array to update. Assign to your integer variable you created.
    And have Assign copy operation like this -
    <copy>
    <from variable="Var_Output_FetchDueDate"
    part="OutputParameters"
    query="/ns18:OutputParameters/ns18:DUEDATE"/>
    <to variable="outputVariable" part="payload"
    query="/client:GetCustomerAccountInformationProcessResponse/client:customer/client:accounts/client:account[$Var_Counter]/client:dueDate"/>
    </copy>
    I have been using this in my processes.

  • How to use a bind variable in an IN clause

    I am trying to use a bind variable in an IN clause where the column is a varchar2 type. Something like:
    select *
    from test
    where test_column in (:bindVariable)I have tried assigning the bind variable comma separated strings (eg. test,test,test) and comma separated strings with quotes (eg. 'test','test','test'). Neither of these work. Does anyone know the correct way to do this?
    Thanks in advance.

    http://tkyte.blogspot.com/2006/06/varying-in-lists.html
    Presents many options.

  • How to use a bind variable in a table-validated flexfield

    Hi,
    I want to prepare a table-validated descriptive flexfield, which uses as source a select statement.
    So, in the form "Validation table information" I use as table name the statement:
    (SELECT my_procedure('test_value') FROM DUAL)
    Up to here it works fine.
    But instead of 'test_value' I want to use the value of a field in the form or a value of another flex (using $FLEX$ bind variables).
    Please advice if it is possible to perform this in "table name" statement. I use it in "where/order by" clauses and it works fine.
    Thank you.

    Hi,
    I have posted in the place where you did advise,
    https://forums.oracle.com/thread/2560192
    but they reply there that this is an EBS question, with no much relation to dev tools in general.
    Please, can I continue in this place with this question?
    Thank you.

  • Using collections / Bind variables with a PL/SQL functio returning a query

    I have this code, which is supposed to assign collection variables as column names
    FOR i in 1 .. Collection_count -1
    LOOP
    SELECT c002 into :P341_M1 FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=i;
    SELECT c002 into varholder FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=i;
    vQuery:= vQuery || 'SUM(decode(label, ''Aware'', product_'|| i || ', ''Expert'', product_' || i || ', ''Proficient'', product_' || i || ', ''Advanced(Demo)'', product_' || i || ' )) as ';
    vQuery:=vQuery || varholder || ', ' ;
    END LOOP;
    I've tried &P341_M1. , :P341_M1, ':P341_M1', varholder
    When I try '&P341_M1' it returns the whole SUM(decode... line as the label
    Basically Im having a hard time using bind variables with the PL/SQL returning a query...anybody?

    Ok so working through this problem more I have realized that the problem is using the for loop i as an index value
    This will get a value:
    SELECT c002 into :P341_M1 FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=2;
    But this won't
    SELECT c002 into :P341_M1 FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=i;
    I'm in the for loop, and use the i variable in other places within this loop...Is there a reason why I can't compare seq_id to i?
    My new code as follows:
    FOR i in 1 .. Collection_count -1 --apex_application.g_f01.COUNT - 1
    LOOP
    varholder:=i;
    SELECT c002 into :P341_M1 FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=2;
    SELECT c002 into varholder FROM APEX_collections WHERE collection_name = 'MA_SKILLS' AND seq_id=4;
    vQuery:= vQuery || 'SUM(decode(label, ''Aware'', product_'|| i || ', ''Expert'', product_' || i || ', ''Proficient'', product_' || i || ', ''Advanced(Demo)'', product_' || i || ' )) as f';
    vQuery:=vQuery || :P341_M1 ||i||', ' ;
    END LOOP;

  • Use of bind variable in repository

    All,
    Our customer has a requirement that they need This year sales Vs Last year Sales by passing the year as a prompt.
    I can not use BI built in function to get Last year start or this year start date as our calendar dates are not standard. So i have to query date dim table to see for ex. for 2010 whats is the start date and so on...
    For this I have created a repository variables to hold these values using a SQL. What I would like to know is can I use a bind variable to this SQL so that when user passes year i can feed that year to this SQL and it will provide me correct start and end date for this year and last year.
    Many thanks in advance

    Yes. We can pass a value what user is selecting from the prompt. For doing that you have create a session variable with "Enable any User to set Value". So in prompt properties for the year column select "Request Variable" for Set a Variable. Then in the content filter use year = 'valueof(NQ_SESSION.myVariable).
    Let me know if this worked.
    Regards,
    Jay

  • Use of Bind variables on Transparent Gateway

    Are there any known issues of using bind variables with queries using the Transparent Gateway? I've included two queries that access data from V_PERSON (alias r) which is a SQL Server 2000 table. We're using TG for MSQL 9.0.1 and calling from an Oracle 8.1.7.4 database.
    All help appreciated.
    - Scott
    SELECT r.lastname,r.email_addr1,MGM_.PHONESTR (r.hmph_ac,r.hmph_number, r.hmph_xten,r.hmph_input),r.hmph_ac,r.hmph_number,r.hmph_xten,r.maiden_name
    FROM V_PERSON r WHERE r.vmn_person_id=184468;
    213 msecs
    SELECT r.lastname,r.email_addr1,MGM_.PHONESTR (r.hmph_ac,r.hmph_number, r.hmph_xten,r.hmph_input),r.hmph_ac,r.hmph_number,r.hmph_xten,r.maiden_name
    FROM V_PERSON r WHERE r.vmn_person_id=:1;
    :1 = 184468
    23 secs

    Scott,
    We are not aware of any issues with bind variables. The time is takes to execute the query depends on the query that is sent over to the non-Oracle system.

  • Use of bind variables in 'IN' operator

    how to use bind variable in the select stmt with 'in' operator?. like
    select * from table_name where col in (:id_list);
    I know we could use it for single value but how do i use bind variable for a list of values
    Thanks

    The IN clause and Stored Procs

  • CAN I PASS A TABLE NAME AS A VARIABLE IN THE FROM CLAUSE?

    For some reason, I am trying to use a variable name containing the actual table name in the from clause and it won't allow me. I keep getting the error saying I need to declare the variable I'm using eventhough I've used it in another statement that is not the FROM clause.
    Example
    SELECT count(col1), sum(col2)
    FROM v_table_name;
    v_table_name was declared as:
    v_tablename VARCHAR2(20);
    v_tablename := real_table_name;
    Is it not allowed to use variables in the FROM clause or am I missing something here?

    You can use the Forms "From Clause Query" as the datasource for the data block. Then you can change the QUERY_DATA_SOURCE_NAME using set_block_property, so you can use any SQL statement you like. Of course you must name/alias the columns in a consistent manner so that the number of database items on the block matches those being queried.

Maybe you are looking for

  • ITunes starts to update the iPod then locks up

    I have a 15GB iPod which was suffering with the chkdsk error, i updated the iTunes software, the iPod software and eventually restored the iPod to its factory settings. When connected I can see the iPod in my computer, in the device manager and in iT

  • RENDER /EXPORT problems with the new CC 2014

    I have updated to the new Premiere pro CC 2014 version. I realise its a standalone upgrade so i deleted the previous cc version from my pc to save disk space... I have a 3 hour file just raw footage, with no plugins on it.... I have tried rendering t

  • Tried to update Itunes and got a runtime error.  now I cannot open Itunes

    trying to update itunes on windows 7 computer and it failed.  now I have a runtime errror R6034 and I cannot get into Itunes at all.  tried to reload Itunes from website and still will not work

  • How to display a confirmation message to the second stage approver.

    Hi, I am working on an application which involves 2 stages of serial approvals. After the first stage approval, the request is forwarded to the second stage. When the second stage approver approves the request, the workflow proceeds with the user cre

  • List ALV - ML85

    Hi everyone, Is possible to assign ALV for tcode ML85? I've tried along the way (IMG > Materials Management > Purchasing > Reporting > Maintain Purchasing Lists > Scope of List), but can not. Thank you, Madi