Reputation: 51
How to create another row from a single row in oracle? Suppose, i have a table CALLTEST.
Dataset is like:
call_id PARENT_CALL OWNER ACCOUNT_ID PARENT_CL_OWNER
C3 P3 O4 HCP2 O5
C2 P2 O3 HCP1 O6
i have to create an another data from one data each, so total 4 dataset needs to be generated. conditions are:
owner field has to be updated with the parent call owner
ACCOUNT_ID needs to be updated with null value for the second record.
dataset would be like this:
call_id PARENT_CALL OWNER ACCOUNT_ID PARENT_CL_OWNER
C3 P3 O5 HCP2 O5
C3_1 P3 O5 O6
C2 P2 O6 HCP1 O6
C2_1 P2 O6 O6
so please help the exact sql query or the procedure block for achieving this scenerio.
Upvotes: 0
Views: 49
Reputation: 5294
SELECT call_id,
parent_call,
parent_cl_owner owner,
account_id,
parent_cl_owner
FROM calltest
UNION ALL
SELECT call_id || '_1',
parent_call,
parent_cl_owner,
NULL,
parent_cl_owner
FROM calltest
ORDER BY call_id
Upvotes: 1