CREATE OR REPLACE PROCEDURE export_tables (p_schema IN VARCHAR2)
IS
v_sql VARCHAR2(4000);
BEGIN
FOR r_table IN (SELECT table_name FROM all_tables WHERE owner = p_schema) LOOP
spool '/home/oracle/' || r_table.table_name || '.txt';
v_sql := 'SELECT * FROM ' || p_schema || '.' || r_table.table_name;
EXECUTE IMMEDIATE v_sql;
spool off;
END LOOP;
END;
/
set linesize 1000
set pagesize 0
set colsep '|'
set trimspool on
set feedback off
set heading off
DECLARE
v_sql VARCHAR2(4000);
BEGIN
FOR r_table IN (SELECT table_name FROM all_tables WHERE owner = 'HR') LOOP -- Reemplazar 'HR' con el nombre del esquema deseado
spool '/home/oracle/' || r_table.table_name || '.txt';
v_sql := 'SELECT * FROM ' || r_table.table_name;
EXECUTE IMMEDIATE v_sql;
spool off;
END LOOP;
END;
/
set heading on
set feedback on
exit;
//////////////////////////////////////
set line 100
set heading off
set feedback off
spool /home/oracle/empleados.txt
select * from hr.employees
/
spool off
set heading on
set feedback on
exit
alter session set current_schema=HR;
set echo offset verify offset heading offset feedback offset pagesize 0spool /home/oracle/create_table.sqlselect 'CREATE TABLE ' || TABLE_NAME || '_TEST ' || 'AS SELECT * FROM ' || TABLE_NAME || ' WHERE 1=2;' from user_tables/spool off
set echo offset verify offset feedback offset pagesize 0spool /home/oracle/drop_table.sqlselect 'DROP TABLE ' || TABLE_NAME || ';'from user_tableswhere table_name like '%_TEST'/spool offset heading onset feedback onexit
No hay comentarios:
Publicar un comentario