Using a variable in a view?

I know that it is not possible to use a variable in a view, but I wonder if it isn't a work around? If there is a single value - from another table - you want to reuse in a view that doesn't use dynamic SQL code, how do you then? I've been playing around with statements, but makes me anywhere, I use 11r2.

BTW, please don't ask me the standard litany of questions in anger-dba (why do this? your database is f *, RTFM, etc.), it's just for my own curiosity. :)

Thank you


Example for demo only for purposes (I know that is not syntactically correct):

var_value variable varchar2 (30)
Start
Select this_is_just_one_value
int: var_value
from tableX where column1 = "BOB";
end;

Select
numerous_columns
of tableY
where
column 5 =: var_value.

893968 wrote:

BTW, please don't ask me the standard litany of questions in anger-dba (why do this? your database is f *, RTFM, etc.), it's just for my own curiosity. :)

Why are you doing this? your database is f *! RTFM! Etc! ;-)

SQL is not a procedural language - you can't create a view for example that has a parameter signature. For example, it is possible in a language of the proceedings:

declare
        cursor c( deptID number ) is
                select * from emp where deptno = deptID;
begin
        open c( 1234 ); --// open SQL cursor using a parameter/variable
        --// etc..
        close c;
end;

It is not possible using a SQL object as a point of view. As a vision is not a procedure. If the same approach than what the above using SQL (stupid example, but only shows the basic principles):

// define
create or replace view emp_view as select * from emp;

// use
select * from emp_view where deptno = 1234;

The CBO is smart - and he's probably going to push such a predicate in the SQL emp_view statement.

To set up this view, is ugly. And should only be taken into account in dealing with issues such as data security restrictions. A context is created - this may contain a number of name values. The view can then use a name-value of the context. Oracle data dictionary views using this approach.

Tags: Database

Similar Questions

  • 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

  • How to use substitution variables, as in Microsoft Word using Hyperion Smart view

    Can we use the Substitution Variables to copy data points and cool off in Microsoft Word? I tried and it does not dynamically (copy the data points only copies what was in excellent cell right there). It copies only the static value of this variable for this cell. I want to use dynamically in Word so that if I change the value of this variable in Essbase, it is updated in Word on refresh. Any idea?

    We need this notification feature in microsoft word and keep using data points every year (instead of copy the cells of excellent on new)

    Any help or suggestion is appreciated.

    Thank you

    You may not use substitution variables, as with the copy data points. I tried a while back (after 111.1.2.1.102) and it wouldn't work.  I checked with Oracle development and they said that I is not available

  • It's as possible use IN the operation in view criteria?

    I use Jdeveloper 11 g R (11.1.2.3) & weblogic 10 G

    In my pages, I use JSF & Facelet

    Hi all

    Is there a way to implement operator in view criteria?

    My requirement is just a seelcte like this:

    Select * from EMPLOYEES where EMPLOYEE_ID IN (2339,2340)

    I want 2339,2340 as the variable to view the object then apply view criteria and link

    the list of parameters is not fixed, so I need to use IN the operation

    Thank you

    Mohsen

    Yes, you can do it. Reading decompilation binary ADF: using bind variable for SQL statements with the paragraph

    which shows how.

    Timo

  • Capture selected vales of Date dates invite you using the variable of presentation

    We have an obligation to display the date on the text of the report / whatever the user selects the date from the command prompt.
    We have a date called created and used operator is between.
    Can someone help me in this area, the use of variable presentation to capture the values of a single Date column of creation?

    In the criteria to add more than 2 columns for Date of creation
    and use these expressions foreach and hide them
    MAX (RMAX (creation Date))
    MIN (RMIN (creation Date))

    In your story view we will call @1 and @2. assuming that these 2 columns are first from left to right.

    No need to use variables of the presentation.

    Mark as correct

    Thank you

    Published by: Srini VIEREN on April 22, 2013 16:47

  • How to set a dynamic title using a variable presentation

    Hello every1

    In my dash I want to use a dynamic title: "list of services by", which is based on the prompt of the user 'countries '.
    How can I do this?
    For example when the user selects Morocco, then the title goes: 'lists of services by the Morocco '.

    Thank you

    Hello

    also try this...
    http://bischool.WordPress.com/2009/05/05/presentation-variable-values-in-report-titles-or-using-presentation-variable-in-dashboard-text-object-and-narrative-view-directly/

  • Using global variables in a device custom

    Hello world

    I have problems with the passing of data through my device customized using global variables. I want to allow a user to select a RIO device address when you set up the system definition file. This is recorded in a global variable using the hand Page VI. I would later use this RIO device address in RT driver to deploy a bitfile. I can hard-code, but it is much more convenient to use a global.

    When I try to store the address of the global variable, it updates the value temporarily (I confirmed that the structure of the event recognizes the change of value). When I click the node of the tree to define system linked to the Main Page VI and then click on it again, the hand Page VI runs again. I wrote the code to repopulate the address of device of RIO with the last value stored in the global variable, but it is empty. I've included the VI global variables in my build, so I can't imagine why it can reset this value.

    Any help would be appreciated!

    Thank you

    Mitch

    Have you tried to use the custom device properties to store this value instead of GVs?

    Configuration VI, you can set this property, and if I'm not mistaken, you can read these properties on the RT driver.

  • WARNING: Incompatible Arg. You can't use stack Variables If generating series is not defined

    What does this message mean?

    "WARNING: incompatible Arg. you can't use stack Variables If generating series is undefined."

    Where can I put generate series only?

    Thank you

    Derek

    Hi Derek,.

    Not all LabVIEW C Generator settings are compatible with each other. In this case, you must define generate series only (aka 'disable parallel execution') If you want to generate the code uses the variable stack.

  • Use the variable based on Chncalculate to tiara

    I need to use a variable in the ChnCalculate function but only takes the text then how to incorporate the varaible in text inside this function. It keeps on undefined variable beep where, as I have already defined at the beginning of the program and also value.

    Hi coolguru,

    The syntax error is in your first line, it should be instead:

    GlobaDim "a".

    Brad Turpin
    Support Engineer product DIAdme
    National Instruments

  • Use of Variables shared with RT-project / home-VI

    Hi all

    I have a small question which is certainly easy to answer for those who have already worked with a RT - VI containing two periods loops and a user interface that is deployed on a host PC.

    Q: is there an advantage to the data acquisition in the urgent loop by using a variable shared unique process (active FIFO) and then through the data on the host computer the nondeterministic loop simply through a shared network-published (new FIFO active) variable that directly passes the data on the host PC?

    Thanks in advance,

    David

    Hi Kolibri,

    The advantage of having the network publishes the variables in your non-deterministic loop as opposed to the evanescent loop is that it reduces the resources needed to perform the evanescent loop.

    Send the data to a different loop in the same program with unique shared variable or process with RT FIFOs requires fewer resources than to send data over the network. This allows the loop of high priority execute more deterministic way, without having to manage communication networks.

    Kind regards

    Stephen S.

  • Can I use a variable in step of TS Message for field 'waiting time '?

    Is it possible to use a variable (inhabitants, parameters, etc.) for the field "Wait time" in the stage of message TestStand?

    TestStand 4.1

    Thank you

    Rafi

    Go to the step settings > properties > Expressions > Expression Pre and enter something like:

    Step.TimeToWait = Locals.MyTimeToWait

  • How to change the value of string clustered, to implement using the node value of property instead of writing directly on the flow of data or using the variable

    new to labview :-) and I have a problem when I want to change the value of a string in bunches, and I want to implement this using the node value of property instead of writing directly to the stream or by using the variable, enclosed is the picture.   No matter, I have change in cluster (control) or value of Popery out (indicator) cluster, the value (sensor 7) dataflow keeps unchanged even I gave the new value by value of property node. Thank you to give me some advice about this.

    Hi GerdW

    Thanks a lot for your answer. The reason I'm stubbornly tring to break the flow of DATA is: we have a test system that have about 100 screws, they have a few connected flow, some of them will be unbundling a cluster dataflow chain to check the value in order to make the different cases.  Now I want to insert user event by changing the control and influential cases during run time.

    As I initially uses a global variable (to control cases) instead of unbundle string data flow, it works well.  But then, I found there are a lot of screws that are using the string unbundle.  One of the 'lazy' means, I tried is to change the value via the property node (because that way, I did not need to find all the places where using the unbundle string and replace them with the global variable), then I noticed a problem with "dataflow", the value in the stream of cluster in fact will not be changed by changing the value of the property node.

    I did a test with VI simple (like the picture in last post), and after reading your advice, I tell myself that I need to understand the concept of "DATAFLOW" in labview, it seems that my "lazy" way can not work in this scenario.

    I have attached the criterion VI here, have you furthur suggestions on what I can do in this case?

    Mant thanks!

    Minyi

  • Why LabVIEW example projects using Global Variables?

    I'm puzzled.  I've been pretty good programmers LabVIEW talks (including some who work for the OR) and came away with the impression that Global Variables should, as a general rule, be avoided, with functional Global Variables (alias VI Globals) generally preferred for "local memory".

    I have studied some of the example distributed with LabVIEW, 2012 and 2013, in particular the proposed acquisition in real time and am struck by the use of Global Variables, where I'd be inclined to use instead a FGV.  For examples, to stop all the loops on the RT target, the overall "All the RT loop Stop" is defined; 'Constants' of configuration (such as timeouts, Streme network names, the names of the journal folder) are kept as Globals; Streme network endpoints are stored in Globals.

    [Note - there is a weird spelling of the second word of the network Streme, above - when I tried to post with the correct spelling, I got an error message saying this word is 'not allowed in this community".]  I apologize for the offense, but I must confess that I do not understand what the problem with the help of the spelling of this word...]

    Why use Globals in these cases, rather than write a bunch of VIGs to hold these data?  Note that almost all these Globals are 'Read' essentially (written once when a resource is acquired, for example) or "Read Only" (treated as if they were a constant).  Indeed, read-only variables can be written as a Subvi with only an output terminal, acting as a (visible, due to the icon) constant.

    I can see advantages to this approach.  On the one hand, VIGs can have error bounds who run the data flow (I just spotted a bug "data flow" in code, I am developing that is based on this model, to read configuration data to an XML file in a world and in the same VI, Global wiring to a "use - me" terminal, but with no guarantee that I'll read the overall after I write it).

    It is, I suppose, a matter of 'speed' - perhaps Global Variables are 'faster' than VIGs (especially if the VIG 'sits' on an error line).  My thought, however, is that this difference is likely to be trivial, especially as these VIGs (or Globals) tend to become "occasional" calls (with the exception of the indicator 'all the loop Stop' which is called once per line).

    Are there other arguments or considerations that make a Variable global to a better choice than a VIG?  Is there a reason that LabVIEW developers put in these start-up of projects LabVIEW?

    BS

    I have to ask, how do you use functional Global Variables?  Like just a Get and Set?  If so, you can use a global variable.

    Yes, globals are faster and use much less overhead.  At the summits of CLA in recent years, we talked about using globals.  The most common use is for Write-Once-Read Many and writing-never-Read Many with configuration data.  It's a good idea to use globals with the constants that can change on you.  It turns out that the world will have the same performance as a constant in this case.  This is done so that you don't have 1 place to edit the 'constant '.

    The rule on "Globals are evil" actually goes back several years when NEITHER had the huge "people of the country are bad" vendata.  But NEITHER explains well how to do things properly.  So I found people, instead of using local variables, using the value property node.  It's even worse because the property causes thread swaps and kills your performance.  It wasn't until I shouted to people to use wires and shift registers I have seen improvements in the way in which people wrote their code.  So people are always riffling in the use of globals and decided to use FGVs with the EEG and fixed rather cases.  But this does not solve the problem of the conditions of race with critical data and you cause an additional burden.

    So from my experience, I use globals all the time for configuration data.  Yes, you must be careful about the race conditions.  But as long as you understand that it is a common and useful practice.

    I would not use a global variable for data that are constantly changing (use registers to offset or Action motor) and/or processes that have critical sections of code (use a motor of Action).

    NOTE: I use the definition of Mercer to FGV (a Get/Set only) and motor Action (many cases which specifically affect the data).

  • Limit set using the variable

    IAM having the following query to load the data of my DataModel

    DataSource {
                id: firstSource
                source: "db/duDatabase.db"
                query: "SELECT title FROM how_to ORDER BY howToId ASC limit 10"
                onDataLoaded:
                    {
                        firstModel.insertList(data);
                    }
               }
    

    My Question is:

    How can I use a variable to set the limit in the query

    That is to say, I want something like that

     query: "SELECT title FROM how_to ORDER BY howToId ASC limit variableName"
    

    Please please help me. IAM stuck here.

    query: "SELECT title OF how_to ORDER BY howToId limit of ASC"+ NomDeLaVariable"

  • 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

Maybe you are looking for