MYSQL でストアド プロシージャを作成しました。ストアド プロシージャに 6 つの入力を渡しています。列名がfinewt_1、finewt_2、finewt_3 ....finewt_260の260個の列があります。
私のストアドプロシージャは次のとおりです。
Create procedure GetImg($r35 double,
r36 double,
$r37 double,
r38 double,
$r39 double,
r40 double)
begin
select img_id,img_path,
((pow((r36-finewt_$r35),2))+(pow((r38-finewt_$r37),2))+(pow((r40-finewt_$r39),2))) as distance from tbl_fine
end
このストアド プロシージャを php から呼び出そうとすると、finewt_$r35 が見つからないというエラーが表示されます。$r35=50 と仮定すると (r36-finewt_50) となるように計算したいと思います。これどうやってするの?これは、30,000以上の画像に対してこれを行う必要があるSQLステートメントのほんの一部であるため、別のselectステートメントを使用したくありません。どうすればこの問題を解決できますか?
動的SQLを使用してみましたが、エラーメッセージが表示されます:
Unknown column 'finewt_13' in 'field list'
私の動的SQLは次のとおりです。
Create procedure GetImg($r35 double,
r36 double,
$r37 double,
r38 double,
$r39 double,
r40 double)
begin
Set @s=CONCAT('select img_id,img_path,
((pow((r36-',finewt_$r35,'),2))+(pow((r38-',finewt_$r37,'),2))+(pow((r40-finewt_$r39),2))) as distance from tbl_fine');
PREPARE stmt FROM @s;
EXECUTE stmt;
end
これを試すと:
CONCAT(......(pow((r36-finewt_',$r35,'),2))+(pow((r38-finewt_',$r37,')),2)+(pow((r40-finewt_',$r39,'),2)).....
エラーが発生します:
Incorrect parameter count in the call to native function 'pow'