更新を含む手順を作成しました。との 2 つの変数がotherCategoryId
ありotherCategoryId
ます。
コマンドラインで手順を実行しようとすると、次のようなエラーが表示されます。
SQL 構文にエラーがあります。near 'update... を使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。
更新ステートメントは次のようになります。
abstract_type set parent_fk = otherCategoryId where id = otherCategoryId;
更新:私のプロシージャのソース コードは次のとおりです。
CREATE PROCEDURE fixCommodityIPRTypes(IN typeClass VARCHAR(255), IN commodityClass VARCHAR(255),IN parrentFk VARCHAR(255))
BEGIN
DECLARE otherCategoryId BIGINT;
DECLARE wrongNoOfAccesses INT;
DECLARE wrongTypeId INT;
DECLARE loop_count INT DEFAULT 1;
DECLARE num_rows INT;
DECLARE nameOfType VARCHAR(1255);
select otherCategoryId = pt.id from abstract_type pt where pt.class = typeClass and pt.name = 'Other' and pt.normalized = 1 and pt.normalize_link_fk is null;
-- declare cursor for all other - specify types with parent fk specified
block_cursor: BEGIN
DECLARE changeOSTypesCursor CURSOR FOR SELECT x.id, x.name, x.no_of_accesses from abstract_type as x where class = typeClass and normalized = 0 and parent_fk = parrentFk;
open changeOSTypesCursor;
select FOUND_ROWS() into num_rows;
update_loop:LOOP
fetch changeOSTypesCursor into wrongTypeId, nameOfType, wrongNoOfAccesses;
-- for each distinct other-specify and parent the category called
inside_loop: BEGIN
DECLARE nrOfAccess BIGINT;
DECLARE otherId BIGINT;
select NO_OF_ACCESSES , Id from abstract_type where class = typeClass and normalized = 0 and parent_fk = otherCategoryId and name = nameOfType into nrOfAccess, otherId ;
-- if there are no types with the same text as the current os type with parent category 'OTHER'
-- then we just change the parent to be the category 'OTHER'
if nrOfAccess =0
update abstract_type set parent_fk = otherCategoryId where id = wrongTypeId;
-- else we must set the no_of_accesses for the type with parent 'OTHER' =
-- current no_of_acceses + accesses from the type with specified parent,
-- replace the foreign_key in commodities with the type with parent_other and
-- delete
else if nrOfAccess > 0 then
begin
update abstract_type set no_of_accesses = wrongNoOfAccesses + nrOfAccess where id = otherId;
update commodity set goods_type_fk = otherId where class = commodityClass and goods_type_fk = wrongTypeId;
delete from abstract_type where id = wrongTypeId;
end
if num_rows <= loop_count then
leave update_loop;
end if
end inside_loop;
end LOOP;
close changeOSTypesCursor;
END block_cursor;
-- update trademarks with parent specified and delete the category of level 1
update type_xref set ref_parents_fk = otherCategoryId where ref_parents_fk = parrentFk;
delete from abstract_type where id = parrentFk;
END ##