Fetching input from Oracle table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetching input from Oracle table
# 1  
Old 07-27-2015
Fetching input from Oracle table

Hi Gurus,
Would like to is there any possibility to fetch the location[ex : chennai,banglore,salem] and sales data [ex :2000,6000] from the oracle tables from unix.
I am not sure how to fetch the data from oracle table by validating each record. Location id and sales value should be passed from oracle records.

Any inputs from you will be highly appreciated.

Code:
SQL> select * from location_queue
LOCATION_CODE                   TIMING      ID
------------------------------ ---------    -----
DETAILS.LNM CHENNAI,2000           20-JUL-12 KMK
DETAILS.LNM BANGLORE,6000          18-JUL-12 KMS
DETAILS.LNM SALEM,5000             18-JUL-12 KMS
DETAILS.LNM TIRUPUR,2000           18-JUL-12 KMS
DETAILS.LNM TRICHY,2000            18-JUL-12 KMS
DETAILS.SKM                        28-NOV-12 PRM 
DETIALS.SKM                        28-NOV-12 PRM 
DETAILS.MKDM                       01-DEC-12 PRM

1st records -> DETAILS.LNM CHENNAI,2000 -> Chennai should be stored in $location and 2000 should be assigned to $sales value.
Input read from text file :
Code:
cat function.sh
sales=10000;
function_value_1(){
value_1_name=$1
value_1=`sqlplus -S /NOLOG << EOF
  CONNECT dbs/passwd@dbtod
  SET head off
  select put_valueS.$value_1_name
     (&location_id,&SALES) from dual;
  exit;
EOF`}
function_value_2(){
value_2=`sqlplus -S /NOLOG << EOF
  CONNECT dbs/passwd@dbtod
  SET head off
  select put_valueS.put_citywise_value(&location_id,&sales) from dual;
  exit;
EOF`}
function_value_3(){
value3=`sqlplus -S /NOLOG << EOF
  CONNECT dbs/passwd@dbtod
  SET head off
  select put_valueS.put_placewise_value(&location_id,&sales) from dual;
  exit;
EOF`}
function_record_delete () {
sqlplus -S /NOLOG << EOF
  CONNECT dbs/passwd@dbtod
  SET head off
SELECT value(*) INTO count_value FROM TOTAL_value WHERE location_id =&location_id AND sales =&sales;
if [[ "&count_value" >0 ]]
then
EXEC SQL DELETE FROM TOTAL_value WHERE location_id =&location_id AND sales=&sales; 
exit;
EOF}
 
while read location_id
do
  case $location_id in
    chennai|banglore)
      function_value_1 chennai_bang ;;
      function_value_1 put_area_loc_value ;;
    salem|trichy||kovai)
      function_record_delete ;;
      function_value_1 salem_trichy ;;
    tirupur)
      function_record_delete ;;
      function_value_1 tirupur ;;
    *)
      echo "location is out of the range $location_id" ;;
  esac
if [[ "$value_1" =0 ]]then
value2 ;;
value3 ;;
fi
if [[ "$value_1" =0 && "$value_2" =0 && "$value_3" =0]] then
echo"job failed"
else
echo "job sucess"
fi
done < "location.txt"

Code:
 
cat location.txt
chennai
banglore
salem
 tirchy
tirupur


Last edited by arun888; 07-27-2015 at 07:45 AM..
# 2  
Old 08-05-2015
Why not use sqlldr with input file ?

With it you have two possible paths.
Parsing input using complex control file or loading data into temporary table as is with simple control file, then do transformation inside database.

Use the database tools and the database since Oracle costs so much Smilie
This User Gave Thanks to Peasant For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to check if Oracle table exists

I am trying to write a script which allows a user to select the what manipulation he needs to do on a table. I want to check if the table exists or not. If it exists I will continue the other things or else I exit saying table doesn't exist. How might I achieve this. (1 Reply)
Discussion started by: gmatcat
1 Replies

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

3. Shell Programming and Scripting

Problems with fetching data from Oracle database

Here's a database query which looks up the NAME column of PRODUCT table SELECT NAME FROM PRODUCT ; And this query retrieves me the following output SUGAR COCOA HONEY WHEAT CABBAGE CAULI FLOWER Please note the last record CAULI FLOWER contains TWO blank spaces between the two words. ... (4 Replies)
Discussion started by: kumarjt
4 Replies

4. Shell Programming and Scripting

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 (8 Replies)
Discussion started by: milink
8 Replies

5. Shell Programming and Scripting

Fetching CLOB value from oracle into shell script

Hi, Can anybody let me know how i can achieve the below output. I have a select query which selects two columns. I need to spool the value into a dat file for each row that is returned from the query with the coulumn1 as the name of the dat file . ex: column1: location_id column2:... (1 Reply)
Discussion started by: justchill
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 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

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

8. Shell Programming and Scripting

Track changes to Oracle table

Hi, I'm trying to write a program with unix shell scripting to track the changes of a particular table in the Oracle database. I've try reading up on sql TRIGGER function, but I'm not sure if its feasible here. Any idea what kind of syntax should I use to track the changes in the table? Can... (0 Replies)
Discussion started by: mervinboyz
0 Replies

9. HP-UX

upload oracle table

am on HP-Unix and want to upload table on windows oracle from HP-Unix Thanx Swapnil (2 Replies)
Discussion started by: swapnil286
2 Replies
Login or Register to Ask a Question