Home » SQL & PL/SQL » SQL & PL/SQL » oracle procedure (oracle 10g)
oracle procedure [message #640333] Mon, 27 July 2015 06:56 Go to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
Hi Guru's,

can anyone help me how to write a oracle procedure for the below requirement.

Step 1 :


SQL> select * from location_queue ;

PROCESS_CODE                   SCHEDULED SCHED PERFORM_WHEN
------------------------------ --------- ----- --------------------
locationCNT CHICAGO,1672o           29-SEP-14
locationCNT BOSTON,1673           29-SEP-14
locationCNT CHICAGO,1673           29-SEP-14
locationCNT NEW YORK,1673           30-SEP-14
locationRETUPD                  19-DEC-14
locationZPUPD                   09-JAN-15

Each record need to be passed & location and sales need to be taken as input only for %locationCNT% records.

Input : location =CHICAGO, sales=1672 need to be 


Step 2:

SELECT COUNT(*) INTO value FROM areas WHERE location = &ocation AND   sales      = &ales;

Step 3 :

If count>0,delete the records from the table.
EXEC SQL DELETE FROM area   WHERE location = &ocation   AND   sales  = &sales;

Step 4 :

WHEN (location = 'CALIFORNIA'| location = 'BOSTON')
:VALUE:=PUTCOUNTS.LET_BOSTON
               (:location,:sales);
WHEN (location ='MASS'|location = 'CHICAGO' |location = 'NEW YORK')
:VALUE:=PUTCOUNTS.LET__CHICAGO
               (:location,:sales);
WHEN (location = 'MASCCEHUTES')
:VALUE:=PUTCOUNTS.LET_MASSCHEUTES
               (:location,:sales);
			   
			   


Oracle functions are :

PUTCOUNTS.LET__CHICAGO
PUTCOUNTS.LET__CHICAGO

[Updated on: Mon, 27 July 2015 06:58]

Report message to a moderator

Re: oracle procedure [message #640335 is a reply to message #640333] Mon, 27 July 2015 07:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Indent the code, use code tags and align the columns in result.

If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data, and an example would be clearer than your short explanations (you are not limited in the number of words, so use plain English to to explain what you want from what exactly).

Re: oracle procedure [message #640336 is a reply to message #640335] Mon, 27 July 2015 07:16 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
sorry for not providing in tags.
I am new to plsql. Any help would be greatly appreciated.

SQL> select * from location_queue ;

Location                          date            userid
------------------------------ --------- ----- --------------------
locationCNT CHICAGO,1672o           29-SEP-14    ldfo
locationCNT BOSTON,1673             29-SEP-14    lfoi
locationCNT CHICAGO,1673            29-SEP-14    lfoi
locationCNT NEW YORK,1673           30-SEP-14    lplm
locationRETUPD                      19-DEC-14    lfks
locationZPUPD                       09-JAN-15    fsds

Each record need to be passed & location and sales need to be taken as input only for %locationCNT% records.

Input : location =CHICAGO, sales=1672 need to be 


Step 2:

SELECT COUNT(*) INTO value FROM areas WHERE location = &location AND   sales      = &ales;

Step 3 :

If count>0,delete the records from the table.
EXEC SQL DELETE FROM area   WHERE location = &location   AND   sales  = &sales;

Step 4 :

if (location = 'CALIFORNIA'|| location = 'BOSTON')
:VALUE:=PUTCOUNTS.LET_BOSTON
               (:location,:sales);
if (location ='MASS'|location = 'CHICAGO' || location = 'NEW YORK')
:VALUE:=PUTCOUNTS.LET__CHICAGO
               (:location,:sales);
if (location = 'MASCCEHUTES')
:VALUE:=PUTCOUNTS.LET_MASSCHEUTES
               (:location,:sales);
			   


Oracle functions are :
PUTCOUNTS.LET_MASSCHEUTES
PUTCOUNTS.LET__CHICAGO
PUTCOUNTS.LET_BOSTON

[Updated on: Mon, 27 July 2015 07:23]

Report message to a moderator

Re: oracle procedure [message #640338 is a reply to message #640336] Mon, 27 July 2015 07:23 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Your requirement is a little unclear. As Michel said:
Michel Cadot wrote on Mon, 27 July 2015 13:11

Welcome to the forum.
...If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data, and an example would be clearer than your short explanations (you are not limited in the number of words, so use plain English to to explain what you want from what exactly).


Re: oracle procedure [message #640339 is a reply to message #640338] Mon, 27 July 2015 07:39 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
In the location table, there will be a records starting with
 DETAILS.LNM CHENNAI,2000 
From this I need to pick before , as 1st argument ie Chennai and After , as 2nd argument ie sales Value. Should pass every record in the for loop and execute the below steps.
Examples :
DETAILS.LNM BANGLORE,6000 => Banglore 1st arg as location id and 6000 as 2nd arg as sales value.
DETAILS.LNM SALEM,5000 => Salem 1st arg as location id and 5000 as 2nd arg as sales value
DETAILS.LNM TIRUPUR,2000 => Tirupur 1st arg as location id and 2000 as 2nd arg as sales value.

Records in table location_all
SQL> select * from location_queue
LOCATION_CODE
------------------------------
DETAILS.LNM CHENNAI,2000
DETAILS.LNM BANGLORE,6000
DETAILS.LNM SALEM,5000
DETAILS.LNM TIRUPUR,2000
DETAILS.LNM TRICHY,4000
DETAILS.SKM
DETIALS.SKM
DETAILS.MKDM

SELECT COUNT(*) INTO value FROM areas WHERE location = CHENNAI AND sales= 2000;

If VALUE>0,delete the records from the table.

EXEC SQL DELETE FROM area WHERE location =chennai AND sales= 20000

if (location = 'CHENNAI'|| location = 'BANGLORE')

#function need to be triggerd for Chennai/banglore

VALUE=PUTCOUNTS.LET_chennai('chennai',20000);

if (location = 'SALEM'|| location = 'TRICHY')

#function need to be triggerd for salem/trichy

VALUE:=PUTCOUNTS.LET_salem(:location,:sales);

If value =0 then
print "job success"
else
print "job failed"
[/code]

Value is the variable.
Respective functions are triggeres for the different locations




[Updated on: Mon, 27 July 2015 07:42]

Report message to a moderator

Re: oracle procedure [message #640341 is a reply to message #640339] Mon, 27 July 2015 07:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Try to post what we have requested.
And, please be cleared and don't change programming language at each line:
"SQL> select * from location_queue" seems to indicate you want to use SQL*Plus and SQL
"SELECT COUNT(*) INTO value FROM areas WHERE location = CHENNAI AND sales= 2000;" seems to be PL/SQL
"EXEC SQL DELETE FROM area WHERE location = &ocation AND sales = &sales;" seems to be a mix up of Pro*X language and SQL*Plus syntax (which does not support Pro*X language).

So restart from the beginning.
Post a test case.
Explain what you want from this one and what are the specification to get it.

Re: oracle procedure [message #640342 is a reply to message #640341] Mon, 27 July 2015 08:07 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
sure. sorry for not providing the details clearly.

I am trying to code this in the procedure.
Each record need to be validated and respective functions need to be triggered for location wise.
 select * from location_queue
 location_code
 ------------------------------ 
 DETAILS.LNM CHENNAI,2000 
 DETAILS.LNM BANGLORE,6000 
 DETAILS.LNM SALEM,5000 
 DETAILS.LNM TIRUPUR,2000 
 DETAILS.LNM TRICHY,4000 
 DETAILS.SKM 
 DETIALS.SKM 
 

select count(*) into count_locat from total_area where location='Chennai' and sales=2000;

if count_locat >0

delete from count_locat where location='Chennai' and sales=2000;

else 

print "no records found"

1) location=Chennai/banglore

Need to check function1[letchennai] returns o or 1.

value=putcount.letchennai('chennai',20000);

2) location =salem/trichy

Salem/trichy sales and location need to be passed in the function.

Need to check function1[letsalem] returns o or 1.

value=putcount.letsalem(:location,:sales);

Both the function [letsalem] and [letchennai] are different.

If value=0
then
do 
Mail "Job success" kkds@xxys.xom
else 
mail " Job failed" kkds@xxys.xom

fi


Please let me know if I am still not clear.
Re: oracle procedure [message #640343 is a reply to message #640342] Mon, 27 July 2015 08:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SQL> select * from location_queue;
select * from location_queue
              *
ERROR at line 1:
ORA-00942: table or view does not exist


Is this clear?

Re: oracle procedure [message #640344 is a reply to message #640342] Mon, 27 July 2015 08:10 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Quote:
SQL and PL/SQL issues or errors:

Include the CREATE table statement, provide sample data (INSERT statements) as well as the expected result. Also include the SQL code that's not working and the error you are getting. For PL/SQL errors, provide the code with the error's line number and the method that was used to call it.

[Updated on: Mon, 27 July 2015 08:11]

Report message to a moderator

Re: oracle procedure [message #640346 is a reply to message #640339] Mon, 27 July 2015 08:18 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
Steps to be executed:
Step 1 :

SQL> select * from location_queue ;

PROCESS_CODE                   date
------------------------------ ---------  
locationCNT TRICHY,16720         29-SEP-14
locationCNT BANGLORE,16730       29-SEP-14
locationCNT TRICHY,16730         29-SEP-14
locationCNT SALEM,16730          30-SEP-14
locationRETUPD                   19-DEC-14
locationZPUPD                    09-JAN-15

Each record need to be passed & location and sales need to be taken as input only for %locationCNT% records.

Input : location =TRICHY, sales=1672 need to be 


Step 2:

select COUNT(*) into value from  areas where location = &ocation and sales= &ales;

Step 3 :

If count>0,delete the records from the table.

delete from areas  where  location = &ocation and   sales  = &sales;

Step 4 :

if (location = 'CHENNAI'| location = 'BANGLORE')
VALUE:=PUTCOUNTS.LET_BANGLORE(&location,&sales);
if(location ='KOVAI'|location = 'TRICHY' |location = 'SALEM')
VALUE:=PUTCOUNTS.LET__TRICHY('&location',&sales);
WHEN (location = 'TIRUPUR')
VALUE:=PUTCOUNTS.LET_TIRUPUR(:location,:sales);
			   
Step 5:
If value=0 , then calculate value1 & value2 by executing the below function.
value1:=PUTCOUNTS.PUTVALUE1(&LOCATION,&SALES;
value2:=PUTCOUNTS.PUTVALUE2(&LOCATION,&SALES);

step 6:

if [value=0 && value1=0 && value2=0] then
do 
print "Job got sucesss"
else
print "job got failed"



Function :

PUTVALUE1(&LOCATION,&SALES;
PUTVALUE2(&LOCATION,&SALES);
LET_TIRUPUR(:location,:sales);
LET_BANGLORE(&location,&sales);

Variable :
Value
value1
Value2
Expected result:
Re: oracle procedure [message #640347 is a reply to message #640344] Mon, 27 July 2015 08:20 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
hi lalith,

I am not sure where to create a dummy table here for you to access it.
Re: oracle procedure [message #640349 is a reply to message #640347] Mon, 27 July 2015 08:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Just write
CREATE TABLE...
and we will create the table on our side.

Re: oracle procedure [message #640353 is a reply to message #640349] Mon, 27 July 2015 08:27 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
create table location_queue
(
location varchar2(30) NOT NULL, date_time date NOT NULL, id varchar2(5) NOT NULL);

Re: oracle procedure [message #640354 is a reply to message #640353] Mon, 27 July 2015 08:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Good, now the INSERT statements.

Re: oracle procedure [message #640355 is a reply to message #640342] Mon, 27 July 2015 08:36 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
insert INTO location_queue(location, date_time,id)VALUES('locationCNT CHICAGO,1672o', '29-SEP-14', 'ldfo');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT BOSTON,1673',  '29-SEP-14', 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT CHICAGO,1673', '29-SEP-14', 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT NEW YORK,1673', '29-SEP-14', 'lplm');

insert INTO location_queue(location, date_time,id)VALUES('locationRETUPD', '29-SEP-14', 'lfks');

insert INTO location_queue(location, date_time,id)VALUES('locationZPUPD', '29-SEP-14', 'fsd');

[Updated on: Mon, 27 July 2015 08:37]

Report message to a moderator

Re: oracle procedure [message #640356 is a reply to message #640355] Mon, 27 July 2015 08:43 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

'29-SEP-14' is not a DATE it is a string and this expression will not work for many of us.
Use TO_DATE function with a date format to fix your statements. It should be better you use month number instead of month name or you have to specify the date language in the TO_DATE function.

Re: oracle procedure [message #640357 is a reply to message #640356] Mon, 27 July 2015 08:45 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
thanks for your correction.

insert INTO location_queue(location, date_time,id)VALUES('locationCNT CHENNAI,1672o', 'to_date', 'ldfo');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT BANGALORE,1673',  'to_date', 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT SALEM,1673', 'to_date', 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT TRICHY,1673', 'to_date', 'lplm');

insert INTO location_queue(location, date_time,id)VALUES('locationRETUPD', '29-SEP-14', 'to_date');

insert INTO location_queue(location, date_time,id)VALUES('locationZPUPD', '29-SEP-14', 'to_date');

[Updated on: Mon, 27 July 2015 08:51]

Report message to a moderator

Re: oracle procedure [message #640358 is a reply to message #640357] Mon, 27 July 2015 08:50 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read what you posted, do you sincerely think it is correct?

TO_DATE

Re: oracle procedure [message #640359 is a reply to message #640358] Mon, 27 July 2015 08:59 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
no its not. It should be TO_DATE.
Sorry for my mistake.

[Updated on: Mon, 27 July 2015 08:59]

Report message to a moderator

Re: oracle procedure [message #640361 is a reply to message #640359] Mon, 27 July 2015 09:03 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Run your insert statements aginst your table. Do they work?
Re: oracle procedure [message #640362 is a reply to message #640361] Mon, 27 July 2015 09:11 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
its not getting insered not sure what I did wrong.
Re: oracle procedure [message #640363 is a reply to message #640362] Mon, 27 July 2015 09:15 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
SQL> insert INTO location_queue(location, date_time,id)VALUES('locationCNT NEW YORK,1673',CURRENT_TIMESTAMP, 'lplm');


Its works now
Re: oracle procedure [message #640366 is a reply to message #640363] Mon, 27 July 2015 09:25 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
So repost your insert statements with code that works (test that those statements work before posting them
Re: oracle procedure [message #640367 is a reply to message #640366] Mon, 27 July 2015 09:33 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
sure I will check it before I post.

insert INTO location_queue(location, date_time,id)VALUES('locationCNT CHENNAI,1672o', CURRENT_TIMESTAMP, 'ldfo');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT BANGALORE,1673', CURRENT_TIMESTAMP, 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT SALEM,1673', CURRENT_TIMESTAMP, 'lfoi');

insert INTO location_queue(location, date_time,id)VALUES('locationCNT TRICHY,1673', CURRENT_TIMESTAMP, 'lplm');

insert INTO location_queue(location, date_time,id)VALUES('locationRETUPD', CURRENT_TIMESTAMP, 'lkml');

insert INTO location_queue(location, date_time,id)VALUES('locationZPUPD', CURRENT_TIMESTAMP, 'kfml');
Re: oracle procedure [message #640368 is a reply to message #640367] Mon, 27 July 2015 09:35 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
A small hint to you:

 SELECT sysdate, TO_DATE('27-07-2015', 'DD-MM-YYYY'), DATE '2015-07-27' FROM dual;
Re: oracle procedure [message #640369 is a reply to message #640368] Mon, 27 July 2015 09:41 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
@OP, Timestamp and date are not same. Timestamp is an extension to the date data type. While date could hold values up to the precision of seconds, timestamp data type goes beyond the precision of seconds. Have a look at this article by TIm Hall https://oracle-base.com/articles/misc/oracle-dates-timestamps-and-intervals
Re: oracle procedure [message #640370 is a reply to message #640368] Mon, 27 July 2015 09:42 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
I have written a procedure below to my understanding. But the location id and week is in the column name location from table location_queue. can you help me how to trim the letter before and after , as field separator and pass the argument $location, $ sales.

SQL> select * from location_queue ;

PROCESS_CODE                   date
------------------------------ ---------  
locationCNT TRICHY,16720         29-SEP-14
locationCNT BANGLORE,16730       29-SEP-14
locationCNT TRICHY,16730         29-SEP-14
locationCNT SALEM,16730          30-SEP-14
locationRETUPD                   19-DEC-14
locationZPUPD                    09-JAN-15

Create or replace procedure Main_Proc 
										
AS

cursor rec 
IS
      SELECT * FROM location; 

V_value       NUMBER;
v_proc_name       VARCHAR2(50);
V_value          NUMBER;
V_value2         NUMBER;
V_value3 		  NUMBER;
BEGIN 
v_proc_name := 'PROCESS';

DBMS_OUTPUT.PUT_LINE ('Insaide the'||v_proc_name);
DBMS_OUTPUT.PUT_LINE ('Now Getting the count from the table areas');
SELECT COUNT(*)
  INTO V_value
  FROM areas
  WHERE location = rec.location
    AND   sales    = rec.sales;
	
	IF V_value > 0 THEN
	DELETE FROM areas
        WHERE location = rec.location
        AND   sales      = rec.sales;
	ELSE
	DBMS_OUTPUT.PUT_LINE ('No Data found from the table areas');
	END IF;
	
	IF rec.location IN ('CHENNAI','BANGLORE') THEN
	V_value := PUTCOUNTS.LET_BANGLORE(rec.location,rec.sales);
    ELSIF   rec.location  IN ('SALEM','TRICHY','KOVAI') THEN
	V_value := PUTCOUNTS.LET__TRICHY(rec.location,rec.sales);
	ELSE rec.location  IN ('TIRUPUR') THEN
	V_value := PUTCOUNTS.LET_TIRUPUR(rec.location,rec.sales);
	 END IF;	
	 
	 IF V_value = 0 THEN
	 V_value2 := PUTCOUNTS.PUTVALUE1(rec.location,rec.sales);
	 V_value3 := PUTCOUNTS.PUTVALUE2(rec.location,rec.sales);
	 END IF;
	 
	 BEGIN
	 IF  V_value = 0 and  V_value2 = 0 and  V_value3 = 0 THEN

	 EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''127.0.0.1''';
     UTL_MAIL.send(sender     => 'me@address.com',
                   recipients => 'you@address.com',
                   subject    => 'Test Mail',
                   message    => 'Job Success',
                   mime_type   => 'text; charset=us-ascii');
     
    ELSE	
	 EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''127.0.0.1''';
     UTL_MAIL.send(sender     => 'me@address.com',
                   recipients => 'you@address.com',
                   subject    => 'Test Mail',
                   message    => 'Job FAIL',
                   mime_type   => 'text; charset=us-ascii');	
				  
	 END IF;	
       	EXCEPTION
            WHEN OTHERS THEN
			DBMS_OUTPUT.PUT_LINE ('Program errors while sending email due to:'||SQLERRM);	 
	 END;
	  
	EXCEPTION
            WHEN OTHERS THEN
			DBMS_OUTPUT.PUT_LINE ('Program errors due to:'||SQLERRM);
	

END;
Re: oracle procedure [message #640372 is a reply to message #640370] Mon, 27 July 2015 09:52 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
arun888 wrote on Mon, 27 July 2015 20:12
       	EXCEPTION
            WHEN OTHERS THEN
			DBMS_OUTPUT.PUT_LINE ('Program errors while sending email due to:'||SQLERRM);	 
	 END;
	  
	EXCEPTION
            WHEN OTHERS THEN
			DBMS_OUTPUT.PUT_LINE ('Program errors due to:'||SQLERRM);


Please read when others.

It's better not to have an exception block than adding noise to the code Smile

[Updated on: Mon, 27 July 2015 09:54]

Report message to a moderator

Re: oracle procedure [message #640375 is a reply to message #640372] Mon, 27 July 2015 10:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It is WHEN OTHERS, in upper case, wiki is case sensitive.

Re: oracle procedure [message #640389 is a reply to message #640375] Mon, 27 July 2015 23:53 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Ah!, yes. Thanks for the correction Michel.
Re: oracle procedure [message #640403 is a reply to message #640389] Tue, 28 July 2015 02:08 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
hi,

I have used the substring function. and i am unable to prinnt the variable. can you tell me whether the code is correct or not.

 SELECT * FROM location_queue; 

location -> column name.

for i in rec
loop
	v_locattion_id :=substr('rec.location',12,4);
	v_sales := substr('rec.location',17,4);
	
v_proc_name := 'SDM JOBS';

DBMS_OUTPUT.PUT_LINE ('Inside the'||V_proc_name);
DBMS_OUTPUT.PUT_LINE ('Inside the programaa'||v_locatioon_id);
DBMS_OUTPUT.PUT_LINE ('Inside the week'||v_sales);

Re: oracle procedure [message #640404 is a reply to message #640403] Tue, 28 July 2015 02:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

What does "i am unable" mean?

Re: oracle procedure [message #640405 is a reply to message #640404] Tue, 28 July 2015 02:12 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
variable is not get printed
Re: oracle procedure [message #640406 is a reply to message #640405] Tue, 28 July 2015 02:38 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Did you "set serveroutput on" or whatever is the equivalent with your tool?

Re: oracle procedure [message #640408 is a reply to message #640403] Tue, 28 July 2015 02:46 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
v_locattion_id :=substr('rec.location',12,4);
	v_sales := substr('rec.location',17,4);

Your substrings will resolve to 'n' and NULL respectively for every iteration of the loop.
Re: oracle procedure [message #640409 is a reply to message #640403] Tue, 28 July 2015 02:51 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
What is your opinion on this:
SQL> select substr('rec.location',12,4) from dual;

S
-
n

? Why did you put the parameter of substring to single quotes - you did it a string literal.

Maybe it is a new way of fixing errors (hiding them), as it would fail because you refer to the cursor name instead of the record name.
http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1363
And, maybe, before any other ready, fire, aim approach, study the documentation in the first place.
Re: oracle procedure [message #640412 is a reply to message #640409] Tue, 28 July 2015 04:59 Go to previous messageGo to next message
arun888
Messages: 100
Registered: June 2015
Location: INDIA
Senior Member
Thanks for your help. Its work now.

Oracle db is 9i.

I would like to know how to send an email from PL SQL language.

It would be great if anyone can help me.

Re: oracle procedure [message #640413 is a reply to message #640412] Tue, 28 July 2015 05:01 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Just search on the board you will find procedures for this.

Re: oracle procedure [message #640414 is a reply to message #640412] Tue, 28 July 2015 05:04 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
OraFAQ wiki : Send mail from PL/SQL.
Re: oracle procedure [message #640420 is a reply to message #640355] Tue, 28 July 2015 06:29 Go to previous messageGo to previous message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
arun888 wrote on Mon, 27 July 2015 08:36
insert INTO location_queue(location, date_time,id)VALUES('locationCNT CHICAGO,1672o', '29-SEP-14', 'ldfo');




Your first column, named LOCATION_QUEUE, looks like it is getting three separate data elements all jammed together -- "locationCNGT", "CHICAGO", and "1672O". This is really, REALLY bad design. You need to read up on the fundamentals of "Data Normalization" and "Third Normal Form." The concept of data normalization and designing your tables to Third Normal Form is not some esoteric subject. It is the very heart of relational databases.
Previous Topic: What is the Difference b/w Up datable Views and Non-Up datable Views their uses
Next Topic: Checking the parameter inside Procedure (merged 2)
Goto Forum:
  


Current Time: Fri Apr 19 12:01:41 CDT 2024