调试仅在 PHP/OCI 中出现的 Oracle 错误
我有一个查询,旨在计算总小时数并根据为 Oracle 数据库编写的这些小时数的构成分配一个值。
该查询在 Navicat 和 Toad 中运行良好,但在使用 OCI/PHP 运行查询时出现以下错误:
ORA-00972: 标识符太长
我明白该消息的含义,但我拥有的标识符都不超过 30 个字符。以防万一,我给表名起了别名,这没有什么区别。
我的代码如下:
$query ="SELECT
SUM( ROUND((A.SCHED_DATE_TO - A.SCHED_DATE_FROM)* 24, 1 )),
SUM( CASE WHEN A.ACTION_TYPE_CODE = 'INSV' THEN ROUND((A.SCHED_DATE_TO-A.SCHED_DATE_FROM)* 24, 1)*30 ELSE 42.50 END)
FROM
WAREHOUSE.DM_DIM_ACTION \"A\",
WAREHOUSE.DM_FCT_ACTION \"C\",
WAREHOUSE.DM_DIM_TECHNICIAN \"B\"
WHERE
A.SHUB_ID = C.SHUB_ID
AND C.FK_TECHNICIAN_WID = B.ROW_WID
AND A.SITE_VISIT_YN = 'Y'
AND A.ACTION_TYPE_CODE IN('INSV', 'SURV')
AND A.STATUS_CODE IN('FDSP', 'DISP', 'ASSN')
AND A.ASSIGNED_CONTRACTOR_CODE = 'NOCO'
AND TRUNC( A.SCHED_DATE_FROM )= '20-Sep-11'
AND B.CELL = 'C04'";
$stid = oci_parse($conn, $sql); if (!$stid) { echo oci_error($conn); $e = oci_error($conn); print htmlentities($e['message']); }
$r = oci_execute($stid, OCI_DEFAULT); if (!$r) { $e = oci_error($stid); echo htmlentities($e['message']); }
$planned = oci_fetch_array($stid, OCI_RETURN_NULLS);
我做错了什么,将来是否可以使用任何方法/工具来进一步诊断此类问题?
编辑: 根据评论,我尝试删除较大的字段并简化查询以尝试缩小问题范围。以下查询也提供了相同的错误,其中最大的字段名称被删除。
SELECT
SUM( ROUND((A.SCHED_DATE_TO - A.SCHED_DATE_FROM)* 24, 1 )),
SUM( CASE WHEN A.ACTION_TYPE_CODE = 'INSV' THEN ROUND((A.SCHED_DATE_TO-A.SCHED_DATE_FROM)* 24, 1)*30 ELSE 42.50 END)
FROM
WAREHOUSE.DM_DIM_ACTION "A"
WHERE
AND A.SITE_VISIT_YN = 'Y'
AND TRUNC( A.SCHED_DATE_FROM )= '20-Sep-11'
I have a query that is designed to total hours and assign a value depending on the make up of those hours written for an Oracle database.
The query runs fine in Navicat and Toad, and yet I get the following error when running the query using OCI/PHP:
ORA-00972: identifier is too long
I understand what the message means, but none of the identifiers I have are greater than 30 characters. In case, I aliased the table names and this makes no difference.
My code is as follows:
$query ="SELECT
SUM( ROUND((A.SCHED_DATE_TO - A.SCHED_DATE_FROM)* 24, 1 )),
SUM( CASE WHEN A.ACTION_TYPE_CODE = 'INSV' THEN ROUND((A.SCHED_DATE_TO-A.SCHED_DATE_FROM)* 24, 1)*30 ELSE 42.50 END)
FROM
WAREHOUSE.DM_DIM_ACTION \"A\",
WAREHOUSE.DM_FCT_ACTION \"C\",
WAREHOUSE.DM_DIM_TECHNICIAN \"B\"
WHERE
A.SHUB_ID = C.SHUB_ID
AND C.FK_TECHNICIAN_WID = B.ROW_WID
AND A.SITE_VISIT_YN = 'Y'
AND A.ACTION_TYPE_CODE IN('INSV', 'SURV')
AND A.STATUS_CODE IN('FDSP', 'DISP', 'ASSN')
AND A.ASSIGNED_CONTRACTOR_CODE = 'NOCO'
AND TRUNC( A.SCHED_DATE_FROM )= '20-Sep-11'
AND B.CELL = 'C04'";
$stid = oci_parse($conn, $sql); if (!$stid) { echo oci_error($conn); $e = oci_error($conn); print htmlentities($e['message']); }
$r = oci_execute($stid, OCI_DEFAULT); if (!$r) { $e = oci_error($stid); echo htmlentities($e['message']); }
$planned = oci_fetch_array($stid, OCI_RETURN_NULLS);
What am I doing wrong, and are there any methods/tools that I can use to further diagnose problems like this in future?
EDIT:
As per comments, I tried removing the larger fields and simplifying the query to try and narrow down the issue. The following query also provides the same error, with the largest field name being removed.
SELECT
SUM( ROUND((A.SCHED_DATE_TO - A.SCHED_DATE_FROM)* 24, 1 )),
SUM( CASE WHEN A.ACTION_TYPE_CODE = 'INSV' THEN ROUND((A.SCHED_DATE_TO-A.SCHED_DATE_FROM)* 24, 1)*30 ELSE 42.50 END)
FROM
WAREHOUSE.DM_DIM_ACTION "A"
WHERE
AND A.SITE_VISIT_YN = 'Y'
AND TRUNC( A.SCHED_DATE_FROM )= '20-Sep-11'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于 SQL 格式,而是我将错误的查询字符串传递给了 OCI_parse 函数。
如果您研究问题中的代码,您会注意到我正在尝试传递
$sql
,而不是我刚刚定义的$query
变量。对于多个查询,你永远不会太小心!
The issue was not the SQL formation, instead I was passing the wrong query string to the
OCI_parse
function.If you study the code in the question, you'll notice I'm trying to pass
$sql
, not the$query
variable that I've just defined.You can never be too careful with multiple queries!