Estimate of poor cardinality using Bind Variables

Hi I'm using the 11.2.0.4.0 Oracle version. I have a query that is underway for the plan of the poor execution by the estimate of poor cardinality for two tables (I've extracted and published this part only) as I mentioned below, the individual conditions for which the estimate goes bad and moving entire query execution path.

These are for two tables and currently we use BIND variable for them in our code, and I notice, its best estimate gives with literals. I need to know how to handle this scenario that I need this query to execute for all types of volumes. Is there something I can do without changing the code, as it works well for most of the execution? In the current scenario of the main query that uses those below tables providing a plan (index + nested loop) that works very well for small volume, but running for 10 hr + for large volume as ideally its going to the same regime.
And Yes, most time that this request will be hit for small volume, but killing some appearance of large volume presents the performance of the queries.


Here are the values of the variable binding.

B1 VARIABLE VARCHAR2 (32);
B2 VARIABLE VARCHAR2 (32);
B3 VARIABLE NUMBER;
B4 VARIABLE VARCHAR2 (32);
B7 VARIABLE VARCHAR2 (32);
B5 VARIABLE NUMBER;
B6 VARIABLE NUMBER;

EXEC: B1: = 'NONE ';
EXEC: B2: = NULL;
EXEC: B3: = 0;
EXEC: B4: = NULL;
EXEC: B7: = NULL;
EXEC: B5: = 0;
EXEC: B6: = 0;

---- For  TABLE1-------
 -- Published Actual VS Etimated cardinality
 
 
-- With bind values
select * from TABLE1 SF
WHERE (   (SF.C1_IDCODE = :B4) OR (NVL (:B4, 'NONE') = 'NONE'))
    AND ( (SF.C2_ID = :B3) OR (NVL (:B3, 0) = 0));
Plan hash value: 2590266031
-----------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                 | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |                     |      1 |        |  28835 |00:00:00.08 |    2748 |     46 |       |       |          |
|*  1 |  TABLE ACCESS STORAGE FULL| TABLE1              |      1 |     11 |  28835 |00:00:00.08 |    2748 |     46 |  1025K|  1025K|          |
-----------------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - storage((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0)))
       filter((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0))) 
 
-- With literals 
select * from TABLE1 SF
 WHERE  (   (SF.C1_IDCODE = null) OR (NVL (null, 'NONE') = 'NONE'))
      AND ( (SF.C2_ID = 0) OR (NVL (0, 0) = 0));
   Plan hash value: 2590266031
--------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                 | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |                     |      1 |        |  28835 |00:00:00.03 |    2748 |       |       |          |
|   1 |  TABLE ACCESS STORAGE FULL| TABLE1              |      1 |  28835 |  28835 |00:00:00.03 |    2748 |  1025K|  1025K|          |
--------------------------------------------------------------------------------------------------------------------------------------

--------For TABLE2 ----------------------- 
-- Published Autotrace plan, as it was taking long time for completion, and actual cardinality is 45M, but its estimating 49 With bind value---

--withbind value
select * from TABLE2 MTF
WHERE (   (MTF.C6_CODE = TRIM (:B2)) OR (NVL (:B2, 'NONE') = 'NONE'))
  AND (   (MTF.C3_CODE = :B1)  OR (NVL (:B1, 'NONE') = 'NONE'))
  AND (   (MTF.C4_CODE = :B7)  OR (:B7 IS NULL))
  AND (   (MTF.C5_AMT <= :B6)  OR (NVL (:B6, 0) = 0))
  AND (   (MTF.C5_AMT >= :B5)  OR (NVL (:B5, 0) = 0));
Execution Plan
----------------------------------------------------------
Plan hash value: 1536592532
-----------------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name         | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |              |    49 | 10437 |   358K  (1)| 01:11:43 |       |    |
|   1 |  PARTITION RANGE ALL       |              |    49 | 10437 |   358K  (1)| 01:11:43 |     1 |  2 |
|*  2 |   TABLE ACCESS STORAGE FULL| TABLE2       |    49 | 10437 |   358K  (1)| 01:11:43 |     1 |  2 |
-----------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - storage(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR
              NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND
              ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR
              NVL(:B2,'NONE')='NONE'))
       filter(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR
              NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND
              ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR
              NVL(:B2,'NONE')='NONE'))
  
-- with literal
select * from TABLE2 MTF
WHERE (   (MTF.C6_CODE = TRIM (null)) OR (NVL (null, 'NONE') = 'NONE'))
 AND (   (MTF.C3_CODE = 'NONE') OR (NVL ('NONE', 'NONE') = 'NONE'))
  AND (   (MTF.C4_CODE = null)  OR (null IS NULL))
   AND (   (MTF.C5_AMT <= 0)  OR (NVL (0, 0) = 0))
  AND (   (MTF.C5_AMT >= 0)  OR (NVL (0, 0) = 0));
Execution Plan
----------------------------------------------------------
Plan hash value: 1536592532
-----------------------------------------------------------------------------------------------------------
| Id  | Operation                  | Name         | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT           |              |    45M|  9151M|   358K  (1)| 01:11:41 |       |    |
|   1 |  PARTITION RANGE ALL       |              |    45M|  9151M|   358K  (1)| 01:11:41 |     1 |  2 |
|   2 |   TABLE ACCESS STORAGE FULL| TABLE2 |    45M|  9151M|   358K  (1)| 01:11:41 |     1 |  2 |
-----------------------------------------------------------------------------------------------------------

select column_name,num_nulls,num_distinct,density
from dba_tab_col_statistics where table_name='TABLE2'
and column_name in ('C3_CODE','C4_CODE','C5_AMT','C6_CODE');
C3_CODE 0 65 0.0153846153846154
C4_CODE 0 2 0.5
C5_AMT 0 21544 4.64166357222429E-5
C6_CODE 1889955 71 0.0140845070422535

933257 wrote:

((SF. C1_IDCODE =: B4) OR (NVL (: B4, 'NONE') = 'NONE'))

In fact for literals, I did not find any section of the predicate after running the sql code with activation "set autotrace traceonly explain."

The main problem is with another large query whose cardinality is underestimated due to the presence of these table (table1, table2) with the above mentioned clause, and the query is for the analysis of index + nested with values of Bind loops and take 10 hr +, whereas with literals, its completion in ~ 8minutes with FTS + Hash Join.

Your real problem is that you try to have just a single SQL query handle all POSSIBLE thanks to the use of embedded FILTERS ' either / or ' filters in the WHERE clause.  You want only a select this OPTION to run whatever filters have been selected at run time by the user or the application using it.  And it would never work.  You really need to SELECT different queries for different combinations of filter conditions.

Why?  Think for a minute.  How Oracle works internally?  A SQL SELECT query gets analyzed and an execution plan is produced which is stored in the library cache and gets REUSED on all subsequent executions of this query - except in certain cases where there may exist several plans run through several cursors of the child.  So with only SELECT a query you only AN execution plan in the library cache, to be used by all THE executions of this query, regardless of the value of your run-time binding variables.

Lets put another way - each library cache execution plan is associated with a SQL statement.  If you want a DIFFERENT execution plan then you need run a DIFFERENT SQL statement.  That's how you get a different execution plan - by running a different SQL statement.  Running the SAME SQL query generally you will get the SAME execution plan every time.

In addition, because of the "either / or" filters that you use you will end up generally with a full Table Scan on each of the referenced tables.  Why?  Given that the optimizer must produce an implementation plan that manages all possible contingencies for all values of possible bind variables in the SELECT.  If the optimizer should choose to use any index based on one of these "either / or" filters then it would only help performance when real value was provided, but it would be really bad if a NULL value was supplied.  If the optimizer ends up ignoring the index because they are not always optimal for all possible input values and instead chose a plan that is "good enough" for all input values possible.  That means that it will use a scanning Table full.

I hope you can see that it is precisely what is happening for you with your query.  You select this OPTION to manage the different combinations of filter, which leads to the execution plan only one, which leads to scans full Table on the referenced tables in these ' either / or ' filters.

The solution?  Build queries SELECT DIFFERENT when input values are NULL.  How you do that?  Read this article to ask Tom that tells you:

http://www.Oracle.com/technetwork/issue-archive/2009/09-Jul/o49asktom-090487.html

To sum up - when you have real value for a bind variable 'bind_var1' add the following filter to your CHOICE:

AND column_name1 =: bind_var1

When the binding variable is NULL, add the filter according to your CHOICE:

AND (1 = 1 OR: bind_var1 IS NULL)

Now, you'll have 2 queries SELECT must be performed, which have exactly the same number of variables in the same order bind, which is important.  When you then run one of these variations, Oracle can analyze and optimize each one SEPARATELY, with a single execution by the SELECT query plan.

When you provide a real value, the filter is a normal 'column = value' that the optimizer can use all indexes on this column, because NULL values are not referenced.

When there is no real value, the optimizer will analyze the '1 = 1 GOLD' and realize that "1 = 1" is set to TRUE and GOLD, it is quite TRUE regardless because the binding variable is null or not.  This means that the optimizer will actually REMOVE this filter, because it filters nothing because it is always TRUE.  You will end up with an operating plan based on the other filters in the query, which is what you want because you have no filter on this column.

What is it - producing distinct SELECT queries to determine if you have a real value to filter or not you end up with DIFFERENT execution plans for each of them, and each of them is OPTIMAL for this particular set of filters.  Now you get good performance for each variation of the performance of the SELECTION, rather than sometimes good and sometimes very bad when using SELECT only one.  It is impossible to try to get multiple shots of execution 'optimal' out of a SELECT query.  That's why you get mediocre performance under different bound the values of the variables.

John Brady

Tags: Database

Similar Questions

  • Problem using bind variables in shared components report queries

    Greetings,

    I use APEX 4.0.1.00.03 and BI Publisher 10.1.3.4.1.

    In the APEX, I try to create a report query that uses bind variables in the where clause. I have a page that contains a button and a text element (P1_ID). The button is used to call the report. I went the shared components and created a new report query. Here is the text of the code.
    select violation_date
    , violation_type
    , nvl(:P1_ID,'zzz')
    from edd_procard_violations
    where upper(card_holder_id) = upper(:P1_ID)
    I also have Session State to enabled and have added the P1_ID in the area of 'State of Session' under the query.

    When I change the query, and click on the 'Set Bind Variables' button, I get a field where I can enter a value for: P1_ID I enter a value that should return lines, but when I click on the button "Test query", I get no rows returned. If I comment on where clause and test the query, even once, I get all rows in the table. You'll notice in my query I have included nvl(:P1_ID,'zzz'). When I run the query, without where clause, the returned value is always "zzz" indicating that: P1_ID is null.

    No idea what I am doing wrong?

    Thank you very much.
    Larry

    Hello Larry,.

    Looks like the wizard to create a report query in the shared components has a bug related to bind variables. I was able to reproduce your problem. Just create the query using the link variable, check the box to include session state, add the item and create the query. When you use the report query to download the report, where the your clause will work fine.

    Thank you
    Machaan

  • Correct way to use Bind variables when you use an interface to MS SQL Server

    Hey,.
    I have some difficulty to find how to use bind variables in a view, when you use an interface to MS SQL Server. For some reason when I use an ApplicationModule who has a library of MS SQL Server JDBC loaded and I try to click on OK when you change the following query:

    SELECT kit_status, component_id
    OF numbered_inv
    WHERE trialname =: 1

    I get an error stating that ' SQL Query Error Message incorrect syntax near ':'. JDeveloper is compatible with SQL server for bind variable as this query works fine if I replace the: 1 with a Word to say "Test test".

    Thanks in advance

    Edited by: NullCheck December 15, 2010 14:06

    Use positional JDBC Style Binding to bind variables
    Try to use? Instead of:
    As shown here:
    http://www.Oracle.com/technetwork/developer-tools/jdev/multidatabaseapp-085183.html

  • PL/SQL using bind variable to delete records

    Hello

    I'm currently implementing PL/SQL using bind variables to remove records from the "item_progress" table in the simple join query where I'm passing itemName, itemLoc and orderLoc in the delete query in pl/sql block.

    Please suggest, it should be easy for oracle experts...

    (a) I need first records in the item_progress table by using the join query and then update of status in the renew_item table.
    (b) it works fine if I use the simple removal with a condition that is ("DELETE from item_progress where itemname =: 1' using itemname1").

    (c) but it gives an error when I run it using delete with join:
    ---------------------------------------
    * Invalid relational operator ORA-00920:
    ORA-06512: at "SE", line 14 (it's the deletion with the join... "DELETE FROM item_progress WHERE item_id IN (SELECT ip.item_id'...)" ....'
    ORA-06512: at line 10
    Process exited.*
    ---------------------------------------

    create or replace PROCEDURE PUT (itemName IN VARCHAR2,
    itemLoc IN VARCHAR2,
    orderLoc IN VARCHAR2) is
    itemName1 varchar2 (30);
    itemLoc1 varchar2 (30);
    orderLoc1 varchar2 (30);
    BEGIN
    orderLoc1: = ' C: test/local /';
    itemLoc1: = ' / / L123/R;
    itemName1: = 'AAA ';

    immediate execution

    "DELETE FROM item_progress WHERE item_id IN (SELECT ip.item_id FROM ip, item_order io item_progress WHERE io.orderlocation: = 1 AND ip.order_id io.order_id UNION SELECT item_id FROM item_progress WHERE ITEMLOCATION =: = 2) AND itemname: = 3' using orderloc1, itemloc1, itemname1;"

    -"DELETE from item_progress where itemname =: 1' using itemname1; -IT WORKS FINE
    -Once the above query is updated to success, the status in another table
    -Renew_item update the Status value = "RENEWED" where ITEMNAME =: 1, ITEMLOCATION =: 2 using itemname1, itemloc1;

    commit;
    END OPERATIONS;

    user10828299 wrote:
    Please suggest, it should be easy for oracle experts...

    You have made a typo. bind variables are preceded by two points, while you put a colon in front of the equality operator that he listens to it in the PL/SQL assignment operator. Change:

    WHERE io.orderlocation : = 1

    TO

    IO.orderlocation WHERE =:1

    Change:

    WHERE ITEMLOCATION : = 2

    TO:

    WHERE ITEMLOCATION =:2

    Change

    AND itemname : = 3

    TO:

    AND itemname =:3

    SY.

  • Using Bind Variable in a SELECT statement

    Hello

    I am trying to build my SQL query running using bind variables and in Oracle® Fusion Middleware Fusion developer Guide for Oracle Application Development Framework 11 g Release 1 (11.1.1) it is said that ' after you define bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows you to bind variables to appear in the SELECT list and in the WHERE clause, you'll generally use them in this context, as part of your WHERE clause. ».

    However, when I try to use bind variables in my SELECT list because I had set a type to the string of the variable variable is inserted with quotes each side for example SELECT TestTable FROM 'Service '. Is it possible to use bind variables to insert a value in my list of selection without the quotes around it?

    Thanks in advance,
    Tom

    Hi Robinst,

    I think you want to set up column name of the table that is not possible using bind variables. With the help of the bind variables you can send a value to the SQL. The String value is therefore always with inverted commas.

    Kind regards

    Branislav

  • Report using Bind Variables

    Hey everybody,

    I have a little trouble to create a report. I need the FROM part of the code in order to use bind variables. I came up with this piece of code below, but im getting the following error:

    Failed to parse the SQL query:
    ORA-06550: line 1, column 8:
    PLS-00103: encountered the symbol "" when expecting one of the following values:

    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 values:

    begin function package pragma procedure subtype type use
    form
    course

    Where can I see im 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;

    AHA, but when you have changed the source, have you also changed the Type (from "SQL query" to "SQL Query-PL/SQL function return SQL Query")?
    And clicked on "use generic names (analysis of query runtime only) column" option below the source code?

  • How to get SQL that do not use bind variables

    Hello

    I am trying to identify the SQL code which should benefit from the use of bind variables.
    First of all, I tried to get the common signature of all the sql calls, using:
    select * from (
    select  force_matching_signature, count(1) from v$sql where force_matching_signature<>0 group by force_matching_signature order by 2 desc
    ) where rownum < 50;
    Then I copied these values to the Clipboard and run:
    select sql_text from v$sql where force_matching_signature=<<<copied_signature_value>>>;
    Now, I want to make it automatically and get only 1 occurrence of each SQL that resembles others by using a query.

    I tried this:
    select sql_text from
    (
    select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc)rn from v$sql where force_matching_signature <>0
    )where rn <2 and rownum < 10 order by force_matching_signature desc
    But it is not returning results by showing up at the count (1) from the first query, I've used. How can I change this if I get the results in order of "importance"?




    Thank you

    And I said. First use the command by then use rownum. I did not mention row_number. Also, there should be no need to add more columns.
    Have you tried it? Why it did not work?

    example not tested

    select * from (
       select sql_text from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn from v$sql where force_matching_signature != 0)
       where rn = 1
       order by force_matching_signature desc /* add any ordering you like here */
       )
    where rownum < 10  /* then filter on the first 10 results */
    

    If you want to order that the statement that found most of the time comes first, say so. However, I don't see how to group in your case.
    Maybe like this

    example of tested

    select * from (
       select cnt, sql_text
       from (select sql_text, force_matching_signature, row_number() over (partition by force_matching_signature order by sql_text desc) rn , count(*) over (partition by force_matching_signature) cnt
             from v$sql
             where force_matching_signature != 0)
       where rn = 1
       order by cnt desc, force_matching_signature desc /* add any ordering you like here */
       )
    where rownum < 10  /* then filter on the first 10 results */
    ;
    

    Published by: Sven w. October 11, 2012 14:49

    Published by: Sven w. October 11, 2012 14:51

    Published by: Sven w. on October 11, 2012 14:56 - number column added to the output

  • printing problem in pdf and csv using bind variables

    Hello

    I created a simple sql statement using a query and bind variables. I noticed when I remove the bind variables and hardcode the values that the CSV/PDF links work. When I handed the return variables in the query, the WB shows "no data found" and pdf shows only the column header.

    If anyone can help me, I would be very happy!


    Thank you
    Ayed P.

    Hello

    How are set the bind variable? If there are topics evaluated by default on the elements of the page, so is not necessarily enough to ensure that the exports are their values. To set values, I tend to use calculations, conditional that the element is null, what works "Before Header". In this way, the value is stored in the session and is available for export. I think the defaults to be those that are defined when the page is submitted and are not available until now.

    Andy

  • Can OBIEE use Bind Variables?

    I doubt that it would be used for warehouse queries, but I'm the question arises. Has anyone used in OBIEE?

    [Here is a brief summary about them. | http://www.akadia.com/services/ora_bind_variables.html]

    I checked with the support of Oracle and it's official - OBIEE does not support the bind variable.

  • APEX 4.0: &gt; Charts: chart of queries using Bind variables &gt; does not?

    SITUATION
    -Attempt to pass a value to the variable in a query.
    -The value of the variable is taken from a page element.
    -SQL is built using a function that returns the SQL


    QUESTION
    -Table returns "no data found".
    -When we hard code the value, the data is returned and the graphic works.
    -SQL works fine in SQL Browser and Toad
    -Reproduce this problem on 3.2
    -Have you tried the two bind syntax (+: point +) and v (v ('item')) syntax

    If anyone else has experienced this? No idea how to fix?

    Walter,

    Perhaps a better way to get the logic you are looking for is to keep it in the process.

    A few examples:
    1. you can use the conditional rendering process so that it fires only when the values of the elements are NULL.
    2. you can use the conditional process rendering so that it fires when the value of the claim is equal to something and then set it via the link to the page.
    3. you can do it directly in the code:

    BEGIN
    
       IF :P2_ITEM IS NULL
       THEN
          :P2_ITEM := 'Some default value';
       END IF;
    
    END; 
    

    Kind regards
    Dan

    Blog: http://DanielMcGhan.us/
    Work: http://SkillBuilders.com/apex/

  • Problem with the selection list dynamic LOV using bind variables

    I have the following SQL to fill a selection list:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on ck.family = ft.famt_name and ck.newseq in (: NEWSEQ_QUERY_SQL)
    )

    Where NEWSEQ_QUERY_SQL is a part of the application that is defined by a calculation of page and essentially returns a list of values NEWSEQ based on some parameters of the user query. For example:

    Select distinct (ck.newseq) in the ck list where rownum < 20

    The query above works fine with SQL Developer and returns two columns needed (display_value, return_value)

    However, it returns no line, when it is used to fill the LOV to a selection list.

    If I replace the: NEWSEQ_QUERY_SQL with a list of NEWSEQ hard-coded, it works:

    Select d, ch from to)
    Select ft. FAMT_NAME d, pi. FAM_ID_T r
    of FAMILY_TRA ft join checklist ck on (ck.family = ft.famt_name and ck.newseq in ('K0242900', 'K0217200'))
    ) ;

    I can even replace: NEWSEQ_QUERY_SQL with hard-coded SQL and it works:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from the list ck where rownum < 20))
    )

    But if there is a connection variable (: NEWSEQ_QUERY_SQL), it doesn't.

    Selection lists are driving me crazy! They seem incredibly capricious.

    Hello:

    You cannot link a "sql statement" that bind the value you're trying to do.
    P2_FAMILY_LIST must be the SQL statement you executed for the LOV. Something like

    select d, r from
    (
    select ft.FAMT_NAME d, ft.FAM_ID_T r from FAMILY_TRA ft
    join checklist ck
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from checklist ck where rownum < 20))
    )
    

    CITY

  • How to use bind variable to update the DB 11 GR 2 access data

    Hello Experts,

    By DB version 11 GR 2

    Operating system Windows Server 2012 - 64 bit

    I want to update some data base record Access to oracle with database link. Here is my SQL, which works.

    UPDATE Transaction@DB_LINK
    SET "WorkCode"=1
    WHERE "WorkCode"=0; 
    

    But, I need to change that to

    UPDATE Transaction@DB_LINK
    SET "WorkCode"=1
    WHERE "DateTime"=:VARIABLE_DATE_TIME; 
    

    and a 2nd does not.

    Any code help or example?

    Ask2Learn

    Hello

    Use DBMS_HS_PASSTHROUGH

    try something of

    DECLARE
      c       BINARY_INTEGER;
      nr      NUMBER;
    BEGIN
    
      c := DBMS_HS_PASSTHROUGH.OPEN_CURSOR@DB_LINK;
    
      DBMS_HS_PASSTHROUGH.PARSE@ATTD_ENVOYF(c,'UPDATE Transaction@ATTD_ENVOYF SET "WorkCode"=1
      where "DateTime" = '||''||VARIABLE_DATE_TIME||'');
      nr:=DBMS_HS_PASSTHROUGH.EXECUTE_NON_QUERY@DB_LINK(c);
      DBMS_HS_PASSTHROUGH.CLOSE_CURSOR@DB_LINK(c);
    
    END;
    

    Hope this helps

    Hamid

  • Run immediately by using bind variable in plsql

    Hello

    I have the procedure which has the status valid .

    SQL > create or replace PROCEDURE (p_CLGProcExcl_s_by_Db_Name_T)

    2 v_Database_name in VARCHAR2 DEFAULT NULL,

    3 cv_1 SYS_REFCURSOR to)

    4

    5 AS

    6 v_SQL VARCHAR2 (2000);

    7    /*

    8. check the table of CLGProcExclusions for columns (lke inserts\updates\deletes) and procs which do not return.  This will prevent

    9 the clg.exe to try to run all these without reason (since all its trying to do is determine what than the willreturn procs).

    10 that this saving thousands back and forth to the DB.

    11 However, the unfavorable to DELETE in the beging erases all procedures that may have been changed since the last time

    CLG 12 determined that it should be excluded column generation routines.

    13 * /

    BEGIN 14

    15 v_SQL: = ' delete object, e CLGProcExclusions e I

    where the 16

    17 i.owner = "' | v_Database_name | " '

    18 AND i.object_name = e.Procedure_Name

    19 AND i.LAST_DDL_TIME > e.CreatedDate';

    20 execute immediate v_SQL using v_Database_name;

    21 OPEN cv_1 to SELECT v_Database_name Database_Name, PROCEDURE_NAME OF CLGProcExclusions WHERE Database_Name is v_Database_name;.

    22 END;

    I have test, run this procedure using SQL developer tool, but encounter following error:

    ORA-00933: SQL not correctly completed command.

    ORA-06512: at "DBCC_CLG. P_CLGPROCEXCL_S_BY_DB_NAME_T', line 20

    ORA-06512: at line 7

    Recognizing the help / suggestion on this.

    Thank you.

    Why use dynamic SQL statements? You can simply do this.

    create or replace procedure p_clgprocexcl_s_by_db_name_t
    (
        v_database_name in   varchar2 default null
      , cv_1            out  sys_refcursor
    )
    as
      v_sql varchar2(2000);
    begin
      delete
        from clgprocexclusions a
       where exists
             (
                select null
                  from all_objects o
                 where o.owner          = v_database_name
                   and o.object_name    = a.procedure_name
                   and o.last_ddl_time  > a.createddate
             );
    
      open cv_1
      for
      select v_database_name database_name
           , procedure_name
        from clgprocexclusions
       where database_name = v_database_name ;
    end;
    
  • Using using Cluase for dynamic cursors using Bind Variables.

    Hello

    I have a quick question. I build dynamic cursor depends on the setting. The one here is my common charly.

    I use the 5 parameter in place several in my query. So, I use almost 40 values if I used with would adopt it. Is there another way to manage rather than spend 40 times.
    SELECT
            decode(GROUPING(nvl2(p_level5, nvl(hier.LVL6,''UNKNOWN''), nvl2(p_level4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(p_level3, nvl(hier.LVL4,''UNKNOWN''), nvl2(p_level2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(p_level1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))))), '1', 'Total',
              nvl2(p_level5, nvl(hier.LVL6,''UNKNOWN''), nvl2(p_level4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(p_level3, nvl(hier.LVL4,''UNKNOWN''), nvl2(p_level2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(p_level1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))))) NAME,
              SUM(kpi),
              .....
    from  tb_test1,...
    where  WHERE upper(nvl(LVL1, ''UNKNOWN'')) = upper(nvl(p_level1, LVL1))
            AND upper(nvl(LVL2, ''UNKNOWN'')) = upper(nvl(p_level2, LVL2))
            AND upper(nvl(LVL3, ''UNKNOWN'')) = upper(nvl(p_level3, LVL3))
            AND upper(nvl(LVL4, ''UNKNOWN'')) = upper(nvl(p_level4, LVL4))
            AND upper(nvl(LVL5, ''UNKNOWN'')) = upper(nvl(p_level5, LVL5))
            AND upper(nvl(LVL6, ''UNKNOWN'')) = upper(nvl(p_level6, LVL6))
          GROUP BY ROLLUP(nvl2(p_level5, nvl(hier.LVL6,''UNKNOWN''), nvl2(p_level4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(p_level3, nvl(hier.LVL4,''UNKNOWN''), nvl2(p_level2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(p_level1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN'')))))))
          ORDER BY nvl2(p_level5, nvl(hier.LVL6,''UNKNOWN''), nvl2(p_level4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(p_level3, nvl(hier.LVL4,''UNKNOWN''), nvl2(p_level2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(p_level1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))));
    Appreciated your help.

    Kind regards
    Vincent.

    Just capture once inside SQL, then use local versions of their

    for example

    with t as (select p_level1 as pl1
                     ,p_level2 as pl2
                     ,p_level3 as pl3
                     ,p_level4 as pl4
                     ,p_level5 as pl5
               from dual)
    SELECT
            decode(GROUPING(nvl2(pl5, nvl(hier.LVL6,''UNKNOWN''), nvl2(pl4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(pl3, nvl(hier.LVL4,''UNKNOWN''), nvl2(pl2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(pl1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))))), '1', 'Total',
              nvl2(pl5, nvl(hier.LVL6,''UNKNOWN''), nvl2(pl4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(pl3, nvl(hier.LVL4,''UNKNOWN''), nvl2(pl2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(pl1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))))) NAME,
              SUM(kpi),
              .....
    from  t, tb_test1,...
    where  WHERE upper(nvl(LVL1, ''UNKNOWN'')) = upper(nvl(pl1, LVL1))
            AND upper(nvl(LVL2, ''UNKNOWN'')) = upper(nvl(pl2, LVL2))
            AND upper(nvl(LVL3, ''UNKNOWN'')) = upper(nvl(pl3, LVL3))
            AND upper(nvl(LVL4, ''UNKNOWN'')) = upper(nvl(pl4, LVL4))
            AND upper(nvl(LVL5, ''UNKNOWN'')) = upper(nvl(pl5, LVL5))
            AND upper(nvl(LVL6, ''UNKNOWN'')) = upper(nvl(p_level6, LVL6))
          GROUP BY ROLLUP(nvl2(pl5, nvl(hier.LVL6,''UNKNOWN''), nvl2(pl4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(pl3, nvl(hier.LVL4,''UNKNOWN''), nvl2(pl2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(pl1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN'')))))))
          ORDER BY nvl2(pl5, nvl(hier.LVL6,''UNKNOWN''), nvl2(pl4, nvl(hier.LVL5,''UNKNOWN''),
              nvl2(pl3, nvl(hier.LVL4,''UNKNOWN''), nvl2(pl2, nvl(hier.LVL3,''UNKNOWN''),
              nvl2(pl1, nvl(hier.LVL2,''UNKNOWN''), nvl(hier.LVL1,''UNKNOWN''))))));
    
  • Using bind variable to allow the user the place where complete clause.

    Hello

    I have a question like that I am able to run in SQL_Developer:
    SELECT INITCAP(c.name) AS "Species Name"
         , AVG(b.height) AS "Avg Height (m)"
      FROM smt_plot_index a
         , smt_photo_plot_data b
         , smt_species_names c
     WHERE a.plot_id = b.plot_id
       AND b.species_name_id = c.species_name_id
       AND a.plot_id IN (2473201,2473202)
     GROUP BY c.name
    But I'd like to do the following in an apex application:
    SELECT INITCAP(c.name) AS "Species Name"
         , AVG(b.height) AS "Avg Height (m)"
      FROM smt_plot_index a
         , smt_photo_plot_data b
         , smt_species_names c
     WHERE a.plot_id = b.plot_id
       AND b.species_name_id = c.species_name_id
       AND a.plot_id IN ( :P11_ENTER_PLOT_NUMBERS )
     GROUP BY c.name
    But this returns an error:

    error report:
    ORA-01722: invalid number

    I know that if I included only one number for example 2473201 in the element: P11_ENTER_PLOT_NUMBERS it market, but if I try and enter the following text in the element 2473201,2473202 it does not work. The screen session state, said that the value of the item is correct depending on how I entered it.

    Anyone have any solutions for this?
    Thank you
    Ben

    Published by: Benton on May 6, 2010 13:54

    Very strange... read the whole message again, there is already something, you should change: INSTR (': ' |: P11_ENTER_PLOT_NUMBERS |': ',' :'|| a.plot_id |': ') > 0 use INSTR ("," |: P11_ENTER_PLOT_NUMBERS |) ',', ',' || a.plot_id | ', ') > 0

    When you use one as a separator instead of:

    You can try to run in the SQL Developer and see how it works?
    If it works, then you would look in session state to see what values are actually used.

    I tried with BLAKE as a value in P1_TEST and that seems to work:
    Select *.
    WCP
    where INSTR (': ' |: P1_TEST |': ',' :'||) Ename |': ') > 0

    Hope that helps,
    Dimitri

Maybe you are looking for