Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

column alias from a table value

SuriJul 9 2020 — edited Jul 9 2020

Hello Gurus,

Would it possible to use column alias from a table value.

For example I have a table like below.

order_items

Order_Codecolumn1column2
APPL10050
ORNG500200

order_codes

order_codecol1_valcol2_val
APPLno of cartons recievedno of cartons shipped
ORNGno of bags recievedno of bags shipped

I would like to display output like below

when I query order_items table

for  order_code - APPL

order_code     no of cartons recieved     no of cartons shipped

  APPL                  100                                  50

For order_code - ORNG

order_code     no of bags recieved     no of bags shipped

  ORNG                  500                                  200

Please find create table and insert statement scripts below

create table order_items ( order_code varchar2(100), column1 varchar2(1000), column2 varchar2(1000));

create table order_codes ( order_code varchar2(100), col1_val varchar2(1000), col2_val varchar2(1000));

insert into order_items values ( 'APPL', '100', '50');

insert into order_items values ( 'ORNG', '500', '200');

insert into order_codes values ( 'APPL', 'no of cartons recieved', 'no of cartons shipped');

insert into order_codes values ( 'ORNG', 'no of bags recieved', 'no of bags shipped');

Comments
Post Details
Added on Jul 9 2020
5 comments
1,420 views