且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

校验和验证

更新时间:2023-02-06 15:30:46

12月17日,上午9:30,E.Bartosiew ... @ gmail.com写道:
On Dec 17, 9:30 am, E.Bartosiew...@gmail.com wrote:

我需要编写一些验证数据的代码。我有一个校验和,

我需要以相当复杂的方式计算,所以一个简单的

CHECK是不够的。哪个是在DB2中执行此操作的***方法?
I need to write some code that will validate data. I have a checksum,
that I need to calculate in a rather complicated way, so a simple
CHECK is not enough. Which is the best way to do that in DB2?



如果验证涉及其他表,则IMO a触发前是您的***选择




CREATE TRIGGER ...

插入之前没有级联......

参考新的N

FOR EACH ROW

模式DB2SQL

WHEN(< condition)SIGNAL SQLSTATE ....


和一个类似的更新涉及的列。


如果相当复杂意味着复杂但只涉及这个表,我

仍将瞄准检查约束

我的2 skr


/ Lennart

If the validation involves other tables, IMO a before trigger is your
best option:

CREATE TRIGGER ...
NO CASCADE BEFORE INSERT ON ...
REFERENCING NEW AS N
FOR EACH ROW
MODE DB2SQL
WHEN ( <condition) SIGNAL SQLSTATE ....

and a similar one for update of involved columns.

If rather complicated means complicated but concern only this table, I
would still aim for check constraint
My 2 skr

/Lennart


如果相当复杂意味着复杂但只关心这个table,I
If rather complicated means complicated but concern only this table, I

仍然会以支票约束为目标
would still aim for check constraint



是的,我忘了提到它确实只涉及一张桌子。我只是在我把它放在表格之前需要检查数据。你能否给我一些关于如何制定检查约束的提示(或链接到man),

包含循环和对数据的一些操作?我从来没写过

支票比CONSTRAINT更复杂一年检查(年(生日)> =

1986)


Ewa

Yes, I forgot to mention that it does concern only one table. I just
need to check the data before I put it in the table. Could you give me
some hints (or link to man) on how to make a check constraint, that
consists of loops and some operations on the data? I never wrote
checks more complicated than CONSTRAINT year CHECK (YEAR(birthday) >=
1986)

Ewa


E。*** *********@gmail.com 写道:

>如果相当复杂意味着复杂但只关注这张表,我仍然会以检查约束为目标
>If rather complicated means complicated but concern only this table, I
would still aim for check constraint



是的,我忘了提到它确实只涉及一个表。我只是在我把它放在表格之前需要检查数据。你能否给我一些关于如何制定检查约束的提示(或链接到man),

包含循环和对数据的一些操作?我从来没写过

支票比CONSTRAINT更复杂一年CHECK(YEAR(生日)> =

1986)


Yes, I forgot to mention that it does concern only one table. I just
need to check the data before I put it in the table. Could you give me
some hints (or link to man) on how to make a check constraint, that
consists of loops and some operations on the data? I never wrote
checks more complicated than CONSTRAINT year CHECK (YEAR(birthday) >=
1986)



你必须写一个函数。

如果你说C UDF(最终没有被禁止)那么复杂,那就是你要走的路。
如果它只是几个IF和一个循环,只需要做一个SQL UDF。

我的拇指规则是SQL UDF不应该长于一个页面。

(25行)


干杯

Serge

-

Serge Rielau

DB2解决方案开发

IBM多伦多实验室

You have to write a function.
If it''s as complex as you say an C UDF (eventually unfenced) woudl be
the way to go.
If it''s just a couple of IFs and a loop, just do a SQL UDF.
My thumb rule is that SQL UDFs shouldn''t be longer than a page.
(25 lines)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab