I am using 10g Release 10.2.0.1.0
I've the following table and wanted to flip table horizontally in such a way that for each key if there is a s_key and type_cd, then it checks another table if that column exist in it or not?
if the column doesnt exist, then it should create a new column in another table.
Table_A
KEY S_KEY TYPE_CD
191 100 A
191 50 A
191 70 A
191 70 C
100 10 A
100 20 C
flip it is this manner
skey_100 skey_50 skey_70 type_A type_C
skey_10 skey_20 type_A type_C
Lets only look at KEY 191.
now i want to check another table TABLE_B if ( columns skey_100 , skey_50, skey_70, type_A, type_C are present) if not then add to that table with datatype varchar2(10)
here is my effort
FOR c IN (SELECT DISTINCT S_KEY, TYPE_CD
FROM TABLE_A
WHERE KEY = 191
)
LOOP
BEGIN
SELECT distinct skey, type_cd
INTO c_column_name
FROM all_tab_columns a
WHERE owner = 'STG'
AND table_name = 'TABLE_A'
AND column_name = 'SKEY_'||c.S_KEY ;
EXCEPTION WHEN NO_DATA_FOUND THEN
EXECUTE IMMEDIATE 'ALTER TABLE TABLE_A ADD '
|| 'SKEY_'||c.S_KEY
|| ' VARCHAR(10)';
END;
END LOOP;
I dont know how to do both the colums together..
Thanks