Skip to content

Instantly share code, notes, and snippets.

@dcdh
Created June 12, 2024 07:40
Show Gist options
  • Save dcdh/1dfe2a3f33d0af6e9c5dc402ccc2ec1e to your computer and use it in GitHub Desktop.
Save dcdh/1dfe2a3f33d0af6e9c5dc402ccc2ec1e to your computer and use it in GitHub Desktop.
echo SET PAGESIZE 0&echo SET LONG 5000&echo SET ECHO OFF&echo SET FEEDBACK OFF&echo SET HEADING OFF&echo SET LINESIZE 32767&echo SPOOL C:\path\to\export\all_tables_ddl.sql&echo @echo off&echo for /f "tokens=*" %%a in ('sqlplus -s username/password@database @ - ^<^<EOF
echo SET PAGESIZE 0
echo SET LONG 5000
echo SET ECHO OFF
echo SET FEEDBACK OFF
echo SET HEADING OFF
echo SET LINESIZE 32767
echo DECLARE
echo CURSOR tables_cur IS
echo SELECT table_name
echo FROM user_tables;
echo BEGIN
echo FOR table_rec IN tables_cur LOOP
echo DBMS_OUTPUT.PUT_LINE(DBMS_METADATA.GET_DDL('TABLE', table_rec.table_name));
echo END LOOP;
echo END;
echo /
echo EOF
echo ') do @echo %%a >> C:\path\to\export\all_tables_ddl.sql'&echo SPOOL OFF&echo EXIT | cmd
@dcdh
Copy link
Author

dcdh commented Jun 12, 2024

@echo off

sqlplus -s scott/tiger@orcl @ - <<EOF
SET PAGESIZE 0
SET LONG 5000
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 32767
SPOOL C:\export\all_tables_ddl.sql
DECLARE
CURSOR tables_cur IS
SELECT table_name
FROM user_tables;
BEGIN
FOR table_rec IN tables_cur LOOP
DBMS_OUTPUT.PUT_LINE(DBMS_METADATA.GET_DDL('TABLE', table_rec.table_name));
END LOOP;
END;
/
SPOOL OFF;
EXIT;
EOF

@dcdh
Copy link
Author

dcdh commented Jun 12, 2024

@echo off

echo SET PAGESIZE 0 > temp.sql
echo SET LONG 5000 >> temp.sql
echo SET ECHO OFF >> temp.sql
echo SET FEEDBACK OFF >> temp.sql
echo SET HEADING OFF >> temp.sql
echo SET LINESIZE 32767 >> temp.sql
echo SPOOL C:\export\all_tables_ddl.sql >> temp.sql
echo DECLARE >> temp.sql
echo CURSOR tables_cur IS >> temp.sql
echo SELECT table_name >> temp.sql
echo FROM user_tables; >> temp.sql
echo BEGIN >> temp.sql
echo FOR table_rec IN tables_cur LOOP >> temp.sql
echo DBMS_OUTPUT.PUT_LINE(DBMS_METADATA.GET_DDL('TABLE', table_rec.table_name)); >> temp.sql
echo END LOOP; >> temp.sql
echo END; >> temp.sql
echo / >> temp.sql
echo SPOOL OFF; >> temp.sql
echo EXIT; >> temp.sql

sqlplus -s scott/tiger@orcl @temp.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment