sql >> データベース >  >> RDS >> Oracle

パスワードにsqlplusと特殊文字を含むシェルスクリプト

    構成ファイルsqlnet.oraを構成します 簡単に接続できます。

    NAMES.DIRECTORY_PATH= (TNSNAMES,ezconnect)
    

    パスワード@T!gerをユーザー「Scott」に変更します。

    [email protected]:~>
    [email protected]:~> sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.3.0 Production on Mon Jan 29 11:05:04 2018
    
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    
    SQL> alter user "Scott" identified by "@T!ger";
    
    User altered.
    

    例1 スクリプトはtest_echo.sh

    です
        #!/bin/sh
    
        username=\"Scott\"
        password=\"@T!ger\"
        ezconnect=10.89.251.205:1521/esmd
    
        echo username:  $username
        echo password:  $password
        echo ezconnect  $ezconnect
    
     echo -e 'show user \n  select 1 from dual;\nexit;' |  sqlplus  $username/[email protected]$ezconnect
    
    [email protected]:~> ./test_echo.sh
    username: "Scott"
    password: "@T!ger"
    ezconnect 10.89.251.205:1521/esmd
    
    SQL*Plus: Release 11.2.0.3.0 Production on Mon Jan 29 11:02:52 2018
    
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    
    SQL> USER is "Scott"
    SQL>
             1
    ----------
             1
    
    SQL> Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    

    例2 スクリプトtest_echo.shをサイレントモードsqlplusで実行します

    #!/bin/sh
    
    username=\"Scott\"
    password=\"@T!ger\"
    ezconnect=10.89.251.205:1521/esmd
    
    echo username:  $username
    echo password:  $password
    echo ezconnect  $ezconnect
    echo -e 'show user \n  select 1 from dual;\nexit;' |  sqlplus -s  $username/[email protected]$ezconnect
    
    [email protected]:~> [email protected]:~> ./test_echo.sh
    username: "Scott"
    password: "@T!ger"
    ezconnect 10.89.251.205:1521/esmd
    USER is "Scott"
    
             1
    ----------
             1
    

    例3 少し別の構文

    #!/bin/sh
    
    username=\"Scott\"
    password=\"@T!ger\"
    ezconnect=10.89.251.205:1521/esmd
    
    
    echo username:  $username
    echo password:  $password
    echo ezconnect: $ezconnect
    
    testoutput=$(sqlplus -s $username/[email protected]$ezconnect  << EOF
    set pagesize 0 feedback off verify off heading off echo off;
    show user
    SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual
    exit;
    EOF
    )
    
    echo $testoutput
    
    [email protected]:~> ./test_Upper_case.sh
    username: "Scott"
    password: "@T!ger"
    ezconnect: 10.89.251.205:1521/esmd
    USER is "Scott" 29-01-2018 11:55 Test passed
    


    1. SQLServer2005クエリをCSVにエクスポートする方法

    2. postgresで不明な行の値を列名に動的に転置する

    3. SQL Server と NoSQL

    4. Google Cloud SQLのCURRENT_TIMESTAMPタイムゾーンを変更しますか?