Scirpt to fetch the variable from sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scirpt to fetch the variable from sqlplus
# 1  
Old 07-28-2015
Scirpt to fetch the variable from sqlplus

Hi Gurus,

I am stuck with the step where i need to fetch the location & sales from the below procedure by taking it from table field using the for loop. any idea how this can be done in unix. From one column both the location and sales are taken out.

Code:
create or replace procedure newyork
as          
cursor rec 
IS
select * from location_queue where location like daily.mmm%';
V_LOC_CT       NUMBER;
v_location_id     VARCHAR2(50);
v_sales           NUMBER;
BEGIN 
for i in rec
loop
select substr(i.location,12,4)  INTO v_location_id from dual;
select substr(i.location,17,4) INTO v_sales from dual; 
DBMS_OUTPUT.PUT_LINE ('locationid is '||v_location_id);
DBMS_OUTPUT.PUT_LINE ('sales is '||v_sales);
SELECT COUNT(*) INTO LOC_CT FROM TOTAL_COUNT WHERE location_ID = v_location_id AND   sales= v_sales;
IF V_CHK_COUNT > 0 THEN
DELETE FROM TOTAL_COUNT WHERE location_ID = v_location_id AND sales= v_sales;
END


Last edited by arun888; 07-28-2015 at 11:16 AM..
# 2  
Old 07-28-2015
Hello Arun,

We would like to know following answers please on your request.
1st: What you have tried so far?
2nd: Do you want anything to fetch from the output of above queries?
3rd: If yes for above, then please do show us the output (Please make it is as a habit to show input and expected output).
4th: If any other information which is necessary to be added should be included too.


Thanks,
R. Singh
# 3  
Old 07-28-2015
Hi Ravi/All,

I have written a oracle procedure where i am not able to send email from oracle due to priviliges issue. any idea how to call it from unix shell side

Output Required :

If job is success/failure need to trigger an email from unix.

Please help me out how to call the below oracle function from unix & send the email from unix

Code:
cursor rec 
IS
SELECT * FROM location_id_queue where location like '%DETAILS.LLL%';
V_value_COUNT       NUMBER;
V_proc_name       VARCHAR2(50);
V_valuexxx          NUMBER;
V_valuexxx2         NUMBER;
V_valuexxx3                           NUMBER;
v_location_id       VARCHAR2(50);
v_sales            NUMBER;
BEGIN 
for i in rec
loop
select substr(i.location,12,4)  INTO v_location_id from dual;
select substr(i.location,17,4) INTO v_sales from dual;                
v_proc_name := 'JOBS';
DBMS_OUTPUT.PUT_LINE ('Program name '||V_proc_name);
DBMS_OUTPUT.PUT_LINE ('outletid is '||v_location_id);
DBMS_OUTPUT.PUT_LINE ('sales is '||v_sales);
DBMS_OUTPUT.PUT_LINE ('Now Getting the count from the table for the outlet '||v_location_id);
SELECT COUNT(*) INTO V_value_COUNT FROM COUNT WHERE location_id = v_location_id AND   sales= v_sales;
                IF V_value_COUNT > 0 THEN
                DELETE FROM COUNT WHERE location_id = v_location_id AND sales= v_sales;
                ELSE
                DBMS_OUTPUT.PUT_LINE ('No Data found from the table TOTAL_Count '||v_location_id);
                END IF;
                IF v_location_id IN ('chen','bang') THEN
                select GET_COUNTS.GET_bang_chen_COUNT(v_location_id,v_sales) INTO V_valuexxx from dual;
  DBMS_OUTPUT.PUT_LINE ('chen/bang functions'|| V_valuexxx);
    ELSIF   v_location_id IN ('sale','tric','padi','madu','PUDU') THEN
   select GET_COUNTS.GET_OTHER_OUTLET_COUNT(v_location_id,v_sales) INTO V_valuexxx from dual;
  DBMS_OUTPUT.PUT_LINE ('sale/tric/padi/madu/PUDU function '|| V_valuexxx);
                ELSIF v_location_id IN ('TIRU') THEN
select GET_COUNTS.GET_TIRU_COUNT(v_location_id,v_sales) INTO V_valuexxx from dual;
DBMS_OUTPUT.PUT_LINE ('TIRU function'|| V_valuexxx);
                END IF; 
                IF V_valuexxx = 0 THEN
  select GET_COUNTS.GET_CRT_COUNT(v_location_id,v_sales) INTO V_valuexxx2 from dual;
select GET_COUNTS.GET_PANEL_COUNT(v_location_id,v_sales) INTO V_valuexxx3 from dual;
   END IF;
                 BEGIN
                IF  V_valuexxx = 0 and  V_valuexxx2 = 0 and  V_valuexxx3 = 0 THEN
DBMS_OUTPUT.PUT_LINE ('Job Sucess'||v_location_id);
ELSE       
DBMS_OUTPUT.PUT_LINE ('Job Failed'|| v_location_id);
END IF; 
                EXCEPTION
            WHEN OTHERS THEN
                                                DBMS_OUTPUT.PUT_LINE ('Program errors while sending email due to:'||SQLERRM);   
                 END;
                  END LOOP;
                EXCEPTION
            WHEN OTHERS THEN
                DBMS_OUTPUT.PUT_LINE ('Program errors due to:'||SQLERRM);
                
END;


Last edited by arun888; 07-28-2015 at 12:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sqlplus variable UNIX

hi guys i have a sqlplus : sqlplus -s username/password << EOF @mysql.sql EOF in mysql.sql there is a count of a table, i want to write in a variabile unix. how can i do? Thanks a lot Regards Francesco. (3 Replies)
Discussion started by: Francesco_IT
3 Replies

2. Shell Programming and Scripting

Fetch field to variable

Input.txt NOTE1|VALUE1|HMM|UPSTR| NOTE2||HMP|UPSTR| NOTE3|VALUE3|HML|UPSTR| NOTE4||HMD|UPSTR| NOTE5|VALUE5|HMS|UPSTR| NOTE6|VALUE6|HSD|UPSTR| NOTE7||HSS|UPSTR| NOTE8|VALUE8|HEE|UPSTR| NOTE9|VALUE9|HER|DOWNSTR| NOTE50|VALUE1|HEE|DOWNSTR| I am trying to read field 1, 2 and 3 from the... (4 Replies)
Discussion started by: Joselouis
4 Replies

3. UNIX for Advanced & Expert Users

[Solved] Unable to fetch the UNIX variable information

I am having a file called variable_info.ksh in that file I am having following global variable information like… EMAIL_PATH=/var/mail TMP_PATH=/home/tmp And we are having another temporary parameter file abcd.txt, in that file we are having the following information like… EMAIL|EMAI_PATH I... (4 Replies)
Discussion started by: mesahammad
4 Replies

4. Shell Programming and Scripting

awk with variable from sqlplus

Hi, I'm a it stuck on the below code where a variable is pulled from sqlplus and used in awk. It runs with no errors but still pulls back all records in the input file. It should pull the max reference from sql plus and then only print those records where the reference value in column 1 is... (4 Replies)
Discussion started by: jonathanb30
4 Replies

5. Shell Programming and Scripting

Fetch the different data by searching with a same variable from a file in AIX server

Hi, I am trying to fetch the different values in an xml file by searching with the same variable in AIX Server. <name>SharedResources/Shared/JNDI/Username</name> <value>admin</value> <name>SharedResources/Shared/JNDI/Username</name> ... (1 Reply)
Discussion started by: tejastrikez
1 Replies

6. UNIX for Dummies Questions & Answers

fetch Variable value

Hi Guys, I have written a script that declares all the variables and its values in a conf file. Now i use a variable whose value i need to change it in one of the sub-file that is used in the script. In the startup file i want to print or check its value. The value get changed and printed... (5 Replies)
Discussion started by: Swapna173
5 Replies

7. Shell Programming and Scripting

Passing the unix variable to sqlplus

Hi, I am writing a script which creates an external table using a shell script. My requirement is like this. Usage: . ./r.ksh <table_name> - this should create an external table. e.g . ./r.ksh abc - this should create an external table as abc_external. How do i achieve this? Please... (5 Replies)
Discussion started by: Anaramkris
5 Replies

8. Shell Programming and Scripting

How to fetch variable value in if block and to compare it with certain string

Hi, I am trying to execute this command if ; then but getting error .Some problem with reteriving the value of $exception_info. Please help.Its urgent. thanks (4 Replies)
Discussion started by: khushboo
4 Replies

9. Shell Programming and Scripting

Unix code to fetch the first field till space in a variable

Hi, I want to get the value of the first field till space in a variable. e.g x=323 /test/personel/logs/File1 I want to get the first field till space i.e 323 in another variable ,lets say y. echo $x|cut -d' ' -f1 gives 323 but when I'm trying y=`echo $x|cut -d' ' -f1 its giving... (3 Replies)
Discussion started by: autosys_nm
3 Replies

10. Shell Programming and Scripting

Using a variable in sqlplus

Hello, I'm trying to write a script that will loop a sql statement through an external list. Basically, the script enters a loop and runs the sql statement for each entry in the list file. Currently, the script will stop at a cursor where I can then manually enter the SQL statment. This is... (11 Replies)
Discussion started by: MadHatter
11 Replies
Login or Register to Ask a Question