| Author |
Message |
Jerome Vitalis *nix forums addict
Joined: 03 Jun 2005
Posts: 58
|
Posted: Fri Jul 21, 2006 12:12 pm Post subject:
Re: SQLPLUS Oracle 8i query
|
|
|
Cris Carampa wrote:
| Quote: | select * from tablename
where
country = 'abc' and
(
(region='pqr' and city='xyz')
or
(region!='pqr')
)
|
That query can be simplified as follows:
select * from tablename where country='abc' and (city='xyz' or
region<>'pqr'); |
|
| Back to top |
|
 |
Cris Carampa *nix forums Guru Wannabe
Joined: 06 May 2005
Posts: 122
|
Posted: Thu Jul 20, 2006 8:35 am Post subject:
Re: SQLPLUS Oracle 8i query
|
|
|
vernalGreens@gmail.com wrote:
| Quote: | If a user selected pqr from a dropdown on the webpage, only then I want
the city statement to run.
How can I achieve this in SQLPLUS (I think the syntax in the above
query is incorrect). I'm using oracle 8i. Can I use conditional if in
SQLPLUS?
|
There's still no need for procedural statements here:
select * from tablename
where country='abc'
and
(
('&&1'='pqr' and city='xyz')
or
('&&1'!='pqr')
) ;
--
Cris Carampa (spamto:cris119@operamail.com)
when they kick at your front door | how you gonna come ?
with your hands on your head | or on the trigger of your gun ? |
|
| Back to top |
|
 |
vernalGreens@gmail.com *nix forums beginner
Joined: 20 Jul 2006
Posts: 2
|
Posted: Thu Jul 20, 2006 7:22 am Post subject:
Re: SQLPLUS Oracle 8i query
|
|
|
select * from tablename
where
country = 'abc'
if @userEnteredParameter = 'pqr' then
and city = 'xyz'
end if
If a user selected pqr from a dropdown on the webpage, only then I want
the city statement to run.
How can I achieve this in SQLPLUS (I think the syntax in the above
query is incorrect). I'm using oracle 8i. Can I use conditional if in
SQLPLUS?
Cris Carampa wrote:
| Quote: | vernalGreens@gmail.com wrote:
I want to modify the query so that "and city = 'xyz'" run only when
region = pqr.
You can do that with plain SQL, there's no need for procedural
constructs here.
It's not clear what you want to do with rows with region!='pqr'. I
assumed you wish to select all of them. Then:
select * from tablename
where
country = 'abc' and
(
(region='pqr' and city='xyz')
or
(region!='pqr')
)
Kind regards,
--
Cris Carampa (spamto:cris119@operamail.com)
when they kick at your front door | how you gonna come ?
with your hands on your head | or on the trigger of your gun ? |
|
|
| Back to top |
|
 |
Cris Carampa *nix forums Guru Wannabe
Joined: 06 May 2005
Posts: 122
|
Posted: Thu Jul 20, 2006 7:15 am Post subject:
Re: SQLPLUS Oracle 8i query
|
|
|
vernalGreens@gmail.com wrote:
| Quote: | I want to modify the query so that "and city = 'xyz'" run only when
region = pqr.
|
You can do that with plain SQL, there's no need for procedural
constructs here.
It's not clear what you want to do with rows with region!='pqr'. I
assumed you wish to select all of them. Then:
select * from tablename
where
country = 'abc' and
(
(region='pqr' and city='xyz')
or
(region!='pqr')
)
Kind regards,
--
Cris Carampa (spamto:cris119@operamail.com)
when they kick at your front door | how you gonna come ?
with your hands on your head | or on the trigger of your gun ? |
|
| Back to top |
|
 |
vernalGreens@gmail.com *nix forums beginner
Joined: 20 Jul 2006
Posts: 2
|
Posted: Thu Jul 20, 2006 7:00 am Post subject:
SQLPLUS Oracle 8i query
|
|
|
select * from tablename
where
country = 'abc'
and city = 'xyz'
I want to modify the query so that "and city = 'xyz'" run only when
region = pqr.
select * from tablename
where
country = 'abc'
if region = 'pqr' then
and city = 'xyz'
end if
What's the exact syntax for doing this in SQLPLUS. I'm using oracle 8i. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|