gpt4 book ai didi

postgresql - 错误 : unterminated dollar-quoted string at or near "$BODY$

转载 作者:行者123 更新时间:2023-11-29 12:10:38 27 4
gpt4 key购买 nike

我正在使用 sql fiddle ...PostgreSQL 9.3:

CREATE TABLE HotelStays
(roomNum INTEGER NOT NULL,
arrDate DATE NOT NULL,
depDate DATE NOT NULL,
guestName CHAR(30) NOT NULL,
PRIMARY KEY (roomNum, arrDate))
;


CREATE OR REPLACE FUNCTION new_customer() RETURNS void AS
$BODY$
DECLARE
depatureDate DATE;\
BEGIN
SELECT depDate INTO depatureDate FROM HotelStays WHERE OLD.roomNum = NEW.roomNum;
IF (depatureDate <= NEW,arrDate)
INSERT INTO HotelStays (roomNum, arrDate, depDate, guestName)
VALUES (:NEW.roomNum, :NEW.arrDate, :NEW.depDate, :NEW.guestName);
END IF;
RETURN;
END
$BODY$
LANGUAGE 'plpgsql' ;
CREATE TRIGGER;

INSERT INTO HotelStays(roomNum, arrDate, depDate, guestName)
VALUES
(123, to_date('20160202', 'YYYYMMDD'), to_date('20160206','YYYYMMDD'), 'A');

我正在尝试解决的问题:即使在现有客人退房之前,也可以为房间号输入一个新条目(针对新客人)。我正在尝试使用触发器来解决这个问题。请帮帮我。提前致谢。

最佳答案

正如作者所提到的,他使用了 SQL Fiddle。我在 db-fiddle.com 上遇到了同样的问题,并通过将 $$$BODY$ 替换为单引号 ' (并加倍中间其他地方的单引号。

例如,db-fiddle

CREATE OR REPLACE FUNCTION update_datem()
RETURNS trigger AS
'
BEGIN
NEW.dateM = DATE_TRUNC(''MONTH'', NEW.date);
RETURN NEW;
END;
'
LANGUAGE plpgsql;

关于postgresql - 错误 : unterminated dollar-quoted string at or near "$BODY$,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37516386/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com