0

I want create new table in oracle with sqlplus and batch file.

sqlplus user/password @create_tables.sql

it is successfully

but that's not what I want. I want the user to input year. My batch file look like :

@echo off

set /p year=__YEAR (YYYY)?
sqlplus user/password
create table data%year%
(Nama varchar2(25),
value number);
echo Successfull
pause

script stops here

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 25 06:07:26 2013

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL>

what's wrong?

1 Answer 1

1

In your example you have launched an interactive shell (with SQL> prompt) and when you exit from that, the batch interpreter will run the create line as a new command (and fail).

If there isn't any other way to do it, you could echo the required commands to a temporary filename.sql in %temp% and then call that. Syntax here might not be 100%, but I hope it's a starting point :

@echo off
set /p year=__YEAR (YYYY)?
  rem  Set command in temp file :
echo create table data%year% (Name varchar2(25), value number); > @%temp%\temp.sql
  rem  Now run the above command :
sqlplus user/password @%temp%\temp.sql
echo Successfull
pause
Sign up to request clarification or add additional context in comments.

1 Comment

Thank U very much. i added echo exit > @%temp%\temp.sql syntax before rem Now run the above command. script work for me. thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.