Change in script to hardcode in a query


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Change in script to hardcode in a query
# 1  
Old 03-31-2010
Change in script to hardcode in a query

HI,
In a script i am using a query
Code:
 ${SQLPLUS_SETTINGS}
        select c.CYCLE_CODE ||'|'|| NEXT_CYCLE_INST ||'|'||  CYCLE_YEAR ||'|'|| to_char(trunc(CYCLE_CLOSE_DATE +1),'DD-MON-YY
YY')||'|'|| to_char(ADD_MONTHS(CYCLE_CLOSE_DATE,1),'DD-MON-YYYY') ||'|'|| CYCLE_MONTH  FROM PM1_CYCLE_STATE C, RPR1_CYCLE_PAR
TITION_REL CPR WHERE C.CYCLE_CODE = CPR.CYCLE_CODE AND C.PARTITION_ID = CPR.PARTITION_ID AND CPR.PARTITION_ID = 15 AND TRUNC
(C.CYCLE_CLOSE_DATE) >= (SELECT MAX (LOGICAL_DATE) FROM LOGICAL_DATE WHERE LOGICAL_DATE_TYPE = 'B' AND EXPIRATION_DATE IS NUL
L) order by c.cycle_code,c.cycle_year,c.cycle_month;


Now What is done is by using cut command filed are populated
Code:
export PREV_CYCLE_NO=$CYCLE_NO
        export NXT_CYCLE_MONTH=`echo $CYCLE|cut -d'|' -f2`
        export NXT_CYCLE_YEAR=`echo $CYCLE|cut -d'|' -f3`

        export NXT_CYCLE_START_DATE=`echo $CYCLE|cut -d'|' -f4`
        export NXT_CYCLE_CLOSE_DATE=`echo $CYCLE|cut -d'|' -f5`
        export PREV_CYCLE_INST=`echo $CYCLE|cut -d'|' -f6`

        mon=`echo $NXT_CYCLE_CLOSE_DATE|cut -d'-' -f2`
        year=`echo $NXT_CYCLE_CLOSE_DATE|cut -d'-' -f3`
        export NXT_CYCLE_CLOSE_DATE='28-'$mon'-'$year
        echo $NXT_CYCLE_CLOSE_DATE

Now I dont want to hard code to 28, want the query to do the same thing.
All my NXT_CYCLE_CLOSE_DATE = 28/MM/YYYY.

Please help

Last edited by Scott; 03-31-2010 at 02:05 PM.. Reason: Code tags, please...
# 2  
Old 03-31-2010
You don't want to hardcode 28? Don't, then.

Code:
export NXT_CYCLE_CLOSE_DATE=$day-$mon-$year
echo $NXT_CYCLE_CLOSE_DATE

You'll need to set $day somewhere else, presumably along where $mon and $year are being set.

Calling cut millions of times like that is extremely inefficient but without seeing the rest of the code, along with whatever data you're inputting, we can't do much about that.
# 3  
Old 03-31-2010
I have a table cycle_definition in which i have a colounm having cycle_close_day now this i want to insert into day (dd) part of this query in CYCLE_CLOSE_DATE .

cycle_close_day = 28
means CYCLE_CLOSE_DATE = 28/03/2010



Code:
select c.CYCLE_CODE ||'|'|| NEXT_CYCLE_INST ||'|'|| CYCLE_YEAR ||'|'|| to_char(trunc(CYCLE_CLOSE_DATE +1),'DD-MON-YYYY')||'|'||
 to_char(ADD_MONTHS(CYCLE_CLOSE_DATE,1),'DD-MON-YYYY') ||'|'|| CYCLE_MONTH ||'|'|| d.CYCLE_CLOSE_DAY FROM PM1_CYCLE_STATE C, 
RPR1_CYCLE_PARTITION_REL CPR,CYCLE_DEFINITION D WHERE C.CYCLE_CODE = CPR.CYCLE_CODE AND C.PARTITION_ID
 = CPR.PARTITION_ID AND CPR.PARTITION_ID = 15 and C.CYCLE_CODE=D.CYCLE_CODE AND TRUNC
(C.CYCLE_CLOSE_DATE) >= (SELECT MAX (LOGICAL_DATE) FROM LOGICAL_DATE WHERE LOGICAL_DATE_TYPE = 'B' AND EXPIRATION_DATE IS
 NULL) order by c.cycle_code,c.cycle_year,c.cycle_month;


Last edited by Scott; 03-31-2010 at 04:26 PM.. Reason: re-added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Further to my query re: failed attempt to change email address on existing account

Neo Thanks for your reply to my original post, entitled "Problem changing the email address associated with my unix.com account". I am unable to reply to you in that thread, as I am unable to log-on to unix.com! From what you said about purging dormant accounts, it is likely that my account... (1 Reply)
Discussion started by: irb
1 Replies

2. Shell Programming and Scripting

Logon to multiple hosts using ssh hardcode password

Hi im trying to write a script to logon to list of servers with same userID. I have no option/plan to implement ssh-keygen sharing between the systems, so i have written script creating 2 files, file1 holds list of hosts host1 host2 host3 file2 has following script for i in `cat file1`... (1 Reply)
Discussion started by: dreamaix
1 Replies

3. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

4. Shell Programming and Scripting

Script query

Hi Admins, count=`ps -ef | grep LIST_8i | grep -v grep|wc -l` pid=`ps -ef|grep LIST_8i|grep -v grep|awk '{print $2}'` if then lsnrctl stop LIST_8i >> ${log} sleep 5 lsnrctl start LIST_8i >> ${log} else echo " " lsnrctl start LIST_8i >> ${log} fi 2>&1 The script restarts... (5 Replies)
Discussion started by: newaix
5 Replies

5. Shell Programming and Scripting

How can we hardcode TNS_ADMIN?

How can we hardcode TNS_ADMIN? When i try to connect to db with the code below..i get TNS issue. So wpndering if i can hardcode TNS.. <html> <head> <title>xxxxxxxxxxxxxx</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <% ### Load modules, connect to... (2 Replies)
Discussion started by: rdhanek
2 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

mysqldump script without hardcode password

OS: Linux ambglx02 2.6.16.60-0.21-default #1 Tue May 6 12:41:02 UTC 2008 i686 i686 i386 GNU/Linux Shell: bash Currently I have a mysqldump script to backup my mysql database, the command is as below: /opt/novell/mysql/bin/mysqldump --add-drop-table -u root -p -h mydb > /home/john/mydb.sql ... (5 Replies)
Discussion started by: bulkbiz
5 Replies

8. UNIX for Dummies Questions & Answers

Permission change query

I need to change permission for a directory from drwxrwxrwx to drwxr--s--T What chmod command will work? What will be the number code to represent the required permission? (4 Replies)
Discussion started by: krishmaths
4 Replies

9. Solaris

i wanto hardcode password for a username to ssh to a server using script

Dear all i want to ssh to a server via running a shell script with a username and i want to hard code the password for that particular username can u help me please Thank u Naree (8 Replies)
Discussion started by: naree
8 Replies

10. UNIX for Dummies Questions & Answers

Date change related query

Good day folks, This is my first post on this board and I thank you in advance for helping me with this issue. Any idea how I can synchronize server time with another timeserver but have my server lag behind by 2 seconds? Meaning...I need a simple unix script that I can run as crone that... (2 Replies)
Discussion started by: franklo
2 Replies
Login or Register to Ask a Question