Problem running oracle script from command line using sqlplus

前端 未结 6 557
暖寄归人
暖寄归人 2021-01-11 20:14

I\'m having a problem trying to run my sql script into oracle using sqlplus. The script just populates some dummy data:

DECLARE 
  role1Id NUMBER;
  user1Id          


        
相关标签:
6条回答
  • 2021-01-11 20:53

    The command line

    sqlplus username/password@server/dbname @Setup.sql
    

    mentioned above means that sqlplus should execute the script Setup.sql and wait further commands interactively (if script does not do exit explicitly). This is a normal behavior of sqlplus.

    sqlplus terminates in three cases:

    • Failure (for some errors you can change if it terminates or not. See WHENEVER plsql-command)
    • Explicit exit (both interactive and sript)
    • End of STDIN (EOF)

    Either from interactive mode or from script you can send ^Z character to softly terminate input flow. Interactively you just press Ctrl+Z,Enter.

    And, of course, you may redirect STDIN, and take it from file, not from keyboard. There are two similar ways to do this:

    1) sqlplus username/password@server/dbname<Setup.sql
    2) echo @Setup.sql|sqlplus username/password@server/dbname
    

    In both cases sqlplus will terminate after the script execution because of EOF in the input flow.

    0 讨论(0)
  • 2021-01-11 20:54

    You need to either put an exit at the end of the script, or run it as sqlplus username/password@server/dbname < Setup.sql (i.e. redirected input, < instead of @). You can check if that's the issue by just typing 'exit' in the hanging session.

    If it is really hanging, have you committed or rolled back the execution from Developer?

    0 讨论(0)
  • 2021-01-11 21:06

    I was seeing this problem as well with certain scripts that would execute fine in a client like TOAD, but when being executed via SQLPlus with the @script directive instead of hanging, the SQLPlus client would return a prompt with a number on it which corresponded to the number of lines in the script being executed (+1).

    For example, if we executed a script named 'doit.sql' that had 70 lines we would start SQLPlus with the appropriate command and enter:

    > @doit.sql

    Then we would see:

    71:

    Pressing enter at this point would return

    72:

    We were able to get these scripts executed by entering / at the prompt and pressing enter.

    0 讨论(0)
  • 2021-01-11 21:06

    The Simple answer

    Make sure you put both 'end;' and in final line put '/'

    It will run with ease.

    0 讨论(0)
  • 2021-01-11 21:10

    Issue is because of SQLplus was running from the oracle client home and it was crashing on running the startup upgrade command.

    Run the sqlplus from the non-client oracle home and tried the commands then it works as expected. so resolution is to run the sqlplus from the main oracle home instead of oracle client home.

    0 讨论(0)
  • 2021-01-11 21:16

    Instead of using the / at the prompt, ensure that your query in the doit.sql ends with a semicolon.

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