Home » SQL & PL/SQL » SQL & PL/SQL » Please help me to build the query. (oracle 10g)
Please help me to build the query. [message #580809] Thu, 28 March 2013 06:09 Go to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
I have a country table it is having 50000 records.
my requirement is
If I pass the country name query has to fetch details corresponding to that country.
Example if I pass the country name as INDIA query has to fetch all the records corresponding to INDIA.
If I pass country name as ALL query has to fetch the details for all the countries.i.e 50000 records.
The country name is passing from front end.

The country name is passing from COGNOS

1) particular country name (or)
2) ALL

If country name is passed as INDIA query has to fetch the records for INDIA.
If country name is passed as ALL query has to fetch the records for all the available countries of the country_names table.
Country name "ALL" is not existed in country_names table.

For example if country name is passed as "ALL" from front end query has to fetch records for all the countries

INDIA
USA
POLAND
CHINA
HONGKONG
.
..
...
..
etc.

Please help me.
Thanks.
Re: Please help me to build the query. [message #580810 is a reply to message #580809] Thu, 28 March 2013 06:15 Go to previous messageGo to next message
cookiemonster
Messages: 10961
Registered: September 2008
Location: Rainy Manchester
Senior Member
Have you not considered the obvious:
WHERE country_name = p_country_name OR p_country_name = 'ALL'
Re: Please help me to build the query. [message #580812 is a reply to message #580810] Thu, 28 March 2013 06:23 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
In a single SQL query.
Not in a procedure.
Re: Please help me to build the query. [message #580815 is a reply to message #580812] Thu, 28 March 2013 06:30 Go to previous messageGo to next message
cookiemonster
Messages: 10961
Registered: September 2008
Location: Rainy Manchester
Senior Member
So how does the country name specified by the user end up in the query if not by a parameter/variable?
Re: Please help me to build the query. [message #580816 is a reply to message #580815] Thu, 28 March 2013 06:42 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
The country name is passing from COGNOS prompt page.
Re: Please help me to build the query. [message #580817 is a reply to message #580816] Thu, 28 March 2013 06:45 Go to previous messageGo to next message
cookiemonster
Messages: 10961
Registered: September 2008
Location: Rainy Manchester
Senior Member
That doesn't answer my question at all.
Re: Please help me to build the query. [message #580821 is a reply to message #580809] Thu, 28 March 2013 06:56 Go to previous messageGo to next message
Michel Cadot
Messages: 59184
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Before, Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

Regards
Michel
Re: Please help me to build the query. [message #580884 is a reply to message #580809] Fri, 29 March 2013 05:15 Go to previous messageGo to next message
ora_000
Messages: 1
Registered: March 2013
Location: Indian
Junior Member
Hi,
SELECT column_name
FROM table_name
WHERE column_name = DECODE('your_input','ALL',column_name,'your_input');


SELECT country_name
FROM table_name
WHERE country_name = DECODE('particular_country_name','ALL', country_name,'particular_country_name');

Thank You...

[Updated on: Fri, 29 March 2013 05:16]

Report message to a moderator

Re: Please help me to build the query. [message #581261 is a reply to message #580884] Wed, 03 April 2013 14:11 Go to previous message
Bill B
Messages: 1100
Registered: December 2004
Senior Member
The correct way is the method given by cookiemonster.

select column_name
from table_name
where ('&input' = 'ALL'
or column_name = '&input');

[Updated on: Wed, 03 April 2013 14:12]

Report message to a moderator

Previous Topic: multiple outer join
Next Topic: decode function
Goto Forum:
  


Current Time: Tue Sep 23 05:57:51 CDT 2014

Total time taken to generate the page: 0.12967 seconds