所以我有以下代码,我只是在执行insert语句之前尝试检查输入,我知道charat在这里是优先的但如果可能我想使用substr方法,如果失败则返回错误消息。我不知道我是否需要out错误消息或者有更简单的方法来执行此操作。我认为它只是我的if语句的语法错误。有人能指出我正确的方向吗?感谢
CREATE PROCEDURE add_test (IN teacherid varchar, IN name varchar, IN startdate, OUT
errorMsg varchar)
BEGIN
if (SUBSTR(teacherid ,1,1) = 'm')
and(cast(SUBSTR(teacherid ,2,2) as smallint) between 0 and 50)
BEGIN
INSERT INTO test (teacherid , name , startdate) VALUES (teacherid , name , startdate);
END
答案 0 :(得分:0)
这样你就必须选择错误信息....
CREATE PROCEDURE add_test (IN @teacherid varchar, IN @name varchar, IN @startdate datetime, OUT @errorMsg varchar)
As
BEGIN
if ((SUBSTR(teacherid ,1,1) = 'm')
and(cast(SUBSTR(teacherid ,2,2) as smallint) between 0 and 50))
BEGIN
INSERT INTO test (teacherid , name , startdate) VALUES (teacherid , name , startdate);
END
Else
BEGIN
Set @errorMsg='Error Msg Not inserted record'
Select @errorMsg
END
END