Table is not updating

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Table is not updating
# 36  
Old 03-27-2012
Quote:
Originally Posted by Scrutinizer
I suggested
Code:
while read a b c x

by the way, not:
Code:
while read a b c

To repeat: First check if the input is to your liking by replacing sqlplus.. with cat..., before you do any tests on your test database..


Is that the exact content? because I see empty lines that should not be there....
I have ran wc -l over the file it displayed 3 lines only.
Code:
more AuditGroupTableTableData_20120327051020.txt
1LK81JVDE2HRNDG              3               0                                                                       
                                                                                                                     
                                                                  
1LMXTJJD0W28TX2              3               0                                                                       
                                                                                                                     
                                                                  
1LS1XJGDEVWAC5T              7               1                                                                       
                                                                                                                     
                                                                  
/p2k/L10.21A/devlp/root/global/data/usage/DAILY/AuditGroupLogs_20120327051020> wc -l AuditGroupTableTableData_20120327051020.txt
       3 AuditGroupTableTableData_20120327051020.txt

I have replaced sqlplus with cat ,modified while loop and the output is as follows:
Code:
ModifyUsgAuditGroupTable.ksh 120318
********Started processing at 20120327054718**********
 log file path is : ./AuditGroupLogs_20120327054718/AuditUpdate_20120327054718.LOG
1LK81JVDE2HRNDG
3
0
cat: cannot open secadmin/vivadmin@ltd121a
1LMXTJJD0W28TX2
3
0
cat: cannot open secadmin/vivadmin@ltd121a
1LS1XJGDEVWAC5T
7
1
cat: cannot open secadmin/vivadmin@ltd121a

---------- Post updated at 04:56 AM ---------- Previous update was at 04:48 AM ----------

Quote:
Originally Posted by methyl
Thank you for posting the full sqlplus error message. I don't have the same version of Oracle as you and we all needed to read it.

The sqlplus syntax to invoke a program with parameters does not allow for the parameters to be passed to an script read from STDIN.

The correct approach is to put the whole SQL program into a ".sql" file (as you were advised before) and call it with parameters from the sqlplus line.
An alternative is to use the Shell approach to modify the program prior to execution as per Scrutinizer's advice.
I am confused with the approach you are saying.
I have tried with scrutinizer's way,it throwed me some error msgs which I just posted now
and about the .sql to be passed as parameter approach.
how this file can be modified so SmilieSmilie
Code:
ret=`sqlplus -s  /nolog << EOF
connect $db_user/$db_pwd@$db_sid;
SPOOL  ./$DirectoryName/AuditGroupTableTableData_$TimeStamp.txt;
set pagesize 0
set feedback off 
set verify off 
set heading off 
set echo off 
set linesize 300 
@./$DirectoryName/SQLQuery_$TimeStamp.sql
SPOOL OFF;
EXIT;
EOF`



while read a b c ; do
echo $a
echo $b
echo $c
cat   $db_user/$db_pwd@$db_sid <<EOF

SET HEADING OFF
SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
CNT  NUMBER(5);
DROPCNT NUMBER(5);
ERRORCNT NUMBER(5);
BEGIN
SELECT COUNT(*) INTO CNT FROM USAGE_INTRNL_ERROR WHERE AUDIT_GROUP_ID='$a';

IF ( CNT != $c) THEN
  SELECT INTRL_DROP_QTY,INTRL_ERROR_QTY INTO DROPCNT,ERRORCNT 
     FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR='$a'; 

     DROPCNT :=DROPCNT-CNT;

     UPDATE USAGE_AUDIT_GROUP 
      SET INTRL_DROP_QTY='DROPCNT' ,INTRL_ERROR_QTY='CNT'  
      WHERE  AUDIT_GROUP_NBR='$a' ;
COMMIT;

END IF;
END;
EXIT;
EOF
done < "./$DirectoryName/AuditGroupTableTableData_$TimeStamp.txt"

# 37  
Old 03-27-2012
I meant: replace:
Code:
sqlplus  $db_user/$db_pwd@$db_sid

with
Code:
cat

# 38  
Old 03-27-2012
Quote:
Originally Posted by Scrutinizer
I meant: replace:
Code:
sqlplus  $db_user/$db_pwd@$db_sid

with
Code:
cat

ohh my mistake

I have done it.
this is the output:
Code:
ModifyUsgAuditGroupTable.ksh 120318
********Started processing at 20120327060800**********
 log file path is : ./AuditGroupLogs_20120327060800/AuditUpdate_20120327060800.LOG
1LK81JVDE2HRNDG
3
0

SET HEADING OFF
SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
CNT  NUMBER(5);
DROPCNT NUMBER(5);
ERRORCNT NUMBER(5);
BEGIN
SELECT COUNT(*) INTO CNT FROM USAGE_INTRNL_ERROR WHERE AUDIT_GROUP_ID='1LK81JVDE2HRNDG';

IF ( CNT != 0) THEN
  SELECT INTRL_DROP_QTY,INTRL_ERROR_QTY INTO DROPCNT,ERRORCNT 
     FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR='1LK81JVDE2HRNDG'; 

     DROPCNT :=DROPCNT-CNT;

     UPDATE USAGE_AUDIT_GROUP 
      SET INTRL_DROP_QTY='DROPCNT' ,INTRL_ERROR_QTY='CNT'  
      WHERE  AUDIT_GROUP_NBR='1LK81JVDE2HRNDG' ;
COMMIT;

END IF;
END;
EXIT;
1LMXTJJD0W28TX2
3
0

SET HEADING OFF
SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
CNT  NUMBER(5);
DROPCNT NUMBER(5);
ERRORCNT NUMBER(5);
BEGIN
SELECT COUNT(*) INTO CNT FROM USAGE_INTRNL_ERROR WHERE AUDIT_GROUP_ID='1LMXTJJD0W28TX2';

IF ( CNT != 0) THEN
  SELECT INTRL_DROP_QTY,INTRL_ERROR_QTY INTO DROPCNT,ERRORCNT 
     FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR='1LMXTJJD0W28TX2'; 

     DROPCNT :=DROPCNT-CNT;

     UPDATE USAGE_AUDIT_GROUP 
      SET INTRL_DROP_QTY='DROPCNT' ,INTRL_ERROR_QTY='CNT'  
      WHERE  AUDIT_GROUP_NBR='1LMXTJJD0W28TX2' ;
COMMIT;

END IF;
END;
EXIT;
1LS1XJGDEVWAC5T
7
1

SET HEADING OFF
SET SERVEROUTPUT ON
SET FEEDBACK OFF
DECLARE
CNT  NUMBER(5);
DROPCNT NUMBER(5);
ERRORCNT NUMBER(5);
BEGIN
SELECT COUNT(*) INTO CNT FROM USAGE_INTRNL_ERROR WHERE AUDIT_GROUP_ID='1LS1XJGDEVWAC5T';

IF ( CNT != 1) THEN
  SELECT INTRL_DROP_QTY,INTRL_ERROR_QTY INTO DROPCNT,ERRORCNT 
     FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR='1LS1XJGDEVWAC5T'; 

     DROPCNT :=DROPCNT-CNT;

     UPDATE USAGE_AUDIT_GROUP 
      SET INTRL_DROP_QTY='DROPCNT' ,INTRL_ERROR_QTY='CNT'  
      WHERE  AUDIT_GROUP_NBR='1LS1XJGDEVWAC5T' ;
COMMIT;

END IF;
END;
EXIT;

# 39  
Old 03-27-2012
What you see there (from SET HEADING OFF to EXIT ) is what gets fed into sqlplus. Now you can check if that is what you think it should be.
# 40  
Old 03-27-2012
Quote:
Originally Posted by Scrutinizer
What you see there (from SET HEADING OFF to EXIT ) is what gets fed into sqlplus. Now you can check if that is what you think it should be.
yes,I dont find any mistakes with the content fed.
Am declaring 3 variables CNT,DROPCNT,ERRORCNT.
storing the count(*) value in CNT.
If that (CNT)is not equal to the $c we have passed then we are fetching DROPCNT,ERROR_CNT from the same table.
editing them and updating them in db and commiting it.

It looks fine.

isit possible to display the contents of CNT,ERRORCNT and DROPCNT used inside the script?

---------- Post updated at 06:23 AM ---------- Previous update was at 05:28 AM ----------

Quote:
Originally Posted by methyl
Thank you for posting the full sqlplus error message. I don't have the same version of Oracle as you and we all needed to read it.

The sqlplus syntax to invoke a program with parameters does not allow for the parameters to be passed to an script read from STDIN.

The correct approach is to put the whole SQL program into a ".sql" file (as you were advised before) and call it with parameters from the sqlplus line.
An alternative is to use the Shell approach to modify the program prior to execution as per Scrutinizer's advice.
Hi Methyl,
can you please help me with the approach you have mentioned with the sql file.
Iam cofused with it Smilie
# 41  
Old 03-27-2012
@rkrish
Quote:
sqlplus -s $db_user/$db_pwd@$db_sid $a $b $c <<EOF > ./${DirectoryName}/Query.sql
The corrected command syntax would be:
Code:
sqlplus -s $db_user/$db_pwd@$db_sid  @myprogram.sql $a $b $c > ./${DirectoryName}/Query.sql

Where the contents of myprogram.sql would be everything in the "here document" in your Shell script between EOF and EOF and excluding the actual terminator (EOF). In other words we take the Oracle program code out of the unix Shell script and put it in an Oracle SQL script file.
Similar to your post #26 the SQL program would contain references to &1 &2 &3 to match the parameters supplied on the sqlplus command line (though in the various versions posted on both threads I have only seen you use &1).

Imho embedding SQL in Shell script is great for quick systems admin tasks but for anything more it should be a proper program with change control headers. Also you don't have to bother about clashes with Shell characters like $ .

You will find numerous examples like this in the Oracle demo examples which came with your system.

A word on security:
Most admins would suggest using the /NOLOG parameter to sqlplus and putting the Oracle account login details in an Oracle CONNECT statement as the first line of your SQL program (there's an example in your other now closed thread on this subject). Obviously securing the program file to be only readable by the owner. This stops the username+password being visible in a unix ps display and (if you have it) some forms of unix process accounting.

Last edited by methyl; 03-27-2012 at 05:02 PM.. Reason: remove some ambiguity, spellin, enhance
# 42  
Old 03-28-2012
As pointed out from the beginning, you need a "/" before the "exit;". You claimed that it didn't make a difference. But it definitely has to be there.
This User Gave Thanks to binlib For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Run the Script from any stage by updating data from Oracle Table.

I have 100 Scripts, each containing 10-15 SQL's in them. Each Script run for 40 mins to 1 hour 30 mins. In the event of Failure in any step, if i re-start the Script, it will start running from the beginning. Which is waste of time. So in order handle this, i made the script to run from the... (7 Replies)
Discussion started by: kiran1992
7 Replies

3. Shell Programming and Scripting

Build a table from a list by comparing existing table entries

I am new to this shell scripting.... I have a file which contains list of users. This files get updated when new user comes into the system. I want to create script which will give a table containing unique list of users. When I say unique, it means script should match table while parsing... (3 Replies)
Discussion started by: dchavan1901
3 Replies

4. UNIX for Dummies Questions & Answers

Creating a condensed table from a pre-existing table in putty

Hello, I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information. More specifically, I'd like the program to look at a specific column, say column N, and see if any of the... (5 Replies)
Discussion started by: Deedee393
5 Replies

5. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

6. Shell Programming and Scripting

updating a column in a unix table for a particular row

Hi, I have the following requirement. I have a unix table as below progname par1 par2 par3 par4 PROG1 abc def 0012 ooo PROG2 wed xas 0100 xxx PROG3 kkk ppp 0004 ppp Different programs(ex:PROG1,PROG2..) accesses this table and update... (5 Replies)
Discussion started by: thanuman
5 Replies

7. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

8. Shell Programming and Scripting

script for updating table using file(

Hi, Data file path (.txt) Control file(.ctl) I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me... (1 Reply)
Discussion started by: unihp1
1 Replies

9. UNIX for Dummies Questions & Answers

Updating table on UNIX server using SFTP

Hi, I have a requirement where in I have to connect to an Unix database server using SFTP. After connecting I have to write some data to one of the tables in UNIX. Can anyone tell me the UNIX commands to open and update database table. Thanks, Pallavi (1 Reply)
Discussion started by: Pallavi_gondkar
1 Replies

10. Shell Programming and Scripting

updating a column in oracle table using shell script

Hi friends, i am having a variable declared in .profile.i am changing its value in a shell script and then i am connecting to oracle and then from there i am calling a .sql called update.sql STATUS is the variable declared in the .profile =============================== if sqlplus <<END... (3 Replies)
Discussion started by: sveera
3 Replies
Login or Register to Ask a Question