How can I issue a single command from the command line through sql plus?

后端 未结 6 1241
半阙折子戏
半阙折子戏 2020-12-02 12:03

Using SQL Plus, you can run a script with the \"@\" operator from the command line, as in:

c:\\>sqlplus username/password@databasename @\         


        
相关标签:
6条回答
  • 2020-12-02 12:40

    I'm able to run an SQL query by piping it to SQL*Plus:

    @echo select count(*) from table; | sqlplus username/password@database
    

    Give

    @echo execute some_procedure | sqlplus username/password@databasename
    

    a try.

    0 讨论(0)
  • 2020-12-02 12:46

    Have you tried something like this?

    sqlplus username/password@database < "EXECUTE some_proc /"
    

    Seems like in UNIX you can do:

    sqlplus username/password@database <<EOF
    EXECUTE some_proc;
    EXIT;
    EOF
    

    But I'm not sure what the windows equivalent of that would be.

    0 讨论(0)
  • 2020-12-02 12:52

    For UNIX (AIX):

    export ORACLE_HOME=/oracleClient/app/oracle/product/version
    export DBUSER=fooUser
    export DBPASSWD=fooPW
    export DBNAME=fooSchema 
    
    echo "select * from someTable;" | $ORACLE_HOME/bin/sqlplus $DBUSER/$DBPASSWD@$DBNAME
    
    0 讨论(0)
  • 2020-12-02 12:54
    sqlplus user/password@sid < sqlfile.sql
    

    This will also work from the DOS command line. In this case the file sqlfile.sql contains the SQL you wish to execute.

    0 讨论(0)
  • 2020-12-02 12:54

    This is how I solved the problem:

    <target name="executeSQLScript">
        <exec executable="sqlplus" failonerror="true" errorproperty="exit.status">
            <arg value="${dbUser}/${dbPass}@<DBHOST>:<DBPORT>/<SID>"/>
            <arg value="@${basedir}/db/scripttoexecute.sql"/>
        </exec>
    </target>
    
    0 讨论(0)
  • 2020-12-02 12:55
    @find /v "@" < %0 | sqlplus -s scott/tiger@orcl & goto :eof
    
    select sysdate from dual;
    
    0 讨论(0)
提交回复
热议问题