かなり標準的な SQL 構文を使用していると思われる SQLAnywhere を使用して SQL を学習しています
私の問題は、ID が char(4) NOT NULL、スコアが 10 進数、ピンが 10 進数のテーブル MatchRecord を作成したことです。
これまでに得たテーブルに値を挿入するプロシージャ insert_scores を作成したいと思います。
create procedure insert_scores(IN play_id char(4), IN play_score decimal(5, 2),
IN no_pins decimal(5, 2), OUT a_message varchar(40))
begin
if substr(play_id, 1, 1)in (Upper('M','F', 'J'
then
if isnumeric(substr(play_id 2, 3)) = 1
then
if isnumeric(play_score) = 1
then
if isnumeric(no_pins) = 1
then
insert into MatchRecord(id, score, pins)
values(play_id, play_score, no_pins);
set a_message = 'Entry successful';
else
set a_message = 'Number of pins must be decimal ie, 1.6 ';
end if;
else
set a_message = 'Score must be decimal ie, 9.4 ';
end if;
else
set a_message = 'ID number must be in range 000 to 999 ';
end if;
else
set a_message = 'First character of ID must be M, F of J':
end if;
終わり
これは、いずれかの 10 進数値に誤って文字が挿入された場合を除いて正常に機能し、システムがエラーをスローすると、if ステートメントを読み取る前にテーブルの種類をチェックするようです。私は isnumeric(string(play_score)) = を試しました1 でも同じエラーです。
最初の if ステートメントの前に、play_score と no_pins で渡された数値が 10 進数であることを確認する方法はありますか?