Oracle / PHP“无效标识符”错误

时间:2016-12-23 14:58:25

标签: php oracle views

我真的不确定此时发生了什么。我正在尝试创建一个视图,当我运行以下查询时:

$view = oci_parse($conn, '
                CREATE OR REPLACE VIEW 
                    V_ORD_HISTORY
                AS 
                SELECT
                    ARCUSTO.ID,
                    ORDERS.ID,
                    ORDERS.PONO,
                    ORDERS.ORDERNO,
                    ORDERS.DATE_TAKEN,
                    ORDERS.ARCUSTO_ID,
                    ORD_DETAIL.ORDERS_ID,
                    ORD_DETAIL.ID,
                    ORD_DETAIL.TOTAL_QTY_ORD,
                    ORD_DETAIL.CUMM_SHIPPED,
                    ORD_DETAIL.DISCOUNT,
                    ORD_DETAIL.UNIT_PRICE
                FROM
                    ARCUSTO a,
                    ORDERS  o,
                    ORD_DETAIL d,
                    ARINVT i
                WHERE
                    a.ID = o.ARCUSTO_ID
                AND
                    d.ORDERS_ID = o.ID
            ');

我收到错误:

ORA-00904: "ORD_DETAIL"."UNIT_PRICE": invalid identifier

如果我尝试从select语句的末尾删除 ORD_DETAIL.UNIT_PRICE ,那么它会告诉我 ORD_DETAIL.DISCOUNT 现在是无效的标识符。列表中最后一列是无效标识符。如果我删除前缀以确定哪个表,那么我会得到列模糊定义的错误。

任何想法??

编辑1

我现在已将代码更改为以下内容:

$view = oci_parse($conn, '
                CREATE OR REPLACE VIEW 
                    V_ORD_HISTORY
                AS 
                SELECT
                    a.ID as CUSTOMER_ID,
                    o.ID as ORD_ID,
                    o.PONO,
                    o.ORDERNO,
                    o.DATE_TAKEN,
                    o.ARCUSTO_ID,
                    d.ORDERS_ID,
                    d.ID as DETAIL_ID,
                    d.TOTAL_QTY_ORD,
                    d.CUMM_SHIPPED,
                    d.DISCOUNT,
                    d.UNIT_PRICE
                FROM
                    ARCUSTO a,
                    ORDERS  o,
                    ORD_DETAIL d,
                    ARINVT i
                WHERE
                    CUSTOMER_ID = o.ARCUSTO_ID
                AND
                    ORD_ID = d.ORDERS_ID
            ');

但现在它说 ORD_ID 是无效的标识符。这是SQL语句的最后一行。

1 个答案:

答案 0 :(得分:1)

尝试怎么样:

CREATE OR REPLACE VIEW 
                    V_ORD_HISTORY
                AS 
                SELECT
                    a.ID as CUSTOMER_ID,
                    o.ID as ORD_ID,
                    o.PONO,
                    o.ORDERNO,
                    o.DATE_TAKEN,
                    o.ARCUSTO_ID,
                    d.ORDERS_ID,
                    d.ID as DETAIL_ID,
                    d.TOTAL_QTY_ORD,
                    d.CUMM_SHIPPED,
                    d.DISCOUNT,
                    d.UNIT_PRICE
                FROM
                    ARCUSTO a,
                    ORDERS  o,
                    ORD_DETAIL d,
                    ARINVT i
                WHERE
                    a.id= o.ARCUSTO_ID
                AND
                    o.id = d.ORDERS_ID