在存储过程中添加异常

时间:2018-07-17 16:07:25

标签: oracle stored-procedures exception-handling

我想用oracle处理异常,因为我以前没有做过。下面是我的存储过程。

create or replace
 PROCEDURE GET_VALID_LATLONG
 (
    P_XYCORDINATE IN VARCHAR2,
   P_SAPID IN VARCHAR2,  
   OUTR4GSTATENAME OUT SYS_REFCURSOR  
  )  
  AS
 v_counter number:=0;
 BEGIN
  DBMS_OUTPUT.ENABLE;

   OPEN OUTR4GSTATENAME FOR 
 SELECT DISTINCT(R4GSTATECODE),R4GSTATENAME 
                  FROM R4G_LB.R4GSTATEBOUNDARY_EVW 
                  WHERE SDE.ST_INTERSECTS(SDE.ST_GEOMETRY('POINT 
('||P_XYCORDINATE||')', 3),SHAPE) = 1;   

 END GET_VALID_LATLONG;

如何处理异常?

更新

我这样添加,发生错误时可以吗??

     create or replace
 PROCEDURE GET_VALID_LATLONG
 (
  P_XYCORDINATE IN VARCHAR2,
 P_SAPID IN VARCHAR2,  
OUTR4GSTATENAME OUT SYS_REFCURSOR  
 )  
 AS
   v_counter number:=0;
BEGIN
DBMS_OUTPUT.ENABLE;

    OPEN OUTR4GSTATENAME FOR 
   SELECT DISTINCT(R4GSTATECODE),R4GSTATENAME 
                   FROM R4G_LB.R4GSTATEBOUNDARY_EVW 
                   WHERE SDE.ST_INTERSECTS(SDE.ST_GEOMETRY('POINT 
   ('||P_XYCORDINATE||')', 3),SHAPE) = 1;   

EXCEPTION

   WHEN OTHERS THEN
      NULL;                      

END GET_VALID_LATLONG;

1 个答案:

答案 0 :(得分:0)

例如,可以在Oracle文档中找到预定义的例外列表。

https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm

您可以在例外子句中使用此例外名称列表,例如

SUCCESS