Retrieving values from the oracle table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieving values from the oracle table
# 1  
Old 12-09-2010
Retrieving values from the oracle table

Hi,

How to retrieve two different date values(min & max) from the oracle table and assign to two different variables in the shell script to process further.

With Regards
# 2  
Old 12-09-2010
Code:
var=`sqlplus username/password@database<<EOF
select date from table;
exit;
EOF`

R0H0N
# 3  
Old 12-09-2010
Hi,

how to return a date value from the function called ?

With Regards
# 4  
Old 12-09-2010
In shell scripting, there is no concept of return value from function. Its a line by line execution. So u can directly use variables set in function afterwords. Consider following code.

Code:
function abc {
....
command 1
command 2
....
var=5
}

function main {
....
abc
date=$var           # I can directly use this variable here which was set in abc function
....
}

The only thing u need to remember is make sure functions are defined before its execution.
R0H0N
# 5  
Old 12-09-2010
Hi,

I need to execute the below code to get the max & min date from the table:

Code:
su - oracle<<EOC
export PATH=${PATH}:${ORACLE_HOME}/bin
id -a
exit
EOC

`sqlplus abc/xyz123@localdb<<EOS
select min(time) from tab_purg;
select max(time) from tab_purg;
exit
EOS`

I want to store the date values retrieved from the above two queries in two different variables and want this variable values to display on the screen.

How can it be done ?

With Regards
# 6  
Old 12-09-2010
Code:
set `sqlplus abc/xyz123@localdb<<EOS
select min(time)||"|"||max(time) from tab_purg;
exit;
EOS`

bothDates="$1"
first=`echo $bothDates|cut -d"\|" -f1`
second=`echo $bothDates|cut -d"\|" -f2`
echo "First=$first and Second=$second"

R0H0N
# 7  
Old 12-09-2010
Hi,

Below is the output of your solution:

First=SQL*Plus: and Second=Release

I need to display date values from the table tab_purg as explained earlier.

With Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

2. Shell Programming and Scripting

Retrieving values from a line in text file

Hi, I am new to Unix/ksh script and will like to check how do I retrieve just the count of '258' in the last line in a text file ? There will be this "TRL" appended with number of count at the last line in a text file . TRL0000000258 var=`grep 'TRL' $HOME/folder/test.txt | wc -l` ... (12 Replies)
Discussion started by: snowfrost
12 Replies

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

4. Shell Programming and Scripting

Problem with retrieving values from properties file

I have an input file like RMS_RPT_PERIOD_DIM,Table,NYTD_SLS_DM,GPS_SLS_DM1,NYTD_SLS_GPS_INT,RMS_DM,byreddys,7/31/2009,byreddys,7/31/2009,Y,//depot/eqr/salesgps/trunk/src/db/table,TBL_GPS_CONTACT_DETAILS.sql,1.1,,lakshmi,sql,y... (2 Replies)
Discussion started by: sailaja_80
2 Replies

5. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

6. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

7. Shell Programming and Scripting

UNIX shell scripting for retrieving from oracle

Hello folks, Please find the below code:(sample5.sh -> filename) echo "Selecting dat afrom Cause code" echo "set appinfo Causecode $preamble set serveroutput on size 10000 select * from RMI003_CAUSE_CODE /" | sqlplus -S $username@$hoststring/$password >> test2.dat When i tried executing... (5 Replies)
Discussion started by: sundar_ravi4
5 Replies

8. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

9. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies
Login or Register to Ask a Question