Home » SQL & PL/SQL » SQL & PL/SQL » query in CASE expression in select (Oracle 11)
icon5.gif  query in CASE expression in select [message #632800] Thu, 05 February 2015 17:20 Go to next message
pallaviprakash
Messages: 2
Registered: February 2015
Junior Member
Hi,

I have a table A with columns and Ouput is Table B

/forum/fa/12488/0/

The natural key is Street_addr and CITY. I am trying to write a Case expression populating another column ADDR_TYPE_CD in Table B based on below rules

Where STREET_ADD=STREET_ADD and CITY=CITY,

if ADDR_TYPE_cd= PROP and MAIL, then ADDR_TYPE_CD in TABLE B = PROP, MAIL, RPT.

if ADDR_TYPE_cd= PROP , then ADDR_TYPE_CD in TABLE B = PROP, RPT.

if ADDR_TYPE_cd= MAIL , then ADDR_TYPE_CD in TABLE B = MAIL, RPT.



I have tried writing through CASE statement as :

select
Case addr_type_cd



WHEN addr_type_cd='PROP' and addr_type_cd='MAIL'


THEN addr_type_cd='RPT' and addr_type_cd='PROP' and addr_type_cd='MAIL'

END

from Table A

where street_addr=street_addr

and city=city



I get missing keyword error, plus am not sure if the logic would work. Any inputs ideas will be very helpful. Hope the question is clear.





Thanks,

Pallavi
/forum/fa/12487/0/
Re: query in CASE expression in select [message #632801 is a reply to message #632800] Thu, 05 February 2015 18:11 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>if ADDR_TYPE_cd= PROP and MAIL

no single column in single row can be concurrently equal to both PROP & MAIL.

to have ADDR_TYPE_cd= PROP and MAIL, then from clause must contain TABLEA twice (FROM TABLEA A1, TABLEA A2)
Re: query in CASE expression in select [message #632817 is a reply to message #632800] Fri, 06 February 2015 00:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals.

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.

Re: query in CASE expression in select [message #632822 is a reply to message #632800] Fri, 06 February 2015 01:49 Go to previous message
John Watson
Messages: 9004
Registered: January 2010
Location: Global Village
Senior Member
Can you describe the whole question (I assume this is a colege homework question?) again? And of course include the CREATE TABLE statement and the seven INSERT statements.
There is a lot I can't understand at the moment. For example, you say "The natural key is Street_addr and CITY" but they do not give you a unique identifier. Furthermore, your table has seven rows but your output has twelve rows, which seems odd.
Previous Topic: More than one column in Connect by prior
Next Topic: extract character between points
Goto Forum:
  


Current Time: Tue Sep 01 16:16:39 CDT 2026