Truncating table from a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Truncating table from a shell script
# 1  
Old 03-03-2010
Truncating table from a shell script

I am trying to truncate a table using below script. When I ran the script it runs fine but table was not truncated and the spool is empty. I am not sure what is wrong with pl/sql block.

Code:
#!/bin/ksh
# ----------------------------------------------------------------------
#
#  Created by: XXXX
#  Generated on: 03/02/2009 15:00:00
#  Job name : TRUNC-MEMBER
#  Job description: Truncate Queries
# ----------------------------------------------------------------------
#
echo "Now processing step: LOAD_"
DB_CONNECT="USER/PASS@TESTDB"
SPOOLFILE=/home/log.txt

echo "Now processing step:" $DB_CONNECT
sqlplus -s ${DB_CONNECT} <<EOF

spool ${SPOOLFILE}

whenever oserror exit sql.sqlcode
whenever sqlerror exit sql.sqlcode
SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED

declare
Begin

DBMS_OUTPUT.PUT_LINE('started;');
EXECUTE IMMEDIATE 'TRUNCATE TABLE MEMBER DROP STORAGE';

End;

spool off;
EXIT;
EOF
echo "Now processing step: LOAD_"


Last edited by pludi; 03-03-2010 at 04:12 AM.. Reason: code tags, please...
# 2  
Old 03-03-2010
Make sure you have permission to truncate the table with the user that you are logged in.
# 3  
Old 03-03-2010
Yes, I do have and I verified running

Code:
echo "Now processing step: LOAD_"
DB_CONNECT="OPS_STATS/OPS_4STATS@UTIDAL"
SPOOLFILE=/home/ca51336/log.txt

echo "Now processing step:" $DB_CONNECT
sqlplus -s ${DB_CONNECT} <<EOF

spool ${SPOOLFILE}

whenever oserror exit sql.sqlcode
whenever sqlerror exit sql.sqlcode
SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED


TRUNCATE TABLE MEMBER DROP STORAGE;


spool off;
exit;
EOF
echo "Now processing step: LOAD_"

Its not truncating only if the code is enclosed in pl/sql block

---------- Post updated at 11:59 PM ---------- Previous update was at 09:49 PM ----------

After adding / at end of pl/sql block the code worked fine.

Code:
SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED
SET FEED OFF
spool ${SPOOLFILE}

BEGIN

DBMS_OUTPUT.PUT_LINE('started;');
EXECUTE IMMEDIATE 'TRUNCATE TABLE MEMBER DROP STORAGE';
END;
/
spool off;
exit;
EOF


Last edited by pludi; 03-03-2010 at 04:13 AM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Download a db table through UNIX shell script

Hi, I'm an amateur and need your help in figuring this out. I have been asked to connect to a prod db from non-prod env., and download a table from prod db to non-prod env. I was able to connect to the prod db and then run a simple query as below. @@@@@@@@@@ ... (7 Replies)
Discussion started by: arunpvp
7 Replies

2. Homework & Coursework Questions

Help with pivoting table shell script

input file txt file 2000 1 name 2000 2 addr 2000 3 phone 2000 4 email 1000 1 name 1000 2 addr 1000 3 phone 1000 4 email 3000 1 name 3000 2 addr 3000 ... (4 Replies)
Discussion started by: senmatrix
4 Replies

3. Shell Programming and Scripting

Need to Print output in table using shell script

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (4 Replies)
Discussion started by: ankit.mca.aaidu
4 Replies

4. Shell Programming and Scripting

Shell Script Table

Hi, i need a bit help. I must write a script with shell- and sed-commands, which reads a table from stdin and writes a html-table on stdout (so i can open it with a web browser). The number of columns must be a parameter for the script, so i can start it for example with: "./htmltab.sh 3... (3 Replies)
Discussion started by: scruffytramp
3 Replies

5. Shell Programming and Scripting

Shell script to query Oracle table

Hi, unix gurnis I need help for following requirement for writing a shell scritp. log in to oracle database, query one table total records (select count(*) from table1), pass the return value to a file. Thanks in advance (2 Replies)
Discussion started by: ken002
2 Replies

6. Shell Programming and Scripting

Create DB table through shell script

Hi, Can anyone tell me that, How to create table in Oracle database through shell script(ksh). Table contains 3 fields, 1] Emp ID, String, primary key 2] Name, String 3] B Date, date. Thanks in advance. (6 Replies)
Discussion started by: Poonamol
6 Replies

7. Shell Programming and Scripting

To update a column in a table through shell script

Hi All, I need to write a shell script in UNIX that should accept booking number as an argument and update it with value "NULL" if the transaction date is greater than 2 years. Booking number and transaction_date are the two columns of the table table_booking. Something like this, through... (3 Replies)
Discussion started by: shilpa_acc
3 Replies

8. Shell Programming and Scripting

Alter Table Shell Script

I want to add some columns to a existing tables through a shell script. Please help. (2 Replies)
Discussion started by: ankitgupta
2 Replies

9. Shell Programming and Scripting

Reading a table in a shell script

Dear all: I want to write a script capable of reading specific rows and collumns of a table, into a variable. Just imagine i have a file named table.dat which contains: GENERAL INFORMATION Col 1 Col2 Col3 1 1 2 2 3 3 4 4 What i want to do... (13 Replies)
Discussion started by: luiscarvalheiro
13 Replies

10. Shell Programming and Scripting

update a oracle table using shell script

Hi, I would like to know how to update a table in Oracle database, if a command in one shell script either successfully completes or it fails.(like Y if its success or N if its a failure) While the command is running,I am able to view the log file created in the Unix machine.After the command... (2 Replies)
Discussion started by: ann_124
2 Replies
Login or Register to Ask a Question