Correct Way to use Bind variables when using an MS SQL server backend

Hey,
I'm having some trouble figuring out how to use bind variables in a view when using an MS SQL server backend. For some reason when I'm using an ApplicationModule that has a MS SQL Server JDBC library loaded and I attempt to click OK when editing the following query:
SELECT kit_status, component_id
FROM numbered_inv
WHERE trialname = :1
I get an error stating that "SQL Query Error Message Incorrect Syntax near ':'". Is JDeveloper compatible with SQL server for bind variables because this query runs just fine if I replace the :1 with a say "Testing testing".
Thanks in advance
Edited by: NullCheck on Dec 15, 2010 2:06 PM

Gotcha. I had tried %1% %0% ?0 and ?1 and various other permutations none of which worked. Got it working by setting the query to:
SELECT kit_status, component_id
FROM numbered_inv
WHERE trialname = ?
ORDER BY kit_status
And then adding a bind variable with "Bind position" set to 0.
Thanks again Shay!

Similar Messages

  • Using bind variables (in & out) with dynamic sql

    I got a table that holds pl/sql code snippets to do validations on a set of data. what the code basically does is receiving a ID and returning a number of errors found.
    To execute the code I use dynamic sql with two bind variables.
    When the codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;however when I get to some more complex validations that need to do calculations or execute multiple queries, I'm running into trouble.
    I've boiled the problem down into this:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare
             some_var number;
          begin
          select 1 into some_var from dual
          where :2 = 61;
          :1 := :2;
          end;
          USING OUT counter, IN my_id;
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;this code doesn't really make any sense, but it's just to show you what the problem is. When I execute this code, I get the error
    ORA-6537 OUT bind variable bound to an IN position
    The error doesn't seem to make sense, :2 is the only IN bind variable, and it's only used in a where clause.
    As soon as I remove that where clause , the code will work again (giving me 61-61, in case you liked to know).
    Any idea whats going wrong? Am I just using the bind variables in a way you're not supposed to use them?
    I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

    Correction. With execute immediate binding is by position, but binds do not need to be repeated. So my statement above is incorrect..
    You need to bind it once only - but bind by position. And the bind must match how the bind variable is used.
    If the bind variable never assigns a value in the code, bind as IN.
    If the bind variable assigns a value in the code, bind as OUT.
    If the bind variable assigns a value and is used a variable in any other statement in the code, bind as IN OUT.
    E.g.
    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
    10                  1 into n
    11          from dual
    12          where :var1 = 61;       --// var1 is used as IN
    13 
    14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
    15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
    16  end;
    17  '
    18          using
    19                  in out id, in out cnt;  --// must reflect usage above
    20 
    21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
    22  end;
    23  /
    Procedure created.
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    PL/SQL procedure successfully completed.
    SQL>

  • Using Bind Variable in a procedure

    Hello all,
    Aim - I wanted to set the value of a bind variable in a procedure
    I was unsuccessful in doing so, pls help me (pls let me know if u need more info).
    I have pasted the commands I executed in a SQL
    SQL> VARIABLE x NUMBER;
    SQL> EXEC :x := 5;
    PL/SQL procedure successfully completed.
    SQL> CREATE OR REPLACE PROCEDURE p1
    2 IS
    3 BEGIN
    4 :x := 5;
    5 END;
    6 /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    4/5 PLS-00049: bad bind variable 'X'

    The reason why the 2nd attempt failed is that in PL/SQL declared code (unlike anonymous blocks) you need to use PL/SQL (host) variables as bind variables and not SQL*Plus (host) variables.
    To explain in more detail:
    SQL> VARIABLE x NUMBER;
    SQL> EXEC :x := 5;
    The EXEC creates and transmits the following PL/SQL anonymous block to Oracle:
    begin
      :x := 5;
    end;It also bind the SQL*Plus host variable (defined as X to the bind variable :x).
    All well. But not the procedure P1 will not work. Numerous reasons - including that when I call the P1 proc from Delphi, or Joe calls it from Java, or Jack calls it from ASP - we do not have that SQL*Plus host variable X defined. That does not exist in the context when we make our PL/SQL calls to P1.
    So how can you write P1 so that we all can use it - from any language?
    You provide an input parameter for P1. This allows all of us to bind our host variables to the P1 call. E.g.
    create or replace procedure P1( x IN OUT number ) is
    begin
      x := 5;
    end;Now when you call it from SQL*Plus, you would do the following:
    SQL> var x number
    SQL> exec P1( x=>:X )
    When I call it from Delphi, I will bind my Delphi (host) variable to the procedure call. Ditto for Joe and Jack.
    Note that PL/SQL itself can also use host and bind variables when talking to the SQL engine. E.g.
    create or replace procedure P2( nRows IN OUT number ) is
    begin
      select count(*) into nRows from all_objects;
    end;In this case, nRows in the SQL statement is a SQL bind variable. It is also the PL/SQL host variable. As you can see, this is very similar to what SQL*Plus did with its host variable.
    Bind variables (within PL/SQL) is explained in more detail in the Oracle® Database PL/SQL User's Guide and Reference guide.

  • Query don't use the right index when using bind variables

    Hi people !
    I need some help because I have an issue with a query that don t use the right Indexes as it should
    First of all, I have mainly three tables :
    ORDER : Table that contains description for each Order (approximately 1 000 000 Records)
    ORDER_MVTS : Table that contains the tasks made (called movements) to set up each Orders
    with quantity of packages prepared for each product (approximately 10 000 000 Records)
    PRODUCT : Tables that contains the products (approximately 50 000 Records)
    When I launch the query with hard coded values, it brings back response very fast
    because it uses the right index (ORDER_DHR_VALID) which represent the date and hour of the order
    (with format 'DD/MM/YYYY HH24:MI:SS'). The selectivity for this index is good.
    NB 1: I have to use the trick " >= Trunc(date) and < trunc(date) +1 " to filter on a simple date because
    the index contains hour and minutes (I know it wasn't probably a bright idea at conception time).
    NB 2: The index on ORDER_MVTS.PRODUCT_CODE is'nt discriminating enough because there is'nt enough different products.
    It's the same for index on CUSTOMER_CODE and on MVT_TYPE so only the index on ORDER.DHR_VALID is good.
    Here is the correct explain plan when I execute the query with hard coded values :
    SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS'))
    AND ORDER.DHR_VALID < TRUNC(to_date('14/11/2008 10:04:56','DD/MM/YYYY HH24:MI:SS')) + 1
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = 'ADIDAS'
    AND PRODUCT.CODE = 1234
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    4 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    4 TABLE ACCESS BY INDEX ROWID ORDER
    777 INDEX RANGE SCAN (object id 378119) --> ORDER_DHR_VALID
    2 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    30 INDEX RANGE SCAN (object id 377784) --> ORDER_MVTS_ORDER_FK
    Now the problem is when the query is used in a Cursor with bind variables.
    It seems like Oracle don't use index on ORDER.DHR_VALID because he can't figure out that he have
    to actually filter on a short period of time (only one day).
    So Oracle uses the index on ORDER_MVTS.PRODUCT_CODE which is'nt a bright idea (it takes 10 secondes instead of just one)
    Here is the bad explain plan :
    Rows Row Source Operation
    1 SORT AGGREGATE
    2 NESTED LOOPS
    722 NESTED LOOPS
    2 INDEX UNIQUE SCAN (object id 378548) --> PRODUCT_PK
    722 TABLE ACCESS BY INDEX ROWID ORDER_MVTS
    1790 INDEX RANGE SCAN (object id 377777) --> ORDER_MVTS_PRODUCT_FK
    2 TABLE ACCESS BY INDEX ROWID ORDER
    1442 INDEX UNIQUE SCAN (object id 378439) --> ORDER_PK
    Now I have found two solutions to this problem :
    1) using a Hint to force the use of index on ORDER.DHR_VALID (with /*+ INDEX(ORDER ORDER_DHR_VALID) */ )
    2) Using Dynamic SQL and keeping the date hard coded (but not the other values except mvt_type)
    For example :
    QUERY :=
    'SELECT SUM(ORDER_MVTS.NB_PACKAGE)
    FROM ORDER_MVTS, PRODUCT, ORDER
    WHERE ORDER.DHR_VALID >= TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) '||
    AND ORDER.DHR_VALID < TRUNC(TO_DATE('''||To_char(P_DTE_VAL,'DD/MM/YYYY')||''',''DD/MM/YYYY'')) + 1 '||
    AND ORDER_MVTS.MVT_TYPE = 'DELIVERY'
    AND PRODUCT.CODE = ORDER_MVTS.PRODUCT_CODE
    AND ORDER_MVTS.ORDER_CODE = ORDER.CODE
    AND ORDER.CUSTOMER_CODE = :CUSTOMER
    AND PRODUCT.CODE = :CODE ';
    These two solutions work but Number 1 is bad in theory because it uses a Hint
    and Number 2 may be difficult to code.
    So my question is : Does someone knows another solution to force the use of index ORDER_DHR_VALID that can be simple and reliable.
    Thank you very much for support
    Edited by: remaï on Apr 1, 2009 4:08 PM

    What version of oracle you have? CBO work is different in 9i and 10g.
    Usually cost based optimizer do not want to use index for >< condition with binding variables because optimizer can not use statistic to determine selectivity, and by default selectivity of <> operators is low.
    (As I remember '>' selectivity by default is 5%, you have two conditions > and <, therefore resulting selectivity will be 0.05*0.05=0.0025 as two independent events, but selectivity of other conditions
    ORDER_MVTS.MVT_TYPE = 'DELIVERY' or ORDER.CUSTOMER_CODE = 'ADIDAS' looks much better for CBO)
    The best solution I see is do not use binding variables. Actually your query looks as searching query, which executes not so often, therefore you will not have perfomance win along of skipping execution plan creation.
    Edited by: JustasVred on Apr 1, 2009 10:10 AM

  • Csv no data found when using bind variables

    Hi,
    I have created a report, that uses 2 date variables to limit the query and rows display as they should. But clicking the csv link opens csv having one row stating 'No data found...'. If I set static values in place of variables, I get the right result. How could I use bind variables and get the right answer in csv (without coding my own function)?
    Kaja

    I am having the same problem.
    The export link opens a new session without submitting the current page. The page item values are therefor not saved to cache before the export is undertaken.
    Any report using page item bind variables in the where clause will not export correctly as the bind values are either null or those of the previous page submit.
    Any ideas on how to get round this??

  • Performance when using bind variables

    I'm trying to show myself that bind variables improve performance (I believe it, I just want to see it).
    I've created a simple table of 100,000 records each row a single column of type integer. I populate it with a number between 1 and 100,000
    Now, with a JAVA program I delete 2,000 of the records by performing a loop and using the loop counter in my where predicate.
    My first JAVA program runs without using bind variables as follows:
    loop
    stmt.executeUpdate("delete from nobind_test where id = " + i);
    end loop
    My second JAVA program uses bind variables as follows:
    pstmt = conn.prepareStatement("delete from bind_test where id = ?");
    loop
    pstmt.setString(1, String.valueof(i));
    rs = pstmt.executeQuery();
    end loop;
    Monitoring of v$SQL shows that program one doesn't use bind variables, and program two does use bind variables.
    The trouble is that the program that does not use bind variables runs faster than the bind variable program.
    Can anyone tell me why this would be? Is my test too simple?
    Thanks.

    [email protected] wrote:
    I'm trying to show myself that bind variables improve performance (I believe it, I just want to see it).
    I've created a simple table of 100,000 records each row a single column of type integer. I populate it with a number between 1 and 100,000
    Now, with a JAVA program I delete 2,000 of the records by performing a loop and using the loop counter in my where predicate.
    Monitoring of v$SQL shows that program one doesn't use bind variables, and program two does use bind variables.
    The trouble is that the program that does not use bind variables runs faster than the bind variable program.
    Can anyone tell me why this would be? Is my test too simple?
    The point is that you have to find out where your test is spending most of the time.
    If you've just populated a table with 100,000 records and then start to delete randomly 2,000 of them, the database has to perform a full table scan for each of the records to be deleted.
    So probably most of the time is spent scanning the table over and over again, although most of blocks might already be in your database buffer cache.
    The difference between the hard parse and the soft parse of such a simple statement might be negligible compared to effort it takes to fulfill each delete execution.
    You might want to change the setup of your test: Add a primary key constraint to your test table and delete the rows using this primary key as predicate. Then the time it takes to locate the row to delete should be negligible compared to the hard parse / soft parse difference.
    You probably need to increase your iteration count because deleting 2,000 records this way probably takes too short and introduces measuring issues. Try to delete more rows, then you should be able to spot a significant and constant difference between the two approaches.
    In order to prevent any performance issues from a potentially degenerated index due to numerous DML activities, you could also just change your test case to query for a particular column of the row corresponding to your predicate rather than deleting it.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Query taking too long when using bind variable

    Hi All,
    There is a query in our prod DB which runs very slow (approx 2 hours) when it uses Bind Variables (using JDBC thin client), and when i try passing the variable using TOAD/SQL developer it runs fine.
    Explain Plan for running Query
    SELECT STATEMENT ALL_ROWSCost: 146 Bytes: 379 Cardinality: 1                                                   
         21 SORT ORDER BY Cost: 146 Bytes: 379 Cardinality: 1                                              
              20 NESTED LOOPS Cost: 145 Bytes: 379 Cardinality: 1                                         
                   17 HASH JOIN Cost: 22 Bytes: 42,558 Cardinality: 123                                    
                        15 MERGE JOIN CARTESIAN Cost: 15 Bytes: 8,910 Cardinality: 27                               
                             12 FILTER                          
                                  11 NESTED LOOPS OUTER Cost: 9 Bytes: 316 Cardinality: 1                     
                                       8 NESTED LOOPS OUTER Cost: 8 Bytes: 290 Cardinality: 1                
                                            5 NESTED LOOPS Cost: 6 Bytes: 256 Cardinality: 1           
                                                 2 TABLE ACCESS BY GLOBAL INDEX ROWID TABLE GDP.GDP_FX_DEALS_INCREMENTOR Cost: 4 Bytes: 28 Cardinality: 1 Partition #: 9 Partition access computed by row location     
                                                      1 INDEX RANGE SCAN INDEX GDP.GDP_FX_DEALS_INC_IDX_01 Cost: 3 Cardinality: 1
                                                 4 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 2 Bytes: 228 Cardinality: 1      
                                                      3 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 1 Cardinality: 1
                                            7 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 2 Bytes: 34 Cardinality: 1           
                                                 6 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 1 Cardinality: 1      
                                       10 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_COUNTERPARTIES Cost: 1 Bytes: 26 Cardinality: 1                
                                            9 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.PK_CPTY Cost: 0 Cardinality: 1           
                             14 BUFFER SORT Cost: 14 Bytes: 448 Cardinality: 32                          
                                  13 TABLE ACCESS FULL TABLE GDP.GDP_CITIES Cost: 6 Bytes: 448 Cardinality: 32                     
                        16 TABLE ACCESS FULL TABLE GDP.GDP_AREAS Cost: 6 Bytes: 2,304 Cardinality: 144                               
                   19 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_PORTFOLIOS Cost: 1 Bytes: 33 Cardinality: 1                                    
                        18 INDEX UNIQUE SCAN INDEX (UNIQUE) GDP.PORTFOLIOS_KEY Cost: 0 Cardinality: 1                               
    Explain Plan for Slow Query
    Plan
    SELECT STATEMENT ALL_ROWSCost: 11,526,226 Bytes: 119,281,912 Cardinality: 314,728                                                   
         21 SORT ORDER BY Cost: 11,526,226 Bytes: 119,281,912 Cardinality: 314,728                                              
              20 HASH JOIN Cost: 11,510,350 Bytes: 119,281,912 Cardinality: 314,728                                         
                   2 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_PORTFOLIOS Cost: 1,741 Bytes: 177,540 Cardinality: 5,380                                    
                        1 INDEX FULL SCAN INDEX (UNIQUE) GDP.PORTFOLIOS_KEY Cost: 14 Cardinality: 5,380                               
                   19 HASH JOIN Cost: 11,507,479 Bytes: 87,932,495,360 Cardinality: 254,140,160                                    
                        3 TABLE ACCESS FULL TABLE GDP.GDP_AREAS Cost: 6 Bytes: 2,304 Cardinality: 144                               
                        18 MERGE JOIN CARTESIAN Cost: 11,506,343 Bytes: 18,602,733,930 Cardinality: 56,371,921                               
                             15 FILTER                          
                                  14 HASH JOIN RIGHT OUTER Cost: 3,930,405 Bytes: 556,672,868 Cardinality: 1,761,623                     
                                       5 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_COUNTERPARTIES Cost: 6,763 Bytes: 892,580 Cardinality: 34,330                
                                            4 INDEX FULL SCAN INDEX (UNIQUE) GDP.PK_CPTY Cost: 63 Cardinality: 34,330           
                                       13 HASH JOIN OUTER Cost: 3,923,634 Bytes: 510,870,670 Cardinality: 1,761,623                
                                            10 HASH JOIN Cost: 2,096,894 Bytes: 450,975,488 Cardinality: 1,761,623           
                                                 7 TABLE ACCESS BY GLOBAL INDEX ROWID TABLE GDP.GDP_FX_DEALS_INCREMENTOR Cost: 2,763 Bytes: 52,083,248 Cardinality: 1,860,116 Partition #: 14 Partition access computed by row location     
                                                      6 INDEX RANGE SCAN INDEX GDP.GDP_FX_DEALS_INC_IDX_01 Cost: 480 Cardinality: 334,821
                                                 9 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 1,734,205 Bytes: 8,320,076,820 Cardinality: 36,491,565      
                                                      8 INDEX FULL SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 104,335 Cardinality: 39,200,838
                                            12 TABLE ACCESS BY INDEX ROWID TABLE GDP.GDP_FX_DEALS Cost: 1,733,836 Bytes: 1,331,145,696 Cardinality: 39,151,344           
                                                 11 INDEX FULL SCAN INDEX (UNIQUE) GDP.GDP_FX_DEALS_KEY Cost: 104,335 Cardinality: 39,200,838      
                             17 BUFFER SORT Cost: 11,499,580 Bytes: 448 Cardinality: 32                          
                                  16 TABLE ACCESS FULL TABLE GDP.GDP_CITIES Cost: 4 Bytes: 448 Cardinality: 32                     
    How can I avoid that.
    Thanks

    Hello
    Could you reformat your execution plans because they aren't particularly readable. The forums allow you to preserve the formatting of code or output by putting the symbol {noformat}{noformat} before and after the section of text you want to preserve formatting for. 
    If you write
    {noformat}select * from v$version
    {noformat}
    it will be displayed asselect * from v$version
    So can you run this above statement and post the output here so we know the full oracle version you are working with?  And finally, it would be really helpful to see the query you are running.  When you say it runs fine in Toad, is that when you replace the bind variables with the values or are you also using bind variables in Toad?
    Cheers
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Possible for Oracle to consider constraints when using bind variable?

    Consider the following table with a check constraint listing the possible values of the column
    create table TEST_TABLE(
    my_column varchar2(10));
    insert into TEST_TABLE select 'VALUE1' from dba_objects;
    alter table TEST_TABLE
    add constraint TEST_TABLE_CHK1
    check (my_column in ('VALUE1', 'VALUE2'));
    begin dbms_stats.gather_table_stats(ownname=>user,tabname=>'TEST_TABLE');END;Let's see the number of logical I/O's needed for the following SQL statements.
    (The value was obtained by the delta ofselect m.value from v$mystat m, v$statname n
    where name='session logical reads' and m.statistic#=n.statistic#)
    If string lateral is used:
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE1';
    end;
    Consistent Gets: 21
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE2';
    end;
    Consistent Gets: 21
    declare
       n number;
    begin
      select count(*) into n from test_table where my_column='VALUE3';
    end;
    Consistent Gets: 0Oracle can eliminate the table if it knows the queried value can't satisfy the constraint. Good.
    (Actually, the execution plan for the last query included the 'FILTER' operation.)
    However, if bind variable is used:
    declare
       n number;
       x varchar2(10);
    begin
      x := 'VALUE1';
      select count(*) into n from test_table where my_column=x;
    end;
    Consistent Gets: 21
    declare
       n number;
       x varchar2(10);
    begin
      x := 'VALUE3';
      select count(*) into n from test_table where my_column=x;
    end;
    Consistent Gets: 21Oracle can't eliminate the table using the constraint. I can understand that because bind variables are used, Oracle can't directly eliminate the table when generating the execution plan. However, is it possible to eliminate the table, or at least employ some shortcut in runtime? If not, will this be a performance loss compared with using values laterals when check constraint exists?
    (And is it possible to use autotrace on PL/SQL block in sqlplus?)
    Oracle:
         10.2.0.4 SE
         11.2.0.2 SE
    OS:
         RHEL5

    However, is it possible to eliminate the table, or at least employ some shortcut in runtime? I can't see how to do this. Oracle has a sqltext that has an embedded bind variable in it. And for this sqltext it has an execution plan in the shared pool that will be used irrespective of the actual bound values at runtime.
    Maybe in 11G, with adaptive cursor sharing / plan bind awareness, Oracle might be smart enough to introduce a second execution plan for the VALUE3 case.
    If not, will this be a performance loss compared with using values laterals when check constraint exists?Only if you submit the dumb query and search for records with VALUE3... Normally your application code would not hold/generate these queries.
    Will it?
    For columns whose values are bound by a CHECK constraint, one might even consider to never use bind variables, since very likely you will have few versions of queries that use these columns.
    Not?
    Edited by: Toon Koppelaars on Jun 22, 2011 1:20 PM

  • What's disadvantages when using bind variables always in java?

    Hello everyone .. Could someone tell me what's the disadvantage when using bind variable in java ? I heard it somecases since before.. Thanks in advance!

    99% of the time, you should be using bind variables. If you have columns which are highly skewed, however, you may want to consider using literals (assuming CURSOR_SHARING=EXACT), since that may allow the CBO to make a better decision.
    If you have an orders table, for example, you may have a status column that specifies whether the order is complete, in transit, or new. If you've been running for a while, 99% of your orders will be complete, so
    SELECT COUNT(*)
      FROM orders
    WHERE status = :1should do a full table scan if you specify 'COMPLETE'. If you passed in 'IN TRANSIT', though, an index scan might be more appropriate. If you want to pass in different values and get different query plans, you need to use literals. 99% of the time, though, you want the same plan, so you want to use bind variables.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Using Bind Variable in a SELECT

    Hi,
    I'm trying to build up my SQL query at run-time using bind variables and in the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) it says that 'After defining the bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows bind variables to appear both in the SELECT list and in the WHERE clause, you'll typically use them in the latter context, as part of your WHERE clause.'.
    However, when I try to use the bind variables in my SELECT list because I've had to set a type for the variable to String the variable gets inserted with inverted commas either side e.g. SELECT 'Service' FROM TestTable. Is it possible to use bind variables to insert a value into my select list without these inverted commas around it?
    Thanks in advance,
    Tom

    OK, thanks for your response. Do you know of a way then where I can control my SELECT parameters programmatically? I'm currently trying to do it using the information in the chapter '35.9 Using Programmatic View Objects for Alternative Data Sources' from the Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1). I think I'm part way there, would this be the correct way of acheiving what I want?
    Cheers, Tom

  • ORA-01722: invalid number caused with SQL using bind variable

    Hi,
    Im am hoping that someone can help me resolve a problem thats only just services and is being experienced on quite a few clients.
    our application uses C++ exes and makes OCI calls to the database.
    what has happened in the last week or so, there has been quite a few invalid number errors being received on a prod server but strangly enough we cannot reproduct the error on our UAT system.
    The sql is using bind variables and the information in the trace file shows that a number is being used for the bind variable, here is an extract from one trace file:
    for some schemas, the bind variable value is some currupted value, i think:
    oacdty=01 mxl=32(21) mxlc=00 mal=00 scl=00 pre=00
    oacflg=03 fl2=1206001 frm=01 csi=178 siz=32 off=0
    kxsbbbfp=9a8d62b8 bln=32 avl=03 flg=05
    value="Â*d"
    but on another schema, the value used is:
    Bind#0
    oacdty=01 mxl=32(32) mxlc=00 mal=00 scl=00 pre=00
    oacflg=03 fl2=1206001 frm=01 csi=178 siz=32 off=0
    kxsbbbfp=c5f92718 bln=32 avl=04 flg=05
    value="2101"
    however both produce invalid number errors.
    I am relatively inexperienced as a DBA so would appreciate as much help as i can get.

    Could you post your sql statement that is being run.
    Also post the query plan from your uat system and the one from your production system (They are likely to be different)
    You can export the stats from your production system and run them in your uat system. If you do this, then the execution plans should be the same on both systems(dbms_stats) and if you have the same data you should run into the same problem on uat as in production.
    The root cause of this type of problem is having a column in a table which holds values which are of different datatypes. Typically there is a condition in the where clause which indicates that for example only numeric columns should be retrieved from the column which holds multiple data types. However since the optimizer is free to rewrite the query any way it sees fit, (It does not necessarily execute in the order the sql statement is written) it does not filter this data first, and therefore you hit non-numeric data and run into the invalid number error.
    You can use little techniques like using an inline view with rownum in the column list, to perform the first filter. This ensures that the inline view is executed on its own, rather than being merged (materialized) with the rest of the query.
    A quick temporary solution is to use a comparison like to_char(column_name) = variable
    Make sure your comparisons are correct and it doesn't negatively impact on performance of the query

  • How to use bind variables in desc flexfields in OA pages?

    Use case: In EBS 11i we have a DFF on po_vendors and one of the segment has a table validated value set that is referencing a forms variable i.e :VENDORS.VENDOR_ID. Now after upgrading to R12 this won't work as the vendor pages moved to OA framework. Is there any way to reference the vendor_id column in OA framework?

    976208 wrote:
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    You cannot avoid hard parsing - as the 1st time a SQL statement (like the SELECT or DELETE statements in your code) is encountered, it does not reside in the server's Shared Pool, and needs to be added into the pool via a hard parse.
    Bind variables does not prevent hard parsing. Hard parsing happens when the SQL statement (with or without bind variables) is a brand new statement encountered by the server.
    Bind variables enables the same SQL cursor to be reused, by simply changing the bind variable value.
    Not using bind variables means that each SQL statement is unique and not shareable - as the value is hardcoded into the statement and cannot be changed via a bind value. This typically means LOTS of different SQL statements (where the only difference is the changed value in the statement) are created - with each statement being a new statement not seen before in the Shared Pool and needing to be hard parsed.
    One does not design one's code not to be hard parsed. There ALWAYS will be a hard parse in order to get a SQL statement into the Shared Pool. One designs one's code to REUSE cursors in the Shared Pool.

  • ORA-01006 Using Bind Variables In A Dynamic SQL Contains Query

    I have the following dynamic SQL query :-
    declare
    TYPE typ_sql IS REF CURSOR;
    ltyp_sql typ_sql;
    lv_sql VARCHAR2(100);
    begin
    lv_sql := 'SELECT arx_id FROM arx WHERE CONTAINS ';
    lv_sql := lv_sql || (arx_full,''(:b1) WITHIN ui'') > 0';
    open ltyp_sql FOR v_sql USING ln_id;
    fetch ......
    close ......
    end;
    When the code tries to open the cursor it gives the above error. I presume it is the way Oracle is expanding the bind variable but I cannot find anything in the docs to say why this is happening or whether you can do this or not using bind variables ( CONTAINS query ). Any help would be appreciated, thanks,
    Stuart.

    lv_sql || '(arx_full, :b1 || '' within ui'') > 0';

  • Using bind variable in dynamic where clause and concatenate with query

    Hi,
    In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
    Is it possible to pass values to the bind variable through the dynamic variable/value?
    Please advise
    Thanks in advance
    Siva
    IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
    My query is like this
    open Out_Main FOR SelectQuery USING optional_using

    Thanks for reply,
    In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
    Please advise...
    IF in_assignedAppFlag IS NOT NULL THEN
              IF in_assignedAppFlag = 'Y' THEN
                   optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
              optional_using := ' in_appFuncGroup'||',in_currentUserID';          
              ELSe
                   IF in_isSupervisor = 0 THEN
                        optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID';
                   END IF;
              END IF;
         ELSE
              IF in_isSupervisor = 0 THEN
                   optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
                   optional_using := ' in_appFuncGroup'||',in_currentUserID';
              END IF;
         END IF;
         IF in_appFuncGroup IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
         END IF;
         IF in_queue_id IS NOT NULL THEN
              optional_where := optional_where || ' AND b.QUEUE_ID = :d';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
         END IF;
         IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
         IF in_sourceCode IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode';
         END IF;
         IF in_logo IS NOT NULL THEN
              optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
         END IF;
         IF in_firstName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
         END IF;
         IF in_surName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
         END IF;
         IF in_retreival_id IS NOT NULL THEN
              optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
         END IF;

  • Report Using Bind Variables

    Hey Everyone,
    I'm having a bit of trouble creating a report. I need the FROM part of the code to use bind variables. I have come up with this peice of code below but im getting the following error:
    failed to parse SQL query:
    ORA-06550: line 1, column 8:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    begin function package pragma procedure subtype type use
    form
    current cursor
    The symbol "" was ignored.
    ORA-06550: line 2, column 24:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    begin function package pragma procedure subtype type use
    form
    current
    Can anyone see where im going wrong?
    Thanks in advance,
    -N.S.N.O.
    Code*
    DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := x || 'select *';
    x := x || 'from ';
    x := x || :p13_schema;
    x := x || '.ddl_log@';
    x := x || :p13_db_name;
    x := x || '_DBAAPEX.TNTEWW.COM';
    RETURN (x);
    END;

    Hey Roel and Daylocks,
    After getting frustrated for a while i deleted the page and started again. I put in the exact same code and it worked just how i wanted in the first place :S
    The only thing i did different is when i was creating the report region the first time around i used a normal SQL query, For Example:
    select sysdate from dual;
    Then i modified it to
    DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := x || 'select ';*
    x := x || 'from ';
    x := x || :p14_schema;
    x := x || '.ddl_log@';
    x := x || :p14_db_name;
    x := x || '_DBAAPEX.TNTEWW.COM';
    RETURN (x);
    END;
    Whereas on the second attempt i used the peice of code in question straight away. Its been a bit of a frustrating morning because i used a similar peice of code for a different application, nevermind tho :)
    Thanks for your replys, much appreciated.
    -N.S.N.O.

Maybe you are looking for

  • Error while copying the Root Organization Unit.

    Hi Experts, Can any one help me in copying the existing Orgnaization structure root in SRM , Because I have requirement like need to create a separate root with independent node under the Old one. so when try to copy the Org structure root node and c

  • "file server is running on your machine" message

    OK, this seems very weird & I can't figure out if the issue is in my new (simultaneous dual band) Airport Extreme or the Mac (iMac G5) I use to administer it. When I try to connect to a USB drive connected to the Extreme from my iMac, & the iMac is c

  • HT201210 i cant update my iphone via itune. ERROR message 1015. have updated everything, still didn't work out

    i cant update my iphone via itune. ERROR message 1015. have updated and done all the trouble shooting, still didn't work out. I tried, reinstalling everything, nothing happens, this is suck! can't use my iphone!

  • Add On costs to the Inventory at sales plant.

    Hello Consultants, My client is an automotive client we move the finished goods from Prod.Plant to sales plant . Fin. goods at sales plant are valuated at MAP with Split valuation based on serial number . The client wants to add some add on costs to

  • Polling in jsp

    Dear All, I'm an absolute newbe in .jsp programming, however I've to build a poll for a site for a rowing competition. Now recentley I saw an interesting poll at http://www.club-vaio.sony-europe.com/clubvaio/en/home.jsp now I did wonder if someone kn