Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Oracle APEX: using Items in a query (:P1_ITEM)

Posted on 2012-08-13
6
Medium Priority
?
538 Views
Last Modified: 2012-08-28
I have a query that has a where clause as follows

 
WHERE THD_TRANMO = 7
  AND THD_TRANDA = 30
  AND THD_TRANYR = 12

Open in new window


I have created text box items in apex with the names P1_MONTH, P1_DATE, P1_YEAR

When i use the same query with the following

Where THD_TRANMO = :P1_YEAR
  AND THD_TRANDA = :P1_DAY
  AND THD_TRANYR = :P1_YEAR

Open in new window


The query takes very long to execute,

when not using items, it takes 1 -2 seconds to execute, when using the items it takes 45 seconds to 1 minute to execute.

Any help is greatly appreciated.
0
Comment
Question by:futureDBA
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:johnsone
ID: 38288969
This has to do with bind variables.

When your query has no bind variables and the values are explicity given in the query, then the optimizer can make a choice based on those values.

When your query has bind variables, the optimizer has no idea what the values are when parsing the query and cannot use the value to determine the best index.

If you do an explain plan on the 2 queries you should see that the access paths are different.

An index or first_rows hint to get the query to go to the index you want is probably what you will need to get the performance of the original.
0
 

Author Comment

by:futureDBA
ID: 38289589
can you please elaborate a bit further, maybe with some example if you have the time? thanks
0
 
LVL 21

Expert Comment

by:flow01
ID: 38289726
and change
Where THD_TRANMO = :P1_YEAR
to
Where THD_TRANMO = :P1_MONTH

search your oracle documentation and the net for "explain plan"
do an explain plan for both queries and provide the results
what indexes are defined on the table ? did you "gather statistics" ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:johnsone
ID: 38289742
In your query:

WHERE THD_TRANMO = 7

and

WHERE THD_TRANMO = :blah

Are 2 completely different queries to the optimizer.

In the first the optimizer knows the value it is looking for and can make assumptions about how many records match to that value.  In the second, the optimizer cannot make those same assumptions so it goes with its own calculations which can drive you to a different query plan.
0
 

Author Comment

by:futureDBA
ID: 38291996
how can i go about coming up with a solution, i thought that having a "default value" that corresponded to an actual date would have solved that problem.  but i have dates i know are valid for query, and that when i query against without using the item, they execute in 1 - 2 seconds
0
 
LVL 35

Accepted Solution

by:
johnsone earned 2000 total points
ID: 38292340
You need to generate a query plan for the queries that are different and post them.  We can help guide you through adding a hint if necessary.  The first one that I would try is FIRST_ROWS.  You can try adding that hint to your query and seeing if that helps.

You would add this:

/*+ FIRST_ROWS */

after the word SELECT in your query.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question