开发者

Command line script to delete Oracle records based on a column value

I am completely new to scripting techniques.

My requirement is

  1. To connect oracle through DOS script
  2. Based on a column value need to delete the particular record

eg:

emp   sal    pt_dt
a     23     22-02-11
b     34     20-01-10
c     45     23-09-85
d    开发者_如何学JAVA 56     30-3-11

Based on the 30-3-11(pt_dt column), I need to delete the record d.

OS - Windows XP DB - Oracle 10g


Simplest method is to first write your sql (e.g. deleterec.sql) script, then call it from a batch (e.g. deleterec.bat) script.

Example contents of deleterec.sql:

DELETE emp WHERE pt_dt = TO_DATE('30-03-2011','DD-MM-RRRR');

Example contents of deleterec.bat:

sqlplus.exe scott/tiger@orcl @deleterec.sql

(replace scott/tiger@orcl with your user name, password and database instance)


You can write a .bat like this:

@echo off
if %%1X==X goto noparam
echo DELETE FROM emp e WHERE e.emp = '%%1' > deleterec.sql
sqlplus.exe scott/tiger@orcl @deleterec.sql
delete deleterec.sql
goto end
:noparam
echo Usage: %%0 {employee id}
goto end
:end
echo Bye!

I admit I stole the sqlplus call from Jeffrey's answer. :-o

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜