忽略PL/SQL SQL * Plus语句 [英] PL/SQL SQL*Plus Statement Ignored

查看:148
本文介绍了忽略PL/SQL SQL * Plus语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Oracle数据库上执行触发器,这是代码

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;

编译时出现以下错误:

错误(4,3):PL/SQL:语句被忽略 错误(4,6):PLS-00382:表达式的类型错误

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

问题似乎出在group_ids变量的类型上,我一直在尝试解决此PLS-00382问题,但不能.

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.

"TELEGRAM_BOT()"行是一个过程调用,它调用Java发布的方法:

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)';

推荐答案

问题与触发器无关.您仅在下面一行中就有语法错误:

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语句和逻辑运算符期望一个布尔表达式. PL/SQL没有将隐式数据类型转换为布尔值.

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

这意味着:NEW.EVENT_ID不是有效的布尔表达式,因此它不能与and -operator一起使用,因此编译失败并显示:

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;
/

这篇关于忽略PL/SQL SQL * Plus语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆