-------------------------------------------------------------------
Create table Test_table_a (
Trans_dt Date,
C1 Number,
C2 Number,
C3 Number,
C4 Number);
-------------------------------------------------------------------
----Inserting Some Sample Data for Testing ------------------------
-------------------------------------------------------------------
Insert Into Test_table_a Values ('23-JUL-05', 9001, 8654, 231, 6954);
Insert Into Test_table_a Values ('23-JUL-04', 432, 3823, 159, 7175);
Insert Into Test_table_a Values ('23-JUL-03', 9356, 2635, 5324, 6586);
Insert Into Test_table_a Values ('23-JUL-02', 7073, 279, 3574, 4816);
Insert Into Test_table_a Values ('23-JUL-01', 1510, 6416, 5987, 9003);
-------------------------------------------------------------------
----Creating Target table -----------------------------------------
-------------------------------------------------------------------
Create table Test_table_b (
Trans_dt Date,
c_name Varchar2(20),
c_val Number);
-------------------------------------------------------------------
----Insert Script to load data into Target ------------------------
-------------------------------------------------------------------
Insert Into Test_table_b select Trans_dt, 'c' || r c_name,
decode( r, 1, c1, 2, c2, 3, c3, 4, c4 ) c_val
from Test_table_a, (select rownum r
from all_objects where rownum <= 4);
-------------------------------------------------------------------
----Output (Select * from Test_tab_b;) ----------------------------
-------------------------------------------------------------------
23-JUL-05 c1 9005
23-JUL-04 c1 432
23-JUL-03 c1 9356
23-JUL-02 c1 7073
23-JUL-01 c1 1510
23-JUL-05 c2 8654
23-JUL-04 c2 3823
23-JUL-03 c2 2635
23-JUL-02 c2 279
23-JUL-01 c2 6416
23-JUL-05 c3 231
23-JUL-04 c3 159
23-JUL-03 c3 5324
23-JUL-02 c3 3574
23-JUL-01 c3 5987
23-JUL-05 c4 6954
23-JUL-04 c4 7175
23-JUL-03 c4 6586
23-JUL-02 c4 4816
23-JUL-01 c4 9003
-------------------------------------------------------------------
-------------------------------------------------------------------
Create table Test_table_a (
Trans_dt Date,
C1 Number,
C2 Number,
C3 Number,
C4 Number);
-------------------------------------------------------------------
----Inserting Some Sample Data for Testing ------------------------
-------------------------------------------------------------------
Insert Into Test_table_a Values ('23-JUL-05', 9001, 8654, 231, 6954);
Insert Into Test_table_a Values ('23-JUL-04', 432, 3823, 159, 7175);
Insert Into Test_table_a Values ('23-JUL-03', 9356, 2635, 5324, 6586);
Insert Into Test_table_a Values ('23-JUL-02', 7073, 279, 3574, 4816);
Insert Into Test_table_a Values ('23-JUL-01', 1510, 6416, 5987, 9003);
-------------------------------------------------------------------
----Creating Target table -----------------------------------------
-------------------------------------------------------------------
Create table Test_table_b (
Trans_dt Date,
c_name Varchar2(20),
c_val Number);
-------------------------------------------------------------------
----Insert Script to load data into Target ------------------------
-------------------------------------------------------------------
Insert Into Test_table_b select Trans_dt, 'c' || r c_name,
decode( r, 1, c1, 2, c2, 3, c3, 4, c4 ) c_val
from Test_table_a, (select rownum r
from all_objects where rownum <= 4);
-------------------------------------------------------------------
----Output (Select * from Test_tab_b;) ----------------------------
-------------------------------------------------------------------
23-JUL-05 c1 9005
23-JUL-04 c1 432
23-JUL-03 c1 9356
23-JUL-02 c1 7073
23-JUL-01 c1 1510
23-JUL-05 c2 8654
23-JUL-04 c2 3823
23-JUL-03 c2 2635
23-JUL-02 c2 279
23-JUL-01 c2 6416
23-JUL-05 c3 231
23-JUL-04 c3 159
23-JUL-03 c3 5324
23-JUL-02 c3 3574
23-JUL-01 c3 5987
23-JUL-05 c4 6954
23-JUL-04 c4 7175
23-JUL-03 c4 6586
23-JUL-02 c4 4816
23-JUL-01 c4 9003
-------------------------------------------------------------------
-------------------------------------------------------------------
No comments:
Post a Comment