0

在 Informix 数据库上运行以下查询时,数据库报告一般语法错误(没有任何关于导致问题的指示)。相同的查询可以在 CUBRID 或 Oracle 数据库上完美运行,它们都支持以下CONNECT BY语法:

select 
  lower(connect_by_root "t_directory"."name"), 
  connect_by_isleaf, 
  connect_by_iscycle, 
  substr(
    sys_connect_by_path(lower("t_directory"."name"), '/'), 
    2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc

我使用的数据库是 Windows 上的 Informix 12.10 开发人员版。我正在使用以下连接 URL 从 JDBC 驱动程序运行查询(以允许引用表标识符):

jdbc:informix-sqli://localhost:9092/test:INFORMIXSERVER=ol_informix;DELIMIDENT=y
4

1 回答 1

0

这里的确切问题是prior不接受带引号的表标识符,尽管带引号的列标识符似乎没问题。此查询运行良好:

select 
  lower(connect_by_root "t_directory"."name"), 
  connect_by_isleaf, 
  connect_by_iscycle, 
  substr(
    sys_connect_by_path(lower("t_directory"."name"), '/'), 
    2) "dir"
from "t_directory"
start with "t_directory"."parent_id" is null
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
order siblings by lower("t_directory"."name") asc

...不同之处在于:

-- Bad:
connect by nocycle prior "t_directory"."id" = "t_directory"."parent_id"

-- Good:
connect by nocycle prior t_directory."id" = "t_directory"."parent_id"
于 2014-07-30T12:07:39.793 回答