脚本在批处理文件中创建User.sql

时间:2015-03-12 12:51:54

标签: windows oracle batch-file cmd

我想创建一个批处理脚本,用于打开CMD并使用命令行参数连接到Oracle Server(带有SQLPlus),用于用户,密码和SID。

连接后,我想运行一个脚本。在这种情况下@CreateUser.sql

CREATE USER TEST IDENTIFIED BY TEST
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON USERS;

但它没有用。

@echo off
@echo off
setlocal
start cmd.exe /k "net use"
if "%~1"=="" goto :error empty 1
if "%~2"=="" goto :error empty 2
if "%~3"=="" goto :error empty 3
set "username=%~1"
if not exist "%username%\" goto :error not exist 1
set "password=%~2"
if not exist "%password%\" goto :error not exist 2
set "SID=%~3"
if not exist "%SID%\" goto :error not exist 3
sqlplus "%username%"/"%password%"@"%SID%" @CreateUser.sql
goto :eof
:error
echo wrong parameters %*
goto :eof

1 个答案:

答案 0 :(得分:0)

@echo off
@echo off
setlocal
set /P ORCL=Enter server or service_name:
set /P UN=Enter DB User:
set /P PWD=Enter password for DB user:
sqlplus "%UN%/%PWD%@%ORCL%" @CreateUser.sql

我解决了这个问题。现在我的用户名有问题。我想从命令行参数传递CreateUser.sql中的用户名。

CREATE USER $ Username IDENTIFIED BY $ UserPassword DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE temp QUOTA无限用户;

我该怎么做?

@echo off
@echo off
setlocal
set /P ORCL=Enter server or service_name:
set /P UN=Enter DB User:
set /P PWD=Enter password for DB user:
set /P User=Enter name for user:
set /P Password=Enter password for user:
sqlplus "%UN%/%PWD%@%ORCL%" @CreateUser.sql "%User%" "%Password%"

谢谢。

寻找你感兴趣的贴纸↓↓↓
豫ICP备18024241号-1