Firebird 中的令牌未知

Token unknown in Firebird

此查询在 firebird 上引发错误,如何解决该错误?

  SELECT EMPNO,SAL 
         FROM EMP E 
         where EMPNO = (SELECT MAX(DEPTNO) FROM DEPT D WHERE E.ENAME NOT like (SELECT TOP 1 ENAME 
                                                                              FROM emp E1 
                                                                              WHERE E1.EMPNO=D.DEPTNO))
         OR 1 = (SELECT MAX(DEPTNO)
                 FROM DEPT D 
                 WHERE E.ENAME like substring('NAME111',1,5))  ORDER BY EMPNO;

这里是错误。

The following error information describes the failure

ODBC Call = SQLPrepareW()

SQL State = HY000

Native error = -104(FFFFFF98)

Error Message = [ODBC Firebird Driver][Firebird]Dynamic SQL Error

SQL error code = -104

Token unknown - line 1, column 111

(编辑以包括来自评论的替代的、更现代的语法)

而不是 SELECT TOP 1 ENAME,使用以下任何一项:

  • SELECT ENAME ... FETCH FIRST ROW ONLY(SQL:2008,火鸟 3+)
  • SELECT ENAME ... ROWS 1(非标准,Firebird 2+)
  • SELECT FIRST 1 ENAME ...(非标准,实际上是 Firebird 1.5+)

另外,使用

substring('NAME111' from 1 for 5)

而不是

substring('NAME111',1,5)

例如,使用 FIRST 1:

SELECT EMPNO,SAL
  FROM EMP E
  WHERE EMPNO = (SELECT MAX(DEPTNO)
                        FROM DEPT D
                        WHERE E.ENAME NOT LIKE (SELECT FIRST 1 ENAME
                                                  FROM emp E1
                                                  WHERE E1.EMPNO=D.DEPTN O))
        OR 1 = (SELECT MAX(DEPTNO)
                  FROM DEPT D
                  WHERE E.ENAME LIKE substring('NAME111 ' from 1 for 5))
  ORDER BY EMPNO;