在Firebird存储过程中选择标量值

时间:2010-02-15 15:44:37

标签: sql select firebird

我想从Firebird 2.1存储过程中获取特定行的ID。我似乎无法记住语法,这让我疯狂。

这是Microsoft SQL Server使用的TSQL代码的外观。

    @ID = SELECT ID FROM ADDRESS WHERE 
      POBox = :POBOX AND
      ExtendedAddress = :EXTENDEDADDRESS AND
      StreetAddress = :STREETADDRESS AND
      Locality = :LOCALITY AND
      Region = :REGION AND
      PostalCode = :POSTALCODE AND
      CountryName = :COUNTRYNAME;

Firebird的等价物是什么?

更新Firebird SQL migration guide表明这应该有效

    SELECT ID INTO :ID FROM ADDRESS WHERE 
      POBox = :POBOX AND
      ExtendedAddress = :EXTENDEDADDRESS AND
      StreetAddress = :STREETADDRESS AND
      Locality = :LOCALITY AND
      Region = :REGION AND
      PostalCode = :POSTALCODE AND
      CountryName = :COUNTRYNAME;

但是当我尝试创建存储过程时,我在“INTO”中收到语法错误。

1 个答案:

答案 0 :(得分:4)

显然,Firebird迁移指南是错误的。这种语法对我有用:

SELECT ID FROM ADDRESS WHERE 
   POBox = :POBOX AND
   ExtendedAddress = :EXTENDEDADDRESS AND
   StreetAddress = :STREETADDRESS AND
   Locality = :LOCALITY AND
   Region = :REGION AND
   PostalCode = :POSTALCODE AND
   CountryName = :COUNTRYNAME
INTO :ID;

请注意,INTO子句必须在 FROMWHERE子句之后