【问题标题】:PLSQL syntax error near ";"";" 附近的 PLSQL 语法错误
【发布时间】:2018-01-17 08:01:18
【问题描述】:

我正在尝试对 liquibase 更新运行查询,并且其中有一个 PLSQL 块,该块有超过 500 行,所以我现在只发布发生错误的几行。

      BEGIN     
            IF NOT EXISTS(select 1 from "public"."eod_report" where "id" = NEW."id") THEN
            -- LOADING STRUCTURE  SECTION
            select "id" into NEW.organization_unit_id from organization_unit where site_id = NEW.organization_unit_id;
                orgUnitId := CAST(NEW.organization_unit_id as int8);
                --INSERT
                IF (NEW.transactions_count is NULL) THEN
                NEW.transactions_count := 0;
                END IF;
                IF (NEW.total_sales is NULL) THEN
                NEW.total_sales := 0; 
                END IF;
            INSERT INTO "public"."eod_report"("id",batch,total_sales,transactions_count,organization_unit_id,pos_total_sales,pos_transactions_count,pos_total_points,total_points,transaction_date) 
            VALUES (NEW."id",NEW.batch,NEW.total_sales,NEW.transactions_count,orgUnitId,NEW.pos_total_sales,NEW.pos_transactions_count,NEW.pos_total_points,NEW.total_points,NEW.transaction_date);  
            -- updates delay transaction or each batch
                select max(id) into lastEodId from "public"."transaction"  where transaction_type = 4 and org_unit_id = orgUnitId and id &lt ;NEW."id"; 
            for eodRow IN       
            select count(case when transaction_type = 3 then -1 else 1 end) as trCount,sum(case when report_prefix = true then points else -points end) as ptSum,sum(case when report_prefix = true then amount else -amount end) as trSum, batch as trBatch from "public"."transaction"
              where id &gt ;lastEodId and id &lt ;NEW."id" and report_prefix is not null and org_unit_id = orgUnitId
              and batch &lt ;NEW.batch group by batch

            LOOP 
              UPDATE "public"."eod_report" SET delayed_points = 
          (delayed_points + eodRow.ptSum),former_delayed_sales =  
            END LOOP;
            END IF;


            RETURN NULL;

当我尝试执行查询时出现此错误:

错误:

“;”处或附近的语法错误
LINE 453: ..._type = 4 and org_unit_id = orgUnitId and id &lt ;NEW."id"; ^ SQL 状态:42601
字符:15018

there is a screenshot where the error is highlighted

【问题讨论】:

    标签: sql plsql syntax syntax-error


    【解决方案1】:

    看起来 <> 字符已替换为 &lt ;,因此语法不正确。

    通过将所有&lt ; 替换为< 来修复SQL

    ... org_unit_id = orgUnitId and id < NEW."id";
    

    还必须将&amp;gt ; 替换为&gt;

    它可能会发生,例如因为从 UI(浏览器)发送的文本的 URL 编码

    【讨论】:

    • 我很惊讶它可以工作,因为 PL/SQL 没有 "IF NOT EXISTS(select" 构造,尽管人们通常认为它应该这样做。
    【解决方案2】:

    您会在查询的多个部分发现相同的问题,因为 HTML 实体如“&lt ;”和“>”在错误指向的 SQL 查询中是不合法的。您应该将它们相应地更改为“”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-22
      • 2017-08-31
      • 2023-03-03
      • 2016-02-16
      • 2018-08-21
      • 2017-01-12
      • 2014-03-12
      • 1970-01-01
      相关资源
      最近更新 更多