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'
The issue was not the SQL formation, instead I was passing the wrong query string to the OCI_parse
function.
If the 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!
精彩评论