1

I can't see my error. I marked the places SQL Developer is citing errors. Can you see where I am going wrong? ZCTA5_2000 is a valid table with data.

CREATE OR REPLACE TRIGGER zip_trigger
  BEFORE INSERT ON ZCTA5_2000
  FOR EACH ROW
DECLARE
  low_zip NUMBER(5);
  high_zip NUMBER(5);  <---  Error PL/SQL: SQL Statement ignored  ******
BEGIN  <-----Error PL/SQL: ORA-00933: SQL command not properly ended ********

  SELECT LOW_ZIP, HIGH_ZIP FROM ZIPTABLE
  INTO low_zip, high_zip
  WHERE :NEW.STATE = STATE_CODE;  <--- Error PLS-00103: Encountered the symbol "END"... 
    IF :NEW.ZIP < LOW_ZIP OR :NEW.ZIP>HIGH_ZIP
    END IF;
END;
4

3 回答 3

1

似乎向您报告的行号不正确。一些前端会这样做。

请注意,PLS-00103: Encountered the symbol "END"消息太快了三行。假设ORA-00933消息相同意味着它确实指向该SELECT语句,并且果然这就是您的错误所在:

SELECT LOW_ZIP, HIGH_ZIP FROM ZIPTABLE
INTO low_zip, high_zip    <== INTO should be before FROM
...

INTO必须在之后SELECT之前FROM尝试将其更改为:

SELECT LOW_ZIP, HIGH_ZIP INTO low_zip, high_zip
FROM ZIPTABLE
...
于 2013-05-21T19:30:14.277 回答
1

错误可能不止一个:

CREATE OR REPLACE TRIGGER zip_trigger
  BEFORE INSERT ON ZCTA5_2000
  FOR EACH ROW
DECLARE
  low_zip NUMBER(5);
  high_zip NUMBER(5);
BEGIN

  SELECT LOW_ZIP, HIGH_ZIP INTO low_zip, high_zip
  FROM ZIPTABLE
  WHERE :NEW.STATE = STATE_CODE;

  IF :NEW.ZIP < LOW_ZIP OR :NEW.ZIP > HIGH_ZIP THEN
    NULL;
  END IF;
END;
/

请注意重新排列的SELECT语句(SELECT...INTO...FROM而不是SELECT...FROM...INTO)和固定IF语句(块THEN内的关键字和虚拟语句IF)。

于 2013-05-21T19:31:05.920 回答
0

FROM出现在 the 之后INTO并且 aTHEN是强制性的,IF然后你也应该在 theIF为真时做一些事情。

CREATE OR REPLACE TRIGGER zip_trigger
  BEFORE INSERT ON ZCTA5_2000
  FOR EACH ROW
DECLARE
  low_zip NUMBER(5);
  high_zip NUMBER(5);  
BEGIN  
  SELECT LOW_ZIP, HIGH_ZIP
  INTO low_zip, high_zip
   FROM ZIPTABLE
  WHERE :NEW.STATE = STATE_CODE;  
    IF :NEW.ZIP < LOW_ZIP OR :NEW.ZIP > HIGH_ZIP THEN
       null;
    END IF;
END;
于 2013-05-21T19:46:13.093 回答