PervasiveSQL - Inserting/Updating 内部记录和 If Else 语句
PervasiveSQL - Inserting/Updating record inside and If Else statement
你好。我正在尝试创建一个基本函数来检查符合特定条件的记录数。如果有 none 然后它执行插入和 returns returns 0,否则它更新现有记录和 returns 1。我在该位置遇到语法错误Insert 和 Update 语句。这是我的 SQL 脚本(仅供参考,我是 pervasive 的新手,如果有人有更好的方法来执行 update/insert 那么我就是 ears/eyes):
CREATE FUNCTION "InsertUpdateWebData"(:KeyType CHAR(1), :KeyValue CHAR(50),
:WebData CHAR(100), :WhiteSpace LONGVARCHAR, :Spare CHAR(97)) RETURNS INTEGER
AS
BEGIN
DECLARE :RecordCount INTEGER;
SET :RecordCount = (SELECT COUNT(*) FROM SYS_WebData WHERE WBD_KeyType
= :KeyType and WBD_KeyValue = :KeyValue);
IF :RecordCount = 0 THEN
BEGIN
INSERT INTO SYS_WebData(WBD_KeyType, WBD_KeyValue, WBD_Data,
WBD_WhiteSpace, WBD_Spare) VALUES (:KeyType, :KeyValue, :WebData,
:WhiteSpace, :Spare);
RETURN 0;
END
ELSE
BEGIN
UPDATE SYS_WebData SET WBD_Data = :WebData, WBD_WhiteSpace = :WhiteSpace,
WBD_Spare = :Spare WHERE WBD_KeyType = :KeyType AND WBD_KeyValue =
:KeyValue;
RETURN 1;
END
END IF
END
执行此操作的正确语法是什么?
来自无孔不入documentation:
Restrictions
You cannot use the CREATE DATABASE or the DROP DATABASE statement in a
user-defined function. The table actions CREATE, ALTER, UPDATE,
DELETE, and INSERT are not permitted within a user-defined function.
您应该 能够将它从 CREATE FUNCTION
更改为 CREATE PROCEDURE
并让它工作。我这样做了,它创建了程序。
你好。我正在尝试创建一个基本函数来检查符合特定条件的记录数。如果有 none 然后它执行插入和 returns returns 0,否则它更新现有记录和 returns 1。我在该位置遇到语法错误Insert 和 Update 语句。这是我的 SQL 脚本(仅供参考,我是 pervasive 的新手,如果有人有更好的方法来执行 update/insert 那么我就是 ears/eyes):
CREATE FUNCTION "InsertUpdateWebData"(:KeyType CHAR(1), :KeyValue CHAR(50),
:WebData CHAR(100), :WhiteSpace LONGVARCHAR, :Spare CHAR(97)) RETURNS INTEGER
AS
BEGIN
DECLARE :RecordCount INTEGER;
SET :RecordCount = (SELECT COUNT(*) FROM SYS_WebData WHERE WBD_KeyType
= :KeyType and WBD_KeyValue = :KeyValue);
IF :RecordCount = 0 THEN
BEGIN
INSERT INTO SYS_WebData(WBD_KeyType, WBD_KeyValue, WBD_Data,
WBD_WhiteSpace, WBD_Spare) VALUES (:KeyType, :KeyValue, :WebData,
:WhiteSpace, :Spare);
RETURN 0;
END
ELSE
BEGIN
UPDATE SYS_WebData SET WBD_Data = :WebData, WBD_WhiteSpace = :WhiteSpace,
WBD_Spare = :Spare WHERE WBD_KeyType = :KeyType AND WBD_KeyValue =
:KeyValue;
RETURN 1;
END
END IF
END
执行此操作的正确语法是什么?
来自无孔不入documentation:
Restrictions
You cannot use the CREATE DATABASE or the DROP DATABASE statement in a user-defined function. The table actions CREATE, ALTER, UPDATE, DELETE, and INSERT are not permitted within a user-defined function.
您应该 能够将它从 CREATE FUNCTION
更改为 CREATE PROCEDURE
并让它工作。我这样做了,它创建了程序。