Home » SQL & PL/SQL » SQL & PL/SQL » Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared (O/S:Windows 8; Product: Oracle; version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production)
Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629035] Tue, 02 December 2014 11:50 Go to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I am trying to capture an error message from the exception block(a private procedure) and then pass it out to the calling procedure. I am getting bogged down with an error "PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared". How can I overcome this or how can I pass the error message to the main procedure.

The situation is as follows:


-- Local variable
   
    CRLF        CONSTANT  VARCHAR2(2) := CHR(13) || CHR(10);

-- --------------------------------------------------------------------------------
-- FORWARD DECLARATIONS
-- -----------------------------------------------------------------------------
  PROCEDURE p_sendmail(p_sender_email  IN VARCHAR2,
                      p_from          IN VARCHAR2,
                      p_to            IN VARCHAR2,
                      msg_subject     IN VARCHAR2 DEFAULT NULL,
                      p_msg_body      IN LONG DEFAULT NULL,
		      p_err_message1  OUT VARCHAR2);




PROCEDURE p_sendmail(p_sender_email  IN VARCHAR2,
                      p_from          IN VARCHAR2,
                      p_to            IN VARCHAR2,
                      msg_subject     IN VARCHAR2 DEFAULT NULL,
                      p_msg_body      IN LONG DEFAULT NULL,
                     p_err_message1   OUT VARCHAR2 ) is
      v_to_list     LONG;
      v_cc_list     LONG;
      v_bcc_list    LONG;
      v_date        VARCHAR2(255) DEFAULT TO_CHAR(SYSDATE, 'DD MON YYYY HH24:MI:SS PM');
      
      g_mail_conn            UTL_SMTP.CONNECTION;
      SMTP_HOST   CONSTANT  VARCHAR2(256) := 'smtp-abc.defg.ca';
      SMTP_PORT   CONSTANT  PLS_INTEGER   := 25;

   BEGIN

      g_mail_conn := UTL_SMTP.OPEN_CONNECTION(SMTP_HOST, SMTP_PORT);

      UTL_SMTP.helo(g_mail_conn, SMTP_HOST);
      UTL_SMTP.mail(g_mail_conn, p_sender_email);   
      UTL_SMTP.rcpt(g_mail_conn, p_to);   
      UTL_SMTP.open_data(g_mail_conn );     
      UTL_SMTP.write_data( g_mail_conn, '' || CRLF);
      UTL_SMTP.write_data(g_mail_conn, p_msg_body);
      UTL_SMTP.close_data(g_mail_conn );
      UTL_SMTP.quit(g_mail_conn);

EXCEPTION

			WHEN utl_smtp.transient_error THEN
			     RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					 --DBMS_OUTPUT.put_line('TransientError: Invalid Operation as service may not be available.');
					 					 
			WHEN utl_smtp.permanent_error THEN
					 RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					 --DBMS_OUTPUT.put_line('Permanent Error: The email id entered is either invalid or recepients mail box is full.');
					 --p_errmessage:=SQLERRM;
					 
			WHEN others THEN
					RAISE_APPLICATION_ERROR(SQLCODE,SQLERRM);
					-- DBMS_OUTPUT.put_line('Unable to send an email.');
					--p_errmessage:=SQLERRM;
			
			IF SQLERRM IS NOT NULL THEN
					 		p_err_message1:=SQLERRM;
			ELSE
			  	 		p_err_message1:=NULL;
			END IF;
					
END p_sendmail;


--The calling procedure below:

p_sendmail(p_sender_email => 'stanjore@someemailid.ca',   --- Send Email to the Donor     
	   p_from => 'PLEDGING <stanjore@someemailid.ca>', 
	   p_to =>   v_store_email_address,
	   p_msg_subject => 'Anonymous User', 
	   p_msg_body => 'Thank you'  ||  
	   CRLF || 
	  'The email confirms that we have received your pledge' ||  
	  CRLF || 
	  CRLF || 
	 ' Name:         ' || v_full_name ||
	  CRLF || 
	 'Temporary  ID: ' || v_azbwccp_id ||
	  CRLF || 
	 'Reference Number:   ' || MTID ||
	 CRLF || 
	 ' Amount:      ' || to_number(campaign_desg_amt1) ||
	 CRLF || 
	' Campaign:    ' || campaign ||
	 CRLF || 
	' Designation: ' || adbdesg_rec.adbdesg_name ||
	 CRLF || 
	' Type:        ' || atvpldg_rec.atvpldg_desc ||
	 CRLF || 
	' Duration:    ' || atvpdur_rec.atvpdur_desc ||
	 CRLF || 
	 ' Frequency:   ' || atvfreq_rec.atvfreq_desc ||
	 CRLF || 
	 ' Start Date:  ' || bill_date2 ||
	 CRLF || 
	 CRLF || 						                     
	 'Your pledge is being processed.' ||
	CRLF || 			
	'In the meantime, should you wish to amend this transaction, please contact us ' ||
	 CRLF || 	
	 CRLF || 				                     					                     
	 'Thank you for your support.' ||
	 CRLF || 
	 CRLF || 
	 CRLF || 
	 CRLF || 
	 '*** This is an automated message system. Please do not respond to this e-mail. *** ',
        p_err_message1);



Now when I compile it, I am getting bogged down with an error message called: PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared

Where is it I am going wrong? When I googled up, it talked about either the variable is not defined(which is not the case) or about privileges (which is not the case as I compiled the same procedure with fewer parameters last week in my schema). Any idea?

I am attaching a screenshot as well.
/forum/fa/12345/0/


[mod-edit: image inserted into message body by bb]

[Updated on: Tue, 02 December 2014 12:03] by Moderator

Report message to a moderator

Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629036 is a reply to message #629035] Tue, 02 December 2014 11:58 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
so where explicitly is P_ERR_MESSAGE1 declared?
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629037 is a reply to message #629035] Tue, 02 December 2014 12:00 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
You are leaving out way too much.
Show use the actual code for the call to the procedure, not just one line.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629038 is a reply to message #629036] Tue, 02 December 2014 12:00 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
It is declared explicitly in forward declaration (p_sendmail procedure) and also in the procedure header (p_sendmail) as an OUT parameter.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629039 is a reply to message #629038] Tue, 02 December 2014 12:01 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
The actual code for procedure call is mentioned under "--The calling procedure below:"
The variable is called at the bottom/as last argument. Please let me know if you haven't been able to find it.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629040 is a reply to message #629038] Tue, 02 December 2014 12:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
buggleboy007 wrote on Tue, 02 December 2014 10:00
It is declared explicitly in forward declaration (p_sendmail procedure) and also in the procedure header (p_sendmail) as an OUT parameter.


WRONG!

DECLARE

P_ERR_MESSAGE1 VARCHAR2(4000);
BEGIN


above is how a variable is declared!
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629041 is a reply to message #629040] Tue, 02 December 2014 12:04 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I will incorporate and come back to you. I thought by passing it as a parameter in a local procedure,it is as good as declared. Please correct me if I am wrong.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629042 is a reply to message #629041] Tue, 02 December 2014 12:05 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Please correct me if I am wrong.

You are wrong as indicated by the error message!
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629043 is a reply to message #629042] Tue, 02 December 2014 12:22 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Thanks Blackswan.

I tried incorporating it and after compiling it get a new message called : PLS-00306: wrong number or types of arguments in call to
'P_SENDMAIL'

So I declared only one variable called P_ERR_MESSAGE1 VARCHAR2(100);

and then removed the OUT parameter(also declared with same name) and then compiled it. It compiled successfully. Now that's a job done. Thanks a lot for correcting me.

I will now unit test it. That's another round still left Smile

Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629044 is a reply to message #629043] Tue, 02 December 2014 12:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

do NOT tell us what you do!

SHOW US!
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629045 is a reply to message #629044] Tue, 02 December 2014 12:27 Go to previous messageGo to next message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
I didn't quite understand what you meant BlackSwan. I was just speaking my mind about what happened and sharing it with you. Not sure why you reacted that way above.

Anyways I would treat this issue closed.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629048 is a reply to message #629039] Tue, 02 December 2014 13:34 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
buggleboy007 wrote on Tue, 02 December 2014 13:01
The actual code for procedure call is mentioned under "--The calling procedure below:"


But that again is leaving out too much.
That is not a code that calls procedure at all. It is just shows a single line. Where are the values of all those variables?
Calling a procedure happens between a BEGIN and END.
Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629062 is a reply to message #629045] Tue, 02 December 2014 15:06 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
The following is a simplification of what you are doing and what you should be doing. In the second package body, line 16 is the line that you are missing. It is the declaration of the variable to return the error message into.

-- what you are doing:
SCOTT@orcl12c> CREATE OR REPLACE PACKAGE bwakplns AS
  2  	PROCEDURE p_sendmail(p_err_message1  OUT VARCHAR2);
  3  END bwakplns;
  4  /

Package created.

SCOTT@orcl12c> SHOW ERRORS
No errors.
SCOTT@orcl12c> CREATE OR REPLACE PACKAGE BODY bwakplns AS
  2  	PROCEDURE p_sendmail(p_err_message1   OUT VARCHAR2 ) IS
  3  	BEGIN
  4  	   NULL;
  5  	EXCEPTION
  6  	   WHEN others THEN
  7  	      IF SQLERRM IS NOT NULL THEN
  8  		 p_err_message1:=SQLERRM;
  9  	      ELSE
 10  		 p_err_message1:=NULL;
 11  	      END IF;
 12  	END p_sendmail;
 13  	PROCEDURE callingproc
 14  	IS
 15  	BEGIN
 16  	   p_sendmail(p_err_message1);
 17  	END callingproc;
 18  END bwakplns;
 19  /

Warning: Package Body created with compilation errors.

SCOTT@orcl12c> SHOW ERRORS
Errors for PACKAGE BODY BWAKPLNS:

LINE/COL ERROR
-------- -----------------------------------------------------------------
16/7     PL/SQL: Statement ignored
16/18    PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared


-- what you should be doing:
SCOTT@orcl12c> CREATE OR REPLACE PACKAGE bwakplns AS
  2  	PROCEDURE p_sendmail(p_err_message1  OUT VARCHAR2);
  3  END bwakplns;
  4  /

Package created.

SCOTT@orcl12c> SHOW ERRORS
No errors.
SCOTT@orcl12c> CREATE OR REPLACE PACKAGE BODY bwakplns AS
  2  	PROCEDURE p_sendmail(p_err_message1   OUT VARCHAR2 ) IS
  3  	BEGIN
  4  	   NULL;
  5  	EXCEPTION
  6  	   WHEN others THEN
  7  	      IF SQLERRM IS NOT NULL THEN
  8  		 p_err_message1:=SQLERRM;
  9  	      ELSE
 10  		 p_err_message1:=NULL;
 11  	      END IF;
 12  	END p_sendmail;
 13  	PROCEDURE callingproc
 14  	IS
 15  -- The line below is what you are missing:
 16  	   p_err_message1  VARCHAR2(4000);
 17  	BEGIN
 18  	   p_sendmail(p_err_message1);
 19  	END callingproc;
 20  END bwakplns;
 21  /

Package body created.

SCOTT@orcl12c> SHOW ERRORS
No errors.

Re: Getting bogged down with PLS-00201: identifier 'P_ERR_MESSAGE1' must be declared [message #629064 is a reply to message #629062] Tue, 02 December 2014 19:34 Go to previous message
buggleboy007
Messages: 282
Registered: November 2010
Location: Canada
Senior Member
Thanks Barbara for pointing it out. I had that rectified. Silly me, I thought that by passing the parameters in the procedure the variables (parameters in this case) were as good as declared. I stand corrected and thanks again for correcting it.

Previous Topic: Date function
Next Topic: Failed to execute target procedure ORA-20002: ORA-29279: SMTP permanent error: 550 5.1.1
Goto Forum:
  


Current Time: Wed Apr 24 20:51:17 CDT 2024