PL/SQL SQL*Plus Statement Ignored

北战南征 提交于 2020-01-06 14:43:06

问题


I'm doing a trigger on my Oracle database, here's the code

CREATE OR REPLACE TRIGGER send_telegram_message
AFTER INSERT ON EVENT_LOG
FOR EACH ROW
DECLARE 
  GROUP_IDS VARCHAR(200);
BEGIN
  IF :NEW.EVENT_ID AND :NEW.DESCRIPTION IS NOT NULL THEN

    SELECT ID_GRUPO INTO GROUP_IDS
    FROM V_EVENT_TELEGRAM 
    WHERE V_EVENT_TELEGRAM.EVENT_ID = :NEW.EVENT_ID;

    TELEGRAM_BOT(GROUP_IDS,:NEW.DESCRIPTION);
  END IF;
END;

When compile I'm getting the following error:

Error(4,3): PL/SQL: Statement ignored Error(4,6): PLS-00382: expression is of wrong type

The problem seems to be with the type of group_ids variable, I've been trying to solve this PLS-00382 issue but I can't.

The "TELEGRAM_BOT()" line is a procedure call that invokes a Java published method:

create or replace PROCEDURE telegram_bot (group_ids VARCHAR2, message VARCHAR2)
AS LANGUAGE JAVA 
NAME 'TelegramBot.subMain(String,String)';

回答1:


The question has nothing to do with the triggers. You simply have a syntax error in the following line:

IF :NEW.EVENT_ID AND :NEW.DESCRIPTION IS NOT NULL THEN

if statement and logical operators expect a boolean expression. PL/SQL doesn't have implicit data type conversions to boolean values.

This means :NEW.EVENT_ID is not a valid boolean expression so it can't be used with and-operator and therefore the compilation fails with:

PLS-00382: expression is of wrong type

Essentially your problem can be narrowed down to the following example:

declare
  v_foo number;
begin
  -- compilation fails because a number (or any other non-boolean
  -- data type) is not a boolean expression.
  if v_foo
  then
    null;
  end if;
end;
/

Working examples (compiles fine):

declare
  v_foo number;
  function to_boolean(p_x in number) return boolean is
  begin
    return p_x > 0;
  end;
begin
  -- a function returns a boolean value
  if to_boolean(v_foo)
  then
    null;
  end if;

  -- a > operator returns a boolean value
  if v_foo > 0
  then
    null;
  end if;

  -- is null operator returns a boolean value
  if v_foo is null
  then
    null;
  end if;
end;
/



回答2:


Try this.

CREATE OR REPLACE TRIGGER send_telegram_message
AFTER INSERT ON EVENT_LOG
FOR EACH ROW
DECLARE 
  GROUP_IDS VARCHAR(200);
BEGIN
  IF :NEW.EVENT_ID IS NOT  NULL AND :NEW.DESCRIPTION IS NOT NULL THEN

    SELECT ID_GRUPO INTO GROUP_IDS
    FROM V_EVENT_TELEGRAM 
    WHERE V_EVENT_TELEGRAM.EVENT_ID = :NEW.EVENT_ID;

    TELEGRAM_BOT(GROUP_IDS,:NEW.DESCRIPTION);
  END IF;
END;


来源:https://stackoverflow.com/questions/36330346/pl-sql-sqlplus-statement-ignored

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!