SQL Query in JSP with variable problem

Researching this but I haven't found an answer yet. I want to pass a user variable to the SQL query. Anyone know how? Thought the form call out might work but it doesn't. Thanks!     <%
     String selectX = request.getParameter("choice");
     String pSQLStr = "SELECT asset, tenant FROM fritco WHERE asset = '::selectX::'";
          try
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection con = DriverManager.getConnection("jdbc:odbc:MyDataSource", "username", "password");
          Statement stmt = con.createStatement();
          ResultSet result = stmt.executeQuery(pSQLStr);

Yes.
Use a Prepared Statement.
Saves you from sql injection attacks.
String selectX = request.getParameter("choice");
String pSQLStr = "SELECT asset, tenant FROM fritco WHERE asset = ?";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:MyDataSource", "username", "password");
PreparedStatement stmt = con.prepareStatement(pSQLStr);
stmt.setString(1, selectX);
ResultSet result = stmt.executeQuery(); Suggestions for improvements.
- Set up a JNDI datasource to retrieve your connection from. WIll do connection pooling for you, rather than creating a new DB connection each time.
- Don't have any sql code in your JSP at all - that should be in beans.
- If sql code MUST be in your JSP, use a taglib for it like the JSTL sql taglib
- Don't use scriptlet code (<% %>) in JSPs. If you want to run java code use beans/servlets.
Cheers,
evnafets

Similar Messages

  • Can I put a SQL query into a bind variable and then use it to output report

    Hi,
    Can I put a SQL query into a bind variable and then use it to output report?
    I want to create a report and an item "text area" (say P1_TEXT) which can let user to input a SQL query(they are all technical users and knows SQL very well). Then, I use a bind variable (that text area) to store the SQL statement. Then, I add a submit button and I want to use the following to output the report:
    select * from (:P1_TEXT);
    Do you think it is possible to do that? Any known limitations for APEX in this area?
    Thanks a lot,
    Angela

    You can, but make sure it's what you really want to do. Make sure you are VERY familiar with SQL Injection. Most people who know what it is, go out of their way to prevent SQL Injection. You're going out of your way to allow it.
    You can try using &P1_TEXT. instead of bind variable syntax. Bind variables are one of the best ways to prevent SQL Injection, which is why it's not working for you.
    Once again, I strongly urge you to consider the implications of your app, but this suggestion should get it working.
    Tyler

  • SQL Query updateable report with row selector. Update process.

    I have a SQL Query updateable report with the row selector(s).
    How would I identify the row selector in an update process on the page.
    I would like to update certain columns to a value of a select box on the page.
    Using the basic:
    UPDATE table_name
    SET column1=value
    WHERE some_column=some_value
    I would need to do:
    UPDATE table_name
    SET column1= :P1_select
    WHERE [row selector] = ?
    Now sure how to identify the [row selector] and/or validate it is checked.
    Thanks,
    Bob

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • Sql Query in JSP

    Hi All
    Had a quick question about a SQL Query in a JSP - Can I duplicated an exact same record in a table with a new primary key without using the insert statement??
    Say for example I have the following table:
    OrderNo OrderName OrderType
    ======= ========== ========
    1 Books Books
    2 CDs CDs
    3 DVDs DVDs
    I want to make an exact copy of OrderNo 3 with new OrderNo 4, so that it will be something like:
    4 DVDs DVDs
    Any ideas friends??
    Later

    Thanks Nikki, you are right. Actually it is my fault, I framed the question in a wrong way. Well, I found out the solution for that and here is the answer
    insert into [tablename] (OrderNo) select 42506 from [sametablename] where OrderNo=42405

  • How to pass a result of SQL query to shell script variable

    Hi all,
    I am trying to pass the result of a simple SQL query that only returns a single row into the shell script variable ( This particular SQL is being executed from inside the same shell script).
    I want to use this value of the variable again in the same shell scirpt by opening another SQL plus session.
    I just want to have some values before hand so that I dont have to do multiple joins in the actual SQL to process data.

    Here an example :
    SQL> select empno,ename,deptno from emp;
         EMPNO ENAME          DEPTNO
          7369 SMITH              20
          7499 ALLEN              30
          7521 WARD               30
          7566 JONES              20
          7654 MARTIN             30
          7698 BLAKE              30
          7782 CLARK              10
          7788 SCOTT              20
          7839 KING               10
          7844 TURNER             30
          7876 ADAMS              20
          7900 JAMES              30
          7902 FORD               20
          7934 MILLER             10
    14 rows selected.
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    $ cat my_shell.sh
    ### First query #####
    ENAME_DEPTNO=`sqlplus -s scott/tiger << EOF
    set pages 0
    select ename,deptno from emp where empno=$1;
    exit
    EOF`
    ENAME=`echo $ENAME_DEPTNO | awk '{print $1}'`
    DEPTNO=`echo $ENAME_DEPTNO | awk '{print $2}'`
    echo "Ename         = "$ENAME
    echo "Dept          = "$DEPTNO
    ### Second query #####
    DNAME_LOC=`sqlplus -s scott/tiger << EOF
    set pages 0
    select dname,loc from dept where deptno=$DEPTNO;
    exit
    EOF`
    DNAME=`echo $DNAME_LOC | awk '{print $1}'`
    LOC=`echo $DNAME_LOC | awk '{print $2}'`
    echo "Dept Name     = "$DNAME
    echo "Dept Location = "$LOC
    $ ./my_shell.sh 7902
    Ename         = FORD
    Dept          = 20
    Dept Name     = RESEARCH
    Dept Location = DALLAS
    $                                                                           

  • SQL QUERY updateable report with APEX_ITEM fields to update hidden columns

    Here is my SQL query:
    select
    "EMPLOYEE_ID",
    "PUBLICATION_ID",
    "TITLE",
    '<NOBR>1. ' || APEX_ITEM.TEXT(101,CODE1,2,3) || '  ' ||
    APEX_ITEM.TEXT(102,CODE1_PCT,2,3) || ' %</NOBR><BR>' ||
    '<NOBR>2. ' || APEX_ITEM.TEXT(103,CODE2,2,3) || '  ' ||
    APEX_ITEM.TEXT(104,CODE2_PCT,2,3) || ' %</NOBR><BR>' ||
    '<NOBR>3. ' || APEX_ITEM.TEXT(105,CODE3,2,3) || '  ' ||
    APEX_ITEM.TEXT(106,CODE3_PCT,2,3) || ' %</NOBR>' rfcd_codes,
    APEX_ITEM.DISPLAY_AND_SAVE(100,CODE1) hidden_rfcd1,
    mycomments
    from "#OWNER#".mytable
    I have 3 code fields with their percentages (_pct). I have concatinated them so I can format them nicely on the page.
    I have create a process 'on-submit and before computations and validations' where I was hoping to assign my table columns (eg the code and pct columns) from the APEXITEMs in my select statement.
    I can get the values from these (APEX_ITEM) fields by referencing APEX_APPLICATION.G_F10(i) etc.... so thats cool.
    But my problem is how do I reference the table columns so I can assign them.
    I am using a 'Multi Row Update' process to perform the update to the database.
    P.S. mycomments column is working fine. It gets updated nicely but its just those other APEX_ITEM fields.

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • SQL Query (updateable report) CheckBox Update Problem

    My process will update 1 or 2 rows, but fails on three or more rows. All the rows on the page can be processed, up to 2 at a time.
    The SQL Query Report can have 50 rows on a page. Only the check box and the hidden primary key column are returned by the report to the process (marked as edit).
    If I issue the update myself, I can update any number of rows with no error.
    If I change the update SQL to a select, it works for the all of the checked lines (the correct count is displayed in the process message.
    The only thing I see for the failure is a url
    http://d101dbaxeaa2llb:10700/apex/wwv_flow.accept
    Process is:
    DECLARE
    vRow BINARY_INTEGER;
    item NUMBER;
    BEGIN
    item := 0;
    FOR i IN 1 .. apex_application.g_f01.COUNT
    LOOP
    item := item + 1;
    vRow := apex_application.g_f01(i);
    update #OWNER#.B_ATT_DAYS_FUT
    set day_status_cd =
    case
    when day_status_cd = -1 and day_dt is not null then 2
    when day_status_cd = -1 and day_dt is null then 0
    when day_status_cd = 6 then 7
    else 2
    end
    where days_pk = to_number(apex_application.g_f02 (vRow));
    END LOOP;
    :P35_CHECKED_CT := item;
    END;
    This is in APEX Application Express 3.1.0.00.32 on Oracle 11.1.0.6.0.

    Query is at the end. The Report Regions is a SQL Query (Updatable Report).
    I don't thinks this is my code problem.
    The system I'm using is dieing. It has had two disk crashes, which spinrite brought back. I've restored from a partition image and a full cold backup. Then I've had a number of blue screen failures. One of the DBAs working for me rebuilt the 11g instance on a VM and restored the cold backup. Everything runs fine there. I even applied the latest code export from the failing systems development workspace to the VM based system. Still runs fine.
    There are a number of abends in the alert log ORA-07445 and ORA-21779 for which our on-site ASC Engineer has opened a TAR/SR. I suspect that some part of one of the FLOW tablespaces was damaged, a part which deals with runtime APEX. Build time is running fine. Application just does not, either as a runtime or in the development system.
    We are moving to a new AIX server, just finishing the setup and then I can send over the exports. That should put this to bed.
    SELECT
    DAYS_PK
    , NAME_TX
    , DAY_CD
    , DAY_DESC_TX
    , DAY_STATUS_CD
    , DAY_STATUS_DESC_TX
    , DAY_DT
    , REASON_TX
    , TEN_DAY_PERIOD_FL
    , EARNED_ON_DT
    , EXPIRES_ON_DT
    , PLANNED_ON_DT
    , GUARANTEED_DAY_CD
    , GUARANTOR
    FROM
    (SELECT
    DAYS."DAYS_PK"
    , A_ATT_USERS.NAME_TX
    , DAYS."DAY_CD"
    , DAY_CD."DAY_DESC_TX"
    , DAYS."DAY_STATUS_CD"
    , DAY_ST_CD."DAY_STATUS_DESC_TX"
    , DAYS."DAY_DT"
    , DAYS."REASON_TX"
    , DAYS."TEN_DAY_PERIOD_FL"
    , DAYS."EARNED_ON_DT"
    , DAYS."EXPIRES_ON_DT"
    , DAYS."PLANNED_ON_DT"
    , CASE DAYS."GUARANTEED_DAY_CD"
    WHEN 'E' THEN 'GUARANTEED'
    WHEN 'R' THEN 'GUARANTOR'
    ELSE NULL
    END GUARANTEED_DAY_CD
    , G_ATT_USERS.NAME_TX "GUARANTOR"
    FROM
    "B_ATT_DAYS_FUT" DAYS
    LEFT OUTER JOIN "A_ATT_USERS" G_ATT_USERS
    ON
    "DAYS"."GUARANTEED_COMIT_ID" = "G_ATT_USERS"."COMIT_ID"
    LEFT OUTER JOIN "A_ATT_USERS"
    ON
    "DAYS"."COMIT_ID" = "A_ATT_USERS"."COMIT_ID"
    , "T_ATT_DAY_CD" DAY_CD
    , "T_ATT_DAY_STATUS_CD" DAY_ST_CD
    WHERE
    DAYS."DAY_CD" = DAY_CD."DAY_CD"
    AND DAYS."DAY_STATUS_CD" = DAY_ST_CD."DAY_STATUS_CD"
    AND DAYS.COMIT_ID IN
    SELECT DISTINCT
    ( R.COMIT_ID )
    FROM
    ATT_ATTENDANCE.A_ATT_STAFF_ROLE R
    WHERE
    R.COMIT_ID <> :P1_COMIT_ID_HIERARCHY START
    WITH R.COMIT_ID = :P1_COMIT_ID_HIERARCHY
    CONNECT BY PRIOR R.COMIT_ID = R.MGR_COMIT_ID
    AND DAYS.DAY_STATUS_CD IN ( 1, -1, 6 )
    AND DAYS.COMIT_ID <> :P1_COMIT_ID
    ORDER BY
    A_ATT_USERS.NAME_TX
    , DAYS.DAY_DT
    , DAYS.DAY_CD DESC
    , DAYS.EARNED_ON_DT)
    WHERE
    INSTR(UPPER(NAME_TX),UPPER(COALESCE(:P35_S_NAME,NAME_TX))) > 0

  • XML SQL - query the table with XML in column [urgent]

    I have table which have to be query-ied with
    oracle.xml.sql.query.OracleXMLQuery class to produce XML
    document for web.
    Problem is that in one column is already XML data (well formed
    HTML) like this:
    <font face="Arial">click</font>
    and when I call OracleXMLQuery.getXMLString() it encode all's '<'
    as ';lt' and so on.
    Can I turn off that kind of encoding some way or is it better
    sollution for this?
    thanks in advance
    Bojan
    null

    You can use an XSLT Stylesheet to achieve what you are wanting to do.
    Say the name of the column containing
    the markup is named "DOC", then
    transforming the output of OracleXMLQuery
    by the following stylesheet using
    the oracle.xml.parser.v2.XSLProcessor...
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl utput method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="DOC">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:template>
    </xsl:stylesheet>
    Will give the results you are looking for.
    You can use the XSQL Servlet to make this combination even easier if that is applicable to your situation.

  • How to set a sql query time out with jdbc:oracle:thin

    should i change the JDBC driver with jdbc:oralce:XA:thin or other driver with XA?

    SQL query timeout may be set with setQueryTimeout.
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#setQueryTimeout(int)
    A query timeout bug is fixed in Oracle JDBC Drivers release
    10.1.0.2.0 (10g)
    FIXED BUG-2249191
    In the Server Internal Driver, setting the query timeout does not
    +(and likely will never) work. The query execution will not be+
    canceled when the timeout expires, even if the query runs forever.
    Further, after the query returns, the execution of your code
    may pause for the length of the timeout.
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_readme101020.html

  • Handling sql query in jsp while extracing records from 3 tables

    hi to one and all,
    i want to implement the sql query given below in jsp in execute query statement . the query is working in sql but not when implemented using jsp. please help me in resolving this.
    Query
    SELECT e.Department , e.ETitle , s.basic , s.da, c.address1 , c.address2 from Employee e , Salary s , Contactdetails1 c where e.id = s.id and e.id =c.id

    It would help if you gave us a little more info to go on like;
    a) post your code
    b) post the error message the compiler is giving you

  • Does SQL Query run faster with/without Conditions....

    Hi All, forgive my novice question.
    Was just wondering" In general if we run a SQL query on a single table; does my query run faster if there are multiple where conditions? or without. What happens if the conditions increase? My table is a big one with 5 million rows and some bitmap indexes defined on it.
    Thanks,
    Kon

    I think it's difficult to give general rule because there are too much dependencies on the fact that the columns are indexed or not, on the way tables and indexes statistics are computed or not, on the possible session or instance parameters that the optimizer may use, on the Oracle version, etc.
    Message was edited by:
    Pierre Forstmann

  • Sql Query(Updateable Report) with pagination

    Hi,
    We're on APEX 3.2 I have a question on Sql Query(Updateable Report) and pagination. I have an updateable report which we have set to show 20 rows. When the userwhi has more than 20 rows enters the data and clicks next the data disappears. I have been reviewing other posts, but haven't come to a clear conclusion on how to prevent this from happening. I have been trying to use javascript to show a save popup when clicking 'Next' Any help is appreciated.
    Thanks,
    Joe

    any ideas?

  • Sql query runing slow with lower cost

    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ?
    Any idea why second query is runing fast after commenting few columns in select and group by clause.
    Query 1
    SELECT PH.CTRL_NBR, PD.SEQ_NBR,PH.CNTRY,PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNIT_VOL,
    IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    IM.PACK_QTY,
    IM.UNITVOL,
    IM.UNITWT,
    IM.PACK_QTY
    Query 2 .
    SELECT PH.CTRL_NBR,
    PD.SEQ_NBR,
    PH.CNTRY,
    PH.SHIP_DATE,
    PHI.WAVE_NBR,
    PD.ID,
    PD.QTY,
    -- IM.PACK_QTY,
    -- IM.UNIT_VOL,
    -- IM.PACK_QTY,
    MAX(CD.PACK_QTY) AS CASE_QTY,
    -- IM.UNIT_WT
    FROM HDR PH,
    HDR_INTRNL PHI,
    DTL PD,
    HDR CH,
    CASEDTL CD,
    IMASTER IM
    WHERE PH.CTRL_NBR = PHI.CTRL_NBR
    AND PD.CTRL_NBR = PH.CTRL_NBR
    AND PD.QTY > 0
    AND SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
    AND CD.CASENBR = CH.CASENBR
    AND CH.STAT_CODE BETWEEN '10' AND '90'
    AND IM.ID = PD.ID
    AND PHI.WAVE_NBR='EL57893'
    GROUP BY PH.CTRL_NBR, PD.SEQ_NBR, PH.CNTRY, PH.SHIP_DATE, PHI.WAVE_NBR, PD.ID, PD.QTY,
    --IM.PACK_QTY,
    --IM.UNITVOL,
    --IM.UNITWT,
    --IM.PACK_QTY
    Edited by: oradba11 on Sep 6, 2012 2:11 PM
    Edited by: oradba11 on Sep 6, 2012 2:12 PM

    oradba11 wrote:
    Hello
    I am working on Oracle 11g and AIX.I have one sql query which is ruing slow as reported by user.
    When i am commenting few line of code it is runing fast.
    I noticed that the execution plan cost of first query is less and second ...as cost of sccond qurey is more.But users are say it is runing fast.
    How it can possiable ? <snip>
    This doesn't address your question, but let me suggest that for your own sanity you start brining some formatting to your sql. And for the sanity of those on this forum of whom you expect assistance, you preserve that formatting through the use of the code tags (see the FAQ for details).
    I've done the first one for you, as an example of what I mean
    SELECT
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,     PHI.WAVE_NBR
    ,     PD.ID
    ,     PD.QTY
    ,     IM.PACK_QTY
    ,     IM.UNIT_VOL
    ,     IM.PACK_QTY
    ,     MAX(CD.PACK_QTY) AS CASE_QTY
    ,     IM.UNIT_WT
    FROM
         HDR PH
    ,     HDR_INTRNL PHI
    ,     DTL PD
    ,     HDR CH
    ,     CASEDTL CD
    ,     IMASTER IM
    WHERE
         PH.CTRL_NBR = PHI.CTRL_NBR
       AND  PD.CTRL_NBR = PH.CTRL_NBR
       AND  PD.QTY > 0
       AND  SUBSTR(CD.ID, 1, 9) = SUBSTR(PD.ID, 1, 9)
       AND  CD.CASENBR = CH.CASENBR
       AND  CH.STAT_CODE BETWEEN '10' AND '90'
       AND  IM.ID = PD.ID
       AND  PHI.WAVE_NBR='EL57893'
    GROUP BY
         PH.CTRL_NBR
    ,     PD.SEQ_NBR
    ,     PH.CNTRY
    ,     PH.SHIP_DATE
    ,      PHI.WAVE_NBR
    ,      PD.ID
    ,      PD.QTY
    ,      IM.PACK_QTY
    ,     IM.UNITVOL
    ,     IM.UNITWT
    ,     IM.PACK_QTY

  • Calling jsp with parameter - problem

    Hi,
    i am calling another jsp in onclick event. But the parameter does seems to be passed.
    when i write like below seperately,
    <script type="text/javascript">
                   window.location.href='emp2.jsp?empcode=<%=request.getParameter("empcode")%>&descr=<%=request.getParameter("empname")%>'
    </script>
    I can see emp2.jsp with correct parameters.
    But when i use the above logic in onclick event, the empcode is missing.
    See the onclick event.
    <INPUT TYPE="submit" value="Modify" ONCLICK="window.location.href='emp2.jsp?empcode=<%=request.getParameter("empcode")%>&descr=<%=request.getParameter("empname")%>'">
    Pls help where am i doing wrong.

    Looks like it should work, provided empcode and empname are both in the request parameters when you load this page.
    If you enter in the empcode and empname on the same screen as the submit button, this won't work.
    I would suggest you just use the default action of a submit button, and submit a form.
    This should be exactly equivalent to what you have written in your onclick event.
    <form action="emp2.jsp>
    <input type="hidden" name="empcode value="<%= request.getParameter("empcode") %>"
    <input type="hidden" name="descr value="<%= request.getParameter("empname") %>"
    <input type="submit" value="Modify">
    </form>

  • SQL query performance difference with Index Hint in Oracle 10g

    Hi,
    I was having a problem in SQL select query which was taking around 20 seconds to get the results. So, by hit and trail method I added Index Oracle Hint into the same query with the list of indexes of the tables and the results are retrieved with in 10 milli seconds. I am not sure to get How this is working with Indexes Hint.
    The query with out Index Hint:
    select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3  where FdnTab.id=52787 and paramTab1.id= FdnTab.id  and paramTab3.id = FdnTab.id  and paramTab3.attr_value = FdnTab2.fdn  and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2  where TemplateTab2.id=FdnTab.id  and ParamTab2.id=TemplateTab2.template_id  and ParamTab2.id=FdnTab2.id  and ParamTab2.attr_name=paramTab1.attr_name)  ==> EXECUTION TIME: 20 secs
    The same query with Index Hint:
    select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name) ==> EXECUTION TIME: 10 milli secs
    Can any one suggest what could be the real problem?
    Regards,
    Purushotham

    Sorry,
    The right query and the explain plan:
    select /*+rule*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3  where FdnTab.id=52787 and paramTab1.id= FdnTab.id  and paramTab3.id = FdnTab.id  and paramTab3.attr_value = FdnTab2.fdn  and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2  where TemplateTab2.id=FdnTab.id  and ParamTab2.id=TemplateTab2.template_id  and ParamTab2.id=FdnTab2.id  and ParamTab2.attr_name=paramTab1.attr_name) 
    SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 651267974
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    |* 1 | FILTER | |
    | 2 | NESTED LOOPS | |
    | 3 | NESTED LOOPS | |
    | 4 | NESTED LOOPS | |
    |* 5 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
    PLAN_TABLE_OUTPUT
    |* 6 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE |
    |* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
    | 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE |
    |* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE |
    | 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
    |* 11 | INDEX UNIQUE SCAN | SYS_C005695 |
    | 12 | NESTED LOOPS | |
    |* 13 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE |
    |* 14 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    1 - filter( EXISTS (SELECT 0 FROM "TEMPLATERELATIONTABLE"
    "TEMPLATETAB2","PARAMETERTABLE" "PARAMTAB2" WHERE
    "PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"=:B2 AND
    "PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID" AND
    "TEMPLATETAB2"."ID"=:B3))
    5 - access("FDNTAB"."ID"=52787)
    6 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
    7 - access("PARAMTAB1"."ID"="FDNTAB"."ID" AND
    PLAN_TABLE_OUTPUT
    "PARAMTAB1"."ATTR_NAME"='harqUsersMax')
    9 - access("PARAMTAB3"."ID"="FDNTAB"."ID")
    11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
    13 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
    14 - access("TEMPLATETAB2"."ID"=:B1 AND
    "PARAMTAB2"."ID"="TEMPLATETAB2"."TEMPLATE_ID")
    Note
    - rule based optimizer used (consider using cbo)
    43 rows selected.
    WITH INDEX HINT:
    select /*+INDEX(fdnmappingtable[PRIMARY_KY_FDNMAPPINGTABLE],parametertable[PRIMARY_KY_PARAMETERTABLE])*/ FdnTab2.fdn, paramTab3.attr_name from fdnmappingtable FdnTab, fdnmappingtable FdnTab2, parametertable paramTab1 ,parametertable paramTab3 where FdnTab.id=52787 and paramTab1.id= FdnTab.id and paramTab3.id = FdnTab.id and paramTab3.attr_value = FdnTab2.fdn and paramTab1.attr_name='harqUsersMax' and paramTab1.attr_value <> 'DEFAULT' and exists ( select ParamTab2.attr_name from parametertable ParamTab2, templaterelationtable TemplateTab2 where TemplateTab2.id=FdnTab.id and ParamTab2.id=TemplateTab2.template_id and ParamTab2.id=FdnTab2.id and ParamTab2.attr_name=paramTab1.attr_name);
    SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    Plan hash value: 2924316070
    | Id | Operation | Name | Rows | B
    ytes | Cost (%CPU)| Time |
    PLAN_TABLE_OUTPUT
    | 0 | SELECT STATEMENT | | 1 |
    916 | 6 (0)| 00:00:01 |
    |* 1 | FILTER | | |
    | | |
    | 2 | NESTED LOOPS | | 1 |
    916 | 4 (0)| 00:00:01 |
    | 3 | NESTED LOOPS | | 1 |
    401 | 3 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    | 4 | NESTED LOOPS | | 1 |
    207 | 2 (0)| 00:00:01 |
    |* 5 | TABLE ACCESS BY INDEX ROWID| PARAMETERTABLE | 1 |
    194 | 1 (0)| 00:00:01 |
    |* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    | 1 (0)| 00:00:01 |
    |* 7 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE | 1 |
    PLAN_TABLE_OUTPUT
    13 | 1 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID | PARAMETERTABLE | 1 |
    194 | 1 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    | 1 (0)| 00:00:01 |
    | 10 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE | 1 |
    515 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 11 | INDEX UNIQUE SCAN | SYS_C005695 | 1 |
    | 1 (0)| 00:00:01 |
    | 12 | NESTED LOOPS | | 1 |
    91 | 2 (0)| 00:00:01 |
    |* 13 | INDEX UNIQUE SCAN | PRIMARY_KEY_TRTABLE | 1 |
    26 | 1 (0)| 00:00:01 |
    |* 14 | INDEX UNIQUE SCAN | PRIMARY_KY_PARAMETERTABLE | 1 |
    65 | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
    1 - filter( EXISTS (SELECT /*+ */ 0 FROM "TEMPLATERELATIONTABLE" "TEMPLATETAB
    2","PARAMETERTABLE"
    PLAN_TABLE_OUTPUT
    "PARAMTAB2" WHERE "PARAMTAB2"."ATTR_NAME"=:B1 AND "PARAMTAB2"."ID"
    =:B2 AND
    "TEMPLATETAB2"."TEMPLATE_ID"=:B3 AND "TEMPLATETAB2"."ID"=:B4))
    5 - filter("PARAMTAB1"."ATTR_VALUE"<>'DEFAULT')
    6 - access("PARAMTAB1"."ID"=52787 AND "PARAMTAB1"."ATTR_NAME"='harqUsersMax')
    7 - access("FDNTAB"."ID"=52787)
    9 - access("PARAMTAB3"."ID"=52787)
    11 - access("PARAMTAB3"."ATTR_VALUE"="FDNTAB2"."FDN")
    13 - access("TEMPLATETAB2"."ID"=:B1 AND "TEMPLATETAB2"."TEMPLATE_ID"=:B2)
    14 - access("PARAMTAB2"."ID"=:B1 AND "PARAMTAB2"."ATTR_NAME"=:B2)
    PLAN_TABLE_OUTPUT
    Note
    - dynamic sampling used for this statement
    39 rows selected.

Maybe you are looking for