rich p
unread,Jun 3, 2011, 7:18:47 AM6/3/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to oracle...@googlegroups.com, gayathri Dev
If you're talking about queries encapsulated within a PL/SQL coding framework, variables are usually kept in one place in the declaration section of a pl/sql object such as a procedure or function. Further, if you need to share a variable value between multiple processes, queries and database operations, consider putting all these common objects within the same package. A package variable is usually declared only once, and can be referenced anywhere from amongst the other objects defined as a part of that package.
Though package variables and constants cannot be directly referenced in queries from SQLPlus sessions (non PL/SQL constructs), I have been able to bypass this problem in the past by writing a function or procedure within the same package which calls and outputs the variable I want to share. In that form, my package variable can also be used across to objects in other packages.
One last comment: if you are planning on using a particular sql statement multiple times where your variable is the only thing that changes, look into the topic of bind variables. PL/SQL automatically treats statement variables as bind variables, but in SQL queries themselves that contain variables, it is optimal to use the notation for bind variables in your code as Oracle database engines queried multiple times through queries without a bind variable reference potentially suffer from noticeable inefficiencies.
As always, Google (and the Internet at large) is your friend. Now that you know a few key words and concepts, go forth and search for what additional info you may need to meet with success.
Rich Pascual