Variable vs hardcoded value in SQL query

Hi Gurus,
I have a SQL query inside a function that looks similar (i'm showing the "where" clause here only) to the below:
WHERE ID = variable_id (by the way this two have exactly the same type, number(20))
and
WHERE ID = 100
In the first option that uses variable it takes 4 secs to complete the query, while the second one that uses hardcoded value completes in milliseonds. Im new to oracle but been to other dbms and havent seen such behaviour. Anyone encountered or know what maybe the cause? I thought of not pasting here the explain plan since its just a question of variable vs hardcoded value.
rgds.

Just want to add something, here is the stats for the two queries:
Statistics for variable_id (15 secs)
29 recursive calls
0 db block gets
24324 consistent gets
21556 physical reads
0 redo size
20676 bytes sent via SQL*Net to client
613 bytes received via SQL*Net from client
25 SQL*Net roundtrips to/from client
17 sorts (memory)
0 sorts (disk)
358 rows processed
Statistics for hardcoded value (5 secs)
4 recursive calls
0 db block gets
2631 consistent gets
0 physical reads
0 redo size
20469 bytes sent via SQL*Net to client
613 bytes received via SQL*Net from client
25 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
358 rows processed
There are differences consistent gets and physical reads. What coul dbe the problem here?
tnx!

Similar Messages

  • Setting a Default Value in SQL Query Report

    Hello:
    We are using a SQL Query Report to provide a mass update to a table. We are using the apex.collection and having it display a number of records in a SQL Query Report for mass update. We have 14 columns in the report, for which the first 11 are populated via the collection. The remaining 3 are open for input but the individual making the updates. We've were able to provide a default value for 2 of the remaining 3 columns using a named LOV's - however the fourth column we would like to default a sysdate - but we are not successful.
    We've attempted many things but none seem to work, including adding that column to the collection and assigning it a default sysdate value. We've also tried changing the settings in the report attributes --> Tabular Form Elements by setting the Display as to: Datepicker, Default type to PL/SQL Expression and setting the default to sysdate. We've also tried caputuring a date on the previous page and loading it onto the report page and trying to default the date column to a page item default.
    I'd appreciate any help.
    Thanks
    FYI - we are using version 3.2

    use as default
    to_char(sysdate, 'dd/mm/yyy') where the format is your application or item date format

  • Get a insert session value for SQL query at report

    Hi friends
    I created a global temp table and procedure to support web search form.
    and a search result report. The procudure
    gets search result from multip tables and
    insert into temp table --recordsearch. I can get value from temp table  by call procedure
    at SQL*Plus.
    However, I can not get this value by web report.
    How can I get this insert session value and pass to SQL query for report?
    Thanks,
    Newweb
    CREATE GLOBAL TEMPORARY TABLE recordsearch
    (emp_id          VARCHAR2(200),
    ssn               VARCHAR2(9),
    fname          VARCHAR2(200),
    lname           VARCHAR2(200),
    m_name          VARCHAR2(200)
    ) ON COMMIT PRESERVE ROWS;

    it possible that your web form does not have a persistent, dedicated connection. if you have connection pooling for example, multiple sessions will see the same instance of the GTT, so if one deletes it, then nobody sees it (or you can see others data). if the connections are not persistent, then they can disconnect between calls, deleting the GTT table.

  • How to capture a parameter value in SQL QUERY of scale marker using GO URL

    Hi,
    Can any one please tell me how to capture the parameter value from go url inside Where clause of Scale Marker.
    I am trying to sift the position of scale marker based on SQL Query.
    Thanks-Bhaskar Gouda.
    Edited by: 961171 on Sep 25, 2012 12:33 AM

    Since this is a synchronous interface, where source is a soap(proxy) call and target is JDBC in the first mapping both of them are request scenarios.
    Source Structure:
    RootNode
        Request             1...unbounded
           No_of_Days   1.1 String
    Target Structure:
    RootNode
       Statement
         TableName
             Action mapped to SQL_QUERY
            Access -  SELECT DISTINCT AL.EC_NO,DP.DATE_TO_FORMAL FROM T_APPLICATION_LIST AL,(SELECT DE.EC_NO AS "EC_NO", DE.PACKAGE_NO AS "PACKAGE_NO",PC.DATE_TO_FORMAL AS "DATE_TO_FORMAL" FROM DAICYO_ECNO DE,PACKAGECTL PC WHERE DE.PACKAGE_NO = PC.PACKAGE_NO AND PC.DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$'))) DP WHERE AL.EC_NO IN  (SELECT EC_NO FROM DAICYO_ECNO WHERE PACKAGE_NO IN (SELECT PACKAGE_NO FROM PACKAGECTL WHERE DATE_TO_FORMAL > (TRUNC(SYSDATE) - to_number('$No_Of_DAYS$')))) AND (AL.FAMILY = ''  or  '' is null and AL.FAMILY is not null ) and DP.EC_NO = AL.EC_NO ORDER BY DATE_TO_FORMAL
         Key
          No_Of_Days   1..1 String
    In Return I am expecting a JDBC response from the Oracle Database as:
    Source Structure:
    RootNode
      STATEMENT_response   1...unbounded
         row                               0...undbounded
           EC_NO                        1..1   String
    Target Structure:
    RootNode
      RESPONSE
        row
         EC_NO                     1..1     String

  • How-To populate SELECT LIST default value from SQL Query

    OK, I've done my homework, and did not find my answer in the Forum, so here it is.
    I have a Page that displays fields from a SQL Query. The Page also has below that radiogroups, checkboxes, and Select Lists to allow the user to change values in the fields that are displayed at the top of the Region. I am able to pre-populate the radiogroups and checkboxes by performing a SELECT in the 'Source value or expression' of the Source area of the Page Item.
    However, I am unable to do the same for the Select List fields. Their default value ends up being the first value in the LOV ('-- None --' for NULL values). Source Used: Only when current value in session state is null. Source Type: SQL Query. Also, when I first go into the Page when running it, and check the Session State values, they are all null, so I don't understand why the field is not populated by the SQL Query statement as the radiogroups and checkboxes are.
    Any suggestions??? I've tried all sorts of combinations.

    Thank you for the suggestion.
    I had considered that, but cannot do so, because we are using Oracle Application Express more for development than for data containment.
    We have all our data in an Oracle 10.g DB which is separate from the OAEX server, and the OAEX app will reference that data via VIEWs and DB LINKs. We are doing so primarily as an added data security layer, where the data is housed separate from the app, in case the Web site is ever compromised. The data that can be viewed is restricted to a subset of the actual data that is available.
    Since the data is on a separate server, (I assume) we will not be able to set the source type to Database column, because (I asume) that is dependent upon the data being housed by the OAEX server.
    That still leaves me with having to populate the field with a SELECT statement from the Oracle DB. This unfortuneately is almost a show-stopper for me because of down-stream processing data requirements. Have not been able to come up with contingencies yet.

  • ADF BC / Why bind variables are mandatory in the sql query

    I got this error during view object excecution in the component browser :
    (oracle.jbo.SQLStmtException) JBO-27122: Erreur SQL lors de la préparation d'une instruction. Instruction : SELECT * FROM (Select distinct(socialgroup.socialgroup_i) from socialgroup, socialgroupmember, lodgingallocation, lodge
    where socialgroup.socialgroup_i = socialgroupmember.socialgroup_i and socialgroupmember.t_socialgrouprole_i = t_rolegroup_ipar.fgetflextypologyclassitem_i(t_rolegroup_ipar.fisbeneficiary) and socialgroupmember.datefrom <= :DateTo and nvl(socialgroupmember.dateto, :DateFrom) >= :DateFrom and socialgroupmember.requester_i = lodgingallocation.requester_i and lodgingallocation.datefrom <= :DateTo and nvl(lodgingAllocation.DateTo, :DateFrom) >= :DateFrom and lodgingallocation.lodge_i = lodge.lodge_i) QRSLT ORDER BY "SOCIALGROUP_I"
    ----- LEVEL 1: DETAIL 0-----
    (java.sql.SQLException) Tentative de définition d'un nom de paramètre qui ne se trouve pas dans le SQL: T_SICategory_I
    The bind variables T_SICategory_I is not yet use in the sql query but will be used later so i defined it for the view object.
    Is it a reason that the run time check this ? It would be more convenient to set the bind variables early when defining the view object and add them later during the development iteration.

    Design-time defined named bind variables can be marked as required, or not.
    This is decided by the use in the where clause or in view criteria. In my case the bind variable was not used in where clause neither in view criteria and that causes the error.
    May be i would be nice to add a check box (a flag) that enable or disable the bind variables for this checking so we will be able to let it defined even we removed some part of the query corresponding to the corresponding restriction or we defined it earlier for a part of the query that is not yet defined.
    In my current case i fully defined the bind variables but would refine my query later ... in that cause i would have to remove this bind variable and loose all the definitions to run this view object.
    sorry for my english ...

  • Fill default value with SQL query or by an other way

    Hello everyone,
    I use Jdeveloper 11g and Weblogic.
    when I click on create button, I would like fill id_employee field automatically with the current user. I think there is a possibility in default value but I don't know how.
    My query is: SELECT Employee.ID_EMPLOYEE FROM Employee WHERE Employee.EMPLOYEE_NAME = :userName
    userName is a bind variable with this value: #{facesContext.externalContext.userPrincipal.name}
    If there is an other way I accept. Maybe with createwithparams, I tried but I didn't success.
    Please help me, I spent 2 weeks for this small problem.
    Thank you
    Regards

    Hi,
    if using ADF BC, you the create with params operation of the Viewobject to create a new row. On the created action binding, use the right mouse button to create a "NamedData" entry. Set the name of this entry to the name of the attribute you want to add teh default value to. In the NDValue field use EL to reference the authenticated user
    Frank
    Ps.: Your query is not a create statement, so I hope you are not confusing usecases here

  • Deafaul Value using SQL query

    Hi
    I'm trying to make a default value using Computations;
    when I create computation,
    I select
    Computation item: PXX_TEST
    computation type: SQL query
    computation Point: I tried all
    Computation: select X FROM Y WHERE X= '1'
    This is the way to get Default Value ??
    I need to display the value when the page is open
    Thanks
    MM

    MM,
    You can use the default value attribute of the item to set a value if the item's source produces a null. A computation (before/after header) can work too, but it's possible that the item source and Source Used attribute (Always/Only) are interfering with your computation so you might want to try setting Source Used to 'Only...' if you have a computation setting the item.
    Scott

  • Setting Default value with SQL Query as Data Model

    Hi All,
    I am developing report based on SQL query.date set as 'SQL Query'. I have created two params start-date and end-date. I am fetching records from database between these two dates.
    I want to populate sysdate as a default values. I do not want to use datatemplate approach i mean using beforeReport trigger.
    Thansk,
    Vara

    Hi Vara,
    To set the default value for one of your parameters to SYSDATE you need to enter:
    {$SYSDATE()$}
    in the Default Value text box
    Is this what you require?
    Cheers
    Andy

  • Retrieving a single value from sql:query

    Hi all, pretty new to jsp and tag libraries so appoligies if this isn't the correct forum or my question is a bit lame...
    I've got a basic input form written in JSP and i'm trying to use AJAX to return a customers name when they input there customer IS. My AJAX interaction works ok and so far i have got it to return a string value to indicate if the customer ID is valid or invalid.
    However, now i want to return the customers name based on a SELECT SQL statement. My sql works ok but i can't figure out how to return / access the single cname field that is returned. ALL the <sql:query> examples that i have seen use a <c:forEach> loop but this doesn't seem to work for me.
    My AJAX / Jsp code looks like this:
    <%@ page contentType="text/html" info="Customer Id Lookup" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <sql:setDataSource scope="application"
       driver="com.mysql.jdbc.Driver"
       url="jdbc:mysql://localhost:3306/dbawp"
       user="*******"
       password="********"
    />
    <sql:query var="qryValidCustomer" >
        SELECT cname FROM camper WHERE cid = ?;
        <sql:param value="${param.data}"/>
    </sql:query>
    <c:choose>
    <c:when test="${qryValidCustomer.rowCount == 0}">
    unknown camper
    </c:when>
    <c:otherwise>
    <c:forEach items="${qryValidCustomer.row}" var="row">
    ${fn:escapeXml(row.cname)}                                                         <- Doesn't seem to work - i get nothing returned
    </c:forEach>
    <%--good camper--%>
    </c:otherwise>   
    </c:choose>Can anyone point me in the right direction?
    Manythanks in advance,
    Sam

    > my db fields contain a list of sections, " 1,2,3,4,"
    When you find yourself storing delimited lists in a field,
    that's a sign that you should
    normalize
    your data. Storing lists is difficult to query, error prone and bad
    for performance.
    A separate table should be used to represent a many-to-many
    relationship.
    Table - Columns
    Advertisement - AdvertisementID, AdvertisementDescription,
    ...other columns
    Type - TypeID, TypeTitle, ...
    AdvertisementType - AdvertisementID, TypeID
    Instead of storing the related types as a list
    AdvertisementID | TypeID
    1 | 1,2,3,4
    Store them as separate records in the 3rd table
    AdvertisementID, TypeID
    1, 1 (ad # 1, type # 1)
    1, 2 (ad # 1, type # 2)
    1, 3 (ad # 1, type # 3)
    1, 4 (ad # 1, type # 4)

  • How can I pass value from sql query to unix script

    I am new to oracle/unix.
    I want to write a simple script to find max date from a table and then pass date into a variable in a korn shell script.
    sql is select max(date) from table;
    how can I pass that value in unix shell as a variable. Thanks

    I use to code like this.
    Enjoy Scripting.
    cmd.sql
    select sysdate from dual;
    exit
    db.sh
    #! /usr/bin/ksh
    . ~oracle/.orapaths
    dbdate=$(sqlplus -S user/pwd@servicename @cmd.sql)
    echo $dbdate
    Run shell scripts
    ./db.sh
    SYSDATE --------- 19-JAN-07

  • Variable with proposed value in BEX Query View

    Dear SAP-Gurus,
    I have a Web Application with some views on one query. In the inital screen i show the popup for entering the global variable values. Now my question; is it possible to give a global variable used filled by exit and used in these queries a proposed value, receeived by user exit?
    With normal query this works, but not with a query view.
    any suggestions?
    kind regards.
    Jürgen

    Hi,
    if anyone has the same problem - you just have to set the parameter variables_clear=x in webtemplate.
    same applies to bookmarks, if you want the variables to be filled by your exit.
    regards
    Jürgen

  • Hardcode value in sql statement

    Hi,
    This may be a simple thing which I'm missing.
    I'm trying to hardcode numeric value in my SQL statement
    '1.0000' AS NUMBER (10,4) - It returns value as 1 instead of 1.0000
    '1.1255' AS NUMBER(10,4) - returns 1.1255
    I need my o/p to be as 1.0000 not as 1.Is there anyway I can get the result as I'm looking for
    Thanks in advance

    Hi,
    847750 wrote:
    Hi,
    This may be a simple thing which I'm missing.
    I'm trying to hardcode numeric value in my SQL statement
    '1.0000' AS NUMBER (10,4) - It returns value as 1 instead of 1.0000
    '1.1255' AS NUMBER(10,4) - returns 1.1255
    I need my o/p to be as 1.0000 not as 1.Is there anyway I can get the result as I'm looking for
    Thanks in advance
    It's hard to tell what you really want to do from such a tiny code fragment.
    Whenever you have a question, post a complete test script that people can run to re-create the problem and test their ideas.
    The value 1 is exactly the same as the value 1.0000; there is no difference between those numbers.
    If you want to display a number in a certain format (e.g. '1.0000' instead of '1'), the front end is probably the best place to do that.
    If you're using SQL*Plus as the front end, you can set the display for the column called increase_pct like this:
    COLUMN  increase_pct  FORMAT 990.0000
    This will make it display the numbers in that column with at least 1 digit to the left of the decimal point, and exactly 4 digits to the right of the decimal point.
    Other front end tools have similar features.
    If you need to do the equivalent in SQL, use the TO_CHAR function, like this
    SELECT  ename
    ,       TO_CHAR (sal, '99999.00')   AS salary
    FROM    scott.emp
    If you really are hard-coding literals, you can hard code a string, such as '1.0000'.  Don't CAST it to a NUMBER..

  • How to read repeated tag values using sql query

    Database version
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE 11.2.0.2.0 Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Question
    How to get repeated tag values?
    <TXLife>
    <TXLifeRequest>
    <TransRefGUID>10bc80e7d60e59b0:a134d0:10d7c4674ad:-7ffd</TransRefGUID>
    <TransType tc="1203">OLI_TRANS_TRNHLD</TransType>
    <TransExeDate>2011-02-27</TransExeDate>
    <TransExeTime>15:06:35</TransExeTime>
    <InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
    <InquiryView>
    <InquiryViewCode>PLANUPDATE_CHBM_1203A</InquiryViewCode>
    </InquiryView>
    <OLifE>
    <SourceInfo>
    <SourceInfoName>CHBM Admin Tool</SourceInfoName>
    </SourceInfo>
    <Activity id="Activity1" HoldingID="Holding1">
    <UserCode>User123</UserCode>
    <LastUpdate>2011-02-27</LastUpdate>
    <ActivityCode>CHBM10001</ActivityCode>
    <OLifEExtension VendorCode="0098" ExtensionCode="Activity">
    <ActivityExtension>
    <SubActivityCode>CHBM20002</SubActivityCode>
    <LastUpdateTime>15:06:35</LastUpdateTime>
    </ActivityExtension>
    </OLifEExtension>
    </Activity>
    <Holding id="Holding1">
    <HoldingTypeCode tc="6">Group Master Contract</HoldingTypeCode>
    <Purpose tc="36">Business Protection and Preservation</Purpose>
    <Policy>
    <CarrierAdminSystem>CHBM</CarrierAdminSystem>
    <PolNumber>CHB0001234</PolNumber>
    <OLifEExtension VendorCode="0098" ExtensionCode="Policy">
    <PolicyExtension>
    <BillingDetail>
    <PaymentMode tc="3">Quarterly</PaymentMode>
    <BillingOrder tc="1009800002">Employee ID</BillingOrder>
    </BillingDetail>
    <SalaryAllotment>12354333</SalaryAllotment>
    </PolicyExtension>
    </OLifEExtension>
    </Policy>
    <Attachment id="Attach1">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 4</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:05:45</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach2">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>System</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Event 3</Description>
    <AttachmentData>Event Log</AttachmentData>
    <AttachmentType tc="1009800001">Transaction Log</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>1</Sequence>
    <CreationTime>16:01:54</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    <Attachment id="Attach3">
    <DateCreated>2011-02-27</DateCreated>
    <UserCode>P62350</UserCode>
    <AttachmentBasicType tc="1">Text</AttachmentBasicType>
    <Description>Note 2</Description>
    <AttachmentData>Enter notes on changes or edits to plan</AttachmentData>
    <AttachmentType tc="14">Note</AttachmentType>
    <AttachmentLocation tc="1">Inline</AttachmentLocation>
    <OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
    <AttachmentExtension>
    <Sequence>2</Sequence>
    <CreationTime>16:02:23</CreationTime>
    </AttachmentExtension>
    </OLifEExtension>
    </Attachment>
    </Holding>
    </OLifE>
    </TXLifeRequest>
    </TXLife>
    Expected output shoulb be like this
    Description AttachmentType AttachmentData
    Event 4 Transaction Log Event Log
    Event 3 Transaction Log Event Log
    Note 2 Note Enter notes on changes or edits to plan
    Please help me any one on this
    Edited by: LRAJESH on Apr 20, 2011 8:27 AM

    SELECT
    t2. Description des,
    t2.AttachmentType attty,
    t2.DateCreated DateCreated,
    t2.UserCode UserCode,
    t1.Planid Planid,
    t2.createdtime,
    t1.Ausercode Ausercode
    FROM (
    SELECT xData doc
    FROM dual
    ) temp_table,
    XMLTable ( '/TXLife/TXLifeRequest/OLifE' passing doc
    COLUMNS
    Planid varchar2(20) path 'Holding/Policy/PolNumber',
    AttachmentType xmltype path 'Holding//Attachment' ,
    Ausercode varchar2(20) path 'Activity/UserCode'
    ) t1,
    XMLTable
    '/Attachment'
    passing t1.AttachmentType
    columns
    Description varchar2(1000) path 'Description',
    AttachmentType varchar2(1000) path 'AttachmentType/@tc',
    DateCreated varchar2(20) path 'DateCreated',
    createdtime varchar2(20) path 'OLifEExtension/AttachmentExtension/CreationTime',
    UserCode varchar2(200) path 'UserCode'
    ) t2

  • Viewing blob datatype value using sql query

    How can i view the text stored in a column of data type blob.
    Thanks.

    using pl/sql developer sql window i want to see the result.Is there any way of converting blob type to varchar type

Maybe you are looking for

  • How do i use file sharing with my microsoft pc and mac book?

    I have a windows vista pc that my daughter uses and I have a macbook pro and we want to use file sharing for our itunes libararys.  We connect to internet with my time capsule.  I have both computers itunes file sharing turned on but I can't seem to

  • Redirect some users on signon (Tools 8.50)

    All, I have a requirement for a subset of my users (those possessing a certain role) to be redirected to a particular page at logon (i.e. they need to be forwarded to a page without seeing the PIA homepage). These users need to use the same PeopleSof

  • Dropdown and lifecycle

    I've been testing a very simple page with a dropdown list which is bounded to an ArrayList, a button to display "hello" and an outputtext where the "hello" string will be displayed. The dropdown selectitems value is bounded to the arraylist. The arra

  • Format duel HD MacBook Pro Help??

    Hi everyone ok im looking to do a full format of my Mac just to generally clean everything up as it got a little slow recently. Im just not sure how to go about this as I have 2 Drives in the machine, the first is a 64gb SSD which is in an optibay wh

  • "No Name" drive Icon in "Devices" section. What is this?

    During a work trip, a folder popped up on my desktop. "No Name" but with an icon below Macintosh HD and iDisk under "Devices". It looks like it has people walking across the box, but I cannot see closely. It could be protractors too... It will not ej