0

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     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

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Forgot to mention this is quite risky. Any attempt to do this in batch is. In this particular case, when someone enters the employee id '; drop database; --, you'll be in trouble. If you are smart and remove the rights to drop the database, they can still write ' OR e.emp IS NOT NULL OR e.emp IS NULL....

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.