wants to check whether the table is present or not.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
awais290
Posts: 1
Joined: 09 Dec 2013 14:36

wants to check whether the table is present or not.

#1 Post by awais290 » 09 Dec 2013 14:59

Hi,



sqlplus "abc/abc@db1" @ test.sql

test.sql
--------

select count(*) from table1;

if the table is present in the DB then i want to continue test.sql script. other wise exit. please suggest.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: wants to check whether the table is present or not.

#2 Post by Ed Dyreen » 09 Dec 2013 16:37

Code: Select all

mySQL.EXE test.sql &&goto :continiue ||goto :error

:error
echo.%errorLevel%
exit

:continiue
do something
As far as I know you can't continue an SQL based upon an error. Create physically separate queries and put the logic in between.

einstein1969
Expert
Posts: 976
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: wants to check whether the table is present or not.

#3 Post by einstein1969 » 09 Dec 2013 17:10

awais290 wrote:Hi,



sqlplus "abc/abc@db1" @ test.sql

test.sql
--------

select count(*) from table1;

if the table is present in the DB then i want to continue test.sql script. other wise exit. please suggest.


try something like this.

you may create a script that return 0/1

test_exists.sql:
select count(*) from user_tables where table_name="table1";


and catch output in a for /F %%f in ('sqlplus "abc/abc@db1" @ test_exist.sql') do if "%%f"=="1" sqlplus "abc/abc@db1" @ test.sql

I can not check the output then surely there is something to fix.

einstein1969

Post Reply