want to run multiple SQL script file in one go with in SQLPLUS

后端 未结 8 652
陌清茗
陌清茗 2021-02-05 23:14

I have to run multiple SQL script file in one go.

Like every time i have to write command in SQLPLUS

SQL>@d:\\a.txt 
SQL>@d:\\a2.txt
SQL>@d:\\a3.txt
SQL>@d:\\         


        
相关标签:
8条回答
  • 2021-02-05 23:45

    There is no single SQL*Plus command to do that, but you can create a single script that calls all the others:

    Put the following into a batch file

    @echo off
    echo.>"%~dp0all.sql"
    for %%i in ("%~dp0"*.sql) do echo @"%%~fi" >> "%~dp0all.sql"
    

    When you run that batch file it will create a new script named all.sql in the same directory where the batch file is located. It will look for all files with the extension .sql in the same directory where the batch file is located.

    You can then run all scripts by using sqlplus user/pwd @all.sql (or extend the batch file to call sqlplus after creating the all.sql script)

    0 讨论(0)
  • 2021-02-05 23:45

    here is similar solution but you do not have to iterate and to have special formated an sql file names. You compose an one sql file and run it once.

    cat table_animal.sql > /tmp/temp.sql
    cat table_horse.sql >> /tmp/temp.sql
    cat table_fish.sql >> /tmp/temp.sql
    sqlplus USERNAME/PASSWORD@DOMAIN @/tmp/temp.sql
    
    0 讨论(0)
  • 2021-02-05 23:50

    If you're using gnu linux, you could use process substitution:

    sqlplus USERNAME/PASSWORD@DOMAIN < <(cat a.txt a2.txt a3.txt a4.txt) 
    # ... or a for loop on input files, inside the process substitution
    

    Alternatively, you can create a .pdc file and list your sql scripts:

    -- pdc file
    @a.txt;
    @a2.txt;
    @a3.txt;
    @a4.txt;
    

    and call sql plus:

    sqlplus USERNAME/PASSWORD@DOMAIN < my_scripts.pdc
    
    0 讨论(0)
  • 2021-02-05 23:52

    For Windows try copy /b *.sql +x final.sql

    sqlplus user/password @final.sql

    0 讨论(0)
  • 2021-02-05 23:54

    It might be worth the time to write a shell script that runs multiple files.

    #!/bin/ksh
    sqlplus user/password@instance <<EOF
    @a.txt
    @a1.txt
    exit
    EOF
    

    For more on the syntax, look into Here Document

    0 讨论(0)
  • 2021-02-05 23:54

    Special Thanks to Joseph Torre

    sqlplus login/password@server @filename
    

    reference link

    0 讨论(0)
提交回复
热议问题