Solved

Compliation error on pl/sql trigger

Posted on 2009-04-01
3
2,772 Views
Last Modified: 2013-12-07
I get the following errors.
SQL> show errors;
Errors for TRIGGER RESUMABLE_DEFAULT:

LINE/COL ERROR
-------- -----------------------------------------------------------------
9/22     PLS-00215: String length constraints must be in range (1 ..
         32767)

I am unsure of how to dreate a TYPE for these variables, I think that is the problem?
Thanks in advance.
err_type          VARCHAR2;
   object_owner      VARCHAR2;
   object_type       VARCHAR2;
   table_space_name  VARCHAR2;
   object_name       VARCHAR2;
   sub_object_name   VARCHAR2;
   error_txt         VARCHAR2;
   msg_body          VARCHAR2;


10/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

11/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

12/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

LINE/COL ERROR
-------- -----------------------------------------------------------------

13/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

14/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

15/22    PLS-00215: String length constraints must be in range (1 ..
         32767)

16/22    PLS-00215: String length constraints must be in range (1 ..

LINE/COL ERROR
-------- -----------------------------------------------------------------
         32767)
CREATE OR REPLACE TRIGGER resumable_default
AFTER SUSPEND
ON DATABASE
DECLARE
   /* declare transaction in this trigger is autonomous */
   /* this is not required because transactions within a trigger
      are always autonomous */
   PRAGMA AUTONOMOUS_TRANSACTION;
   cur_sid           NUMBER;
   cur_inst          NUMBER;
   errno             NUMBER;
   err_type          VARCHAR2;
   object_owner      VARCHAR2;
   object_type       VARCHAR2;
   table_space_name  VARCHAR2;
   object_name       VARCHAR2;
   sub_object_name   VARCHAR2;
   error_txt         VARCHAR2;
   msg_body          VARCHAR2;
   ret_value         BOOLEAN;
   mail_conn         UTL_SMTP.CONNECTION;
BEGIN
   -- Get session ID
   SELECT DISTINCT(SID) INTO cur_SID FROM V$MYSTAT;
 
   -- Get instance number
   cur_inst := userenv('instance');
 
   -- Get space error information
   ret_value := 
   DBMS_RESUMABLE.SPACE_ERROR_INFO(err_type,object_type,object_owner,
        table_space_name,object_name, sub_object_name);
   /*
   -- If the error is related to undo segments, log error, send email
   -- to DBA, and abort the statement. Otherwise, set timeout to 8 hours.
   -- 
   -- sys.rbs_error is a table which is to be
   -- created by a DBA manually and defined as
   -- (sql_text VARCHAR2(1000), error_msg VARCHAR2(4000),
   -- suspend_time DATE)
   */
 
   IF OBJECT_TYPE = 'UNDO SEGMENT' THEN
       /* LOG ERROR */
       INSERT INTO sys.rbs_error (
           SELECT SQL_TEXT, ERROR_MSG, SUSPEND_TIME
           FROM DBMS_RESUMABLE
           WHERE SESSION_ID = cur_sid AND INSTANCE_ID = cur_inst
        );
       SELECT ERROR_MSG INTO error_txt FROM DBMS_RESUMABLE 
           WHERE SESSION_ID = cur_sid and INSTANCE_ID = cur_inst;
 
        -- Send email to receipient via UTL_SMTP package
        msg_body:='Subject: Space Error Occurred
 
                   Space limit reached for undo segment ' || object_name || 
                   on ' || TO_CHAR(SYSDATE, 'Month dd, YYYY, HH:MIam') ||
                   '. Error message was ' || error_txt;
 
        mail_conn := UTL_SMTP.OPEN_CONNECTION('localhost', 25);
        UTL_SMTP.HELO(mail_conn, 'localhost');
        UTL_SMTP.MAIL(mail_conn, 'sender@localhost');
        UTL_SMTP.RCPT(mail_conn, 'recipient@localhost');
        UTL_SMTP.DATA(mail_conn, msg_body);
        UTL_SMTP.QUIT(mail_conn);
 
        -- Abort the statement
        DBMS_RESUMABLE.ABORT(cur_sid);
    ELSE
        -- Set timeout to 8 hours
        DBMS_RESUMABLE.SET_TIMEOUT(28800);
    END IF;
 
    /* commit autonomous transaction */
    COMMIT;   
END;
/

Open in new window

0
Comment
Question by:dplinnane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
dmcdconsult earned 500 total points
ID: 24039433
that error usually refers to changing the VARCHAR2  to VARCHAR2(250);  the '250' is an example and could be as the error states (imagine that!) any number between 1 and 32767.



0
 
LVL 1

Expert Comment

by:dmcdconsult
ID: 24039475
For example:
   err_type          VARCHAR2(25);
   object_owner      VARCHAR2(50);
   object_type       VARCHAR2(50);
   table_space_name  VARCHAR2(25); ...
   msg_body          VARCHAR2(2000);

Make sure to choose lengths long enough to fit the actual returned data...
0
 

Author Comment

by:dplinnane
ID: 24040493
This trigger was full of typos and mistakes it was taken directly from oracle documentation.
The _type was leading me to beliee I needed to creat a type variable.


CREATE OR REPLACE TRIGGER resumable_default
AFTER SUSPEND
ON DATABASE
DECLARE
   /* declare transaction in this trigger is autonomous */
   /* this is not required because transactions within a trigger
      are always autonomous */
   PRAGMA AUTONOMOUS_TRANSACTION;
   cur_sid           NUMBER(10);
   cur_inst          NUMBER(10);
   errno             NUMBER(10);
   err_type          VARCHAR2(50);
   object_owner      VARCHAR2(50);
   object_type       VARCHAR2(50);
   table_space_name  VARCHAR2(50);
   object_name       VARCHAR2(50);
   sub_object_name   VARCHAR2(50);
   error_txt         VARCHAR2(50);
   msg_body          VARCHAR2(50);
   ret_value         BOOLEAN;
   mail_conn         UTL_SMTP.CONNECTION;
BEGIN
   -- Get session ID
   SELECT DISTINCT(SID) INTO cur_SID FROM V$MYSTAT;
 
   -- Get instance number
   cur_inst := userenv('instance');
 
   -- Get space error information
   ret_value :=
   DBMS_RESUMABLE.SPACE_ERROR_INFO(err_type,object_type,object_owner,
        table_space_name,object_name, sub_object_name);
   /*
   -- If the error is related to undo segments, log error, send email
   -- to DBA, and abort the statement. Otherwise, set timeout to 8 hours.
   --
   -- sys.rbs_error is a table which is to be
   -- created by a DBA manually and defined as
   -- (sql_text VARCHAR2(1000), error_msg VARCHAR2(4000),
   -- suspend_time DATE)
   */
 
   IF OBJECT_TYPE = 'UNDO SEGMENT' THEN
       /* LOG ERROR */
       INSERT INTO rbs_error (
           SELECT SQL_TEXT, ERROR_MSG, SUSPEND_TIME
           FROM dba_resumable /* typo DBMS_RESUMABLE  */     
           WHERE SESSION_ID = cur_sid AND INSTANCE_ID = cur_inst
        );
       SELECT ERROR_MSG INTO error_txt FROM dba_resumable /* typo DBMS_RESUMABLE  */
           WHERE SESSION_ID = cur_sid and INSTANCE_ID = cur_inst;
 
        -- Send email to receipient via UTL_SMTP package
        msg_body:='Subject: Space Error Occurred
 
                   Space limit reached for undo segment ' || object_name ||
                   ' on ' || TO_CHAR(SYSDATE, 'Month dd, YYYY, HH:MIam') ||
                   '. Error message was ' || error_txt;
 
        mail_conn := UTL_SMTP.OPEN_CONNECTION('exchv2003.ibm.com', 25);
        UTL_SMTP.HELO(mail_conn, 'exchv2003.ibm.com');
        UTL_SMTP.MAIL(mail_conn, 'alerts@ibm.com');
        UTL_SMTP.RCPT(mail_conn, 'tom@ibm.com');
        UTL_SMTP.DATA(mail_conn, msg_body);
        UTL_SMTP.QUIT(mail_conn);
 
        -- Abort the statement
        DBMS_RESUMABLE.ABORT(cur_sid);
    ELSE
        -- Set timeout to 8 hours
        DBMS_RESUMABLE.SET_TIMEOUT(28800);
    END IF;
 
    /* commit autonomous transaction */
    COMMIT;
END;
/

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword 2 98
PL/SQL Two changes 7 41
Input a SQl, output tables amd columns used in the SQL 19 62
Database Design Dilemma 6 66
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question