Issues: While executing this query it throws following error ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at line 5 01422. 00000 - "exact fetch returns more than requested number of row
Other Issue is I am trying to get all primary key columns at one place but it is creating a separate sql line for the other column in the same primary key column.
DECLARE
v_create VARCHAR2(10000);
v_alter varchar2(10000);
v_index varchar2(10000);
BEGIN
SELECT 'create table owner_new.'
||table_name
||' as select * from '
||owner
||'.'
||table_name
||';',
'alter table owner_new.'
||table_name
||' add (Time timestamp not null default systimestamp, Action varchar2(10) not null default ''I'');',
'create index '
||cc.owner
||'.'
||cc.constraint_name
||' on '
||cc.owner
||'.'
||cc.table_name
||'('
||cc.column_name
||' ASC '
||')'
||';'
INTO v_create,
v_alter,
v_index
FROM all_tables,
all_cons_columns cc,
all_constraints pk
WHERE cc.owner = pk.owner
AND cc.constraint_name = pk.constraint_name
AND pk.constraint_type = 'P'
AND cc.owner = owner
AND owner IN ('Old_owner',
)
EXECUTE immediate
v_create;
EXECUTE immediate
v_alter;
EXECUTE immediate
v_index;
END;