如何在两个 sqlplus 实例中 运行 shell 脚本

How to run shell script in two sqlplus instances

有没有办法 运行 一个 shell 脚本,当它更新一个 sqlplus 实例时它会更新第二个实例?

代码:

echo "Please enter last name: 'input;"
    read input
    Statement2="INSERT INTO users VALUES ('"$input"');"
    output1=$($sqlplus -s User/Pass@connection <<EOF
    set head off
    select count (*) from users
    where fname = '$input';
    EXIT;
    EOF
    )

    read -p "User $input appears $output1 times. Create user? [Y/n]" answer
    if [ -z "$answer" -o "$answer" == "y" -o "$answer" == "Y" ]
    then

    $sqlplus -s User/Pass@connection << Eossql
    set autocommit on
    set head off
    $Statement2
        quit;
    Eossql

    else
        echo "Not creating user"
    fi

如果最终用户选择 (y),我如何使用单独的用户 ID 和密码更新第二个 sqlpus 实例

谢谢!

您可以将 SQL 代码保存到 运行 两个实例中的一个变量中,然后再使用它:

sql=$(cat << EOF
set autocommit on
set head off
$Statement2
    quit;
EOF
)
$sqlplus -s User/Pass@connection <<< "$sql"
$sqlplus -s User2/Pass2@connection2 <<< "$sql"