1

我的表具有这种结构T_user(usern,pass,realname: varchar(50); 我是 Firebird 的初学者,我想执行以下语句,但出现此错误:

if (select Count(*) as cnt FROM T_USER WHERE ( usern = 'test') And (pass
= ']')) > 0  then  select T_user.realname from t_user where t_user.usern = 'test';

这是错误消息:

错误:IBPP::SQLException 上下文:Statement::Prepare( if (select Count(*) as cnt FROM T_USER WHERE (usern = 'test') And (pass = ']')) > 0 then select T_user.realname from t_user其中 t_user.usern = 'test' ) 消息:isc_dsql_prepare 失败

SQL 消息:-104 无效令牌

引擎代码:335544569 引擎消息:动态 SQL 错误 SQL 错误代码 = -104 令牌未知 - 第 1 行,第 1 列如果

我正在使用 Firebird 2.5 和 FlameRobin。

4

2 回答 2

3

试试这个代码:

EXECUTE BLOCK
  RETURNS (name VARCHAR(50))
AS
  DECLARE VARIABLE C INTEGER;
BEGIN
  select Count(*) 
  FROM T_USER 
  WHERE  usern = 'test' And pass = ']'
  INTO :C;

  IF (:C > 0) THEN
    select T_user.realname 
    from t_user 
    where t_user.usern = 'test'
    into :name;
  ELSE
    name = NULL;

  SUSPEND;
END
于 2012-10-17T14:30:59.297 回答
-1
IF ((SELECT COUNT(*) AS CNT
    FROM T_USER
    WHERE (USERN = 'test')
          AND (PASS = ']')) > 0) THEN
  SELECT T_USER.REALNAME
  FROM T_USER
  WHERE T_USER.USERN = 'test';
于 2012-10-17T15:04:45.143 回答