开发者

In Firebird, how to return the ids of the deleted rows?

I would like to return the ids which have been deleted by a DELETE query.

On Stackoverlow, I found this: How to get ID of the last updated row in MySQL?

The top1 answer has a very nice solution, but it's for mysql. I tried to do the same in Firebird after reading some part of the Firebird manual:

set term ^ ;

EXECUTE BLOCK
AS
    DECLARE VARIABLE uids BLOB SUB_TYPE TEXT;
begin
    DELETE FROM CATEGORY WHERE name = 'Haló'
    AND ( SELECT id INTO :uids );
    SELECT @uids;
end
^

Yes, I know that 'uids' will always contain one ID, since I'm overwriting the variable, but it's only a test, and w开发者_开发知识库hat is more, it doesn't work. It stops at 'INTO' saying "Token unknown - line 8, column 21". I don't know what to do, what to continue with.. :\

Thanks for Your help!


For this, please run separate queries

  1. First fetch the record ids those you want to delete by the same where condition for DELETE

like, SELECT ID FROM CATEGORY WHERE name = 'Haló'

  1. Then delete the records


you could try the "RETURNING" clause, like this:

delete from Scholars
  where firstname = 'Henry' and lastname = 'Higgins'
  returning lastname, fullname, id

look here for more details

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜