本文介绍了校验和验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

CHECK是不够的。哪个是DB2中最好的方法呢?


Ewa。

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?

Ewa.

推荐答案



如果验证涉及其他表,则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




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




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


这篇关于校验和验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:10