我的表格有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(如果 (选择Count(*)作为cnt FROM T_USER WHERE(usern =' test')和(通过 =']'))> 0然后从t_user中选择T_user.realname,其中t_user.usern =' test' )消息:isc_dsql_prepare失败
SQL消息:-104无效令牌
引擎代码:335544569引擎消息:动态SQL错误SQL 错误代码= -104令牌未知 - 第1行,第1列,如果
我使用的是Firebird 2.5和FlameRobin。
答案 0 :(得分: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
答案 1 :(得分:0)
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';