1

正如问题所述。每次我尝试创建一个视图时,它都会对我调用它的第一列感到生气,并且无论该列可能是什么,它都会显示“意外的'Column_Name'”。

我是笨蛋还是有其他事情搞砸了?并不是说这些是相互排斥的......

-- Enterprise Factory Data Warehouse : EFDW

-- use appropriate role
USE ROLE EFDW_DEV_DB_DEV;
--USE ROLE EFDW_PROD_DB_DEV;

-- use appropriate Database
USE DATABASE EFDW_DEV_DB;
--USE DATABASE EFDW_PROD_DB;

-- use SUPPLYCHAIN_LOGISTICS schema
USE SCHEMA SUPPLYCHAIN_LOGISTICS;


--------------------------------------------------------------------------------------------------------
---------------------------------------- Information Object creation-------------------------------------------
--------------------------------------------------------------------------------------------------------

-- Demand Data Information Object
CREATE OR REPLACE VIEW SUPPLYCHAIN_LOGISTICS.DEMAND(
    MATERIAL_NUM COMMENT 'Material or Part Number',
    RSF_INDICATOR COMMENT 'Rough(R), Semi-Finished(S), or Finished(F) Indicator',
    SOURCE_PLANT_CODE COMMENT 'Plant code for the sending facility related to SAP',
    SOURCE_FACILITY_CODE COMMENT 'Plant code for the sending facility non-SAP',
    SOURCE_VALUE_STREAM_CODE COMMENT 'Sending valuestream within the source facility',
    PO_NUMBER COMMENT 'Part Order Number',
    PO_SCHEDULE_DUE_DATE COMMENT 'Scheduled Due Date for the PO',
    SCHEDULED_QUANTITY COMMENT 'Scheduled Quantity of pieces',
    SHIP_QUANTITY COMMENT 'Quantity of pieces actually shipped',
    RECEIVING_FACILITY_CODE 'Receiving Facility Code',
    DATA_SRC COMMENT 'Data Source',
    REFRESHED_TS COMMENT 'Refreshed Date. Last time the data was refreshed'
)

COMMENT = 'Data related to future demand'

AS

-- KK LEGACY DEMAND DATA
WITH KK_LEGACY_DEMAND AS (

SELECT 
    LEGACY_DEMAND.IDENT AS MATERIAL_NUM,
    LEGACY_DEMAND.RSF_I AS RSF_INDICATOR,
    NULL AS SOURCE_PLANT_CODE,
    'CZ' AS SOURCE_FACILITY_CODE,
    LEGACY_DEMAND.SCTN AS SOURCE_VALUE_STREAM_CODE,
    LEGACY_DEMAND.PO_NBR AS PO_NUMBER,
    LEGACY_DEMAND.PO_SCHD_DUE_DT AS PO_SCHEDULE_DUE_DATE,
    LEGACY_DEMAND.CUR_SCHD_QTY AS SCHEDULED_QUANTITY,
    LEGACY_DEMAND.SHP_QTY AS SHIP_QUANTITY,
    LEGACY_DEMAND.RCVG_FAC AS RECEIVING_FACILITY_CODE,
    'TBUPRODA_ISS_DMD_SCHD_TBL' AS DATA_SRC,
    LEGACY_DEMAND.REFRESHED_TS AS REFRESHED_TS
FROM
    EFDL_DEV_DB.DB2.TBUPRODA_ISS_DMD_SCHD_TBL LEGACY_DEMAND
    --  EFDL_DROD_DB.DB2.TBUPRODA_ISS_DMD_SCHD_TBL LEGACY_DEMAND
WHERE 
    LEGACY_DEMAND.PO_SCHD_DUE_DT >= CURRENT_DATE()
    AND LEGACY_DEMAND.REL_IND IN ('1', '0')
)

-- KK Legacy MAMM Demand
SELECT  
    KKLD.MATERIAL_NUM AS MATERIAL_NUM,
    KKLD.RSF_INDICATOR AS RSF_INDICATOR,
    NULL AS SOURCE_PLANT_CODE,
    KKLD.SOURCE_FACILITY_CODE AS SOURCE_FACILITY_CODE,
    KKLD.SCTN AS SOURCE_VALUE_STREAM_CODE,
    KKLD.PO_NBR AS PO_NUMBER,
    KKLD.PO_SCHD_DUE_DT AS PO_SCHEDULE_DUE_DATE,
    KKLD.CUR_SCHD_QTY AS SCHEDULED_QUANTITY,
    KKLD.SHP_QTY AS SHIP_QUANTITY,
    KKLD.RCVG_FAC AS RECEIVING_FACILITY_CODE,
    'TBUPRODA_ISS_DMD_SCHD_TBL' AS DATA_SRC,
    KKLD.REFRESHED_TS AS REFRESHED_TS
FROM KK_LEGACY_DEMAND KKLD
;

这是我的错误

SQL查询执行期间发生错误

原因:SQL 错误 [1003] [42000]:SQL 编译错误:位置 1 处的语法错误第 2 行意外'MATERIAL_NUM'。

4

1 回答 1

1

好的 - 所以我在同事的帮助下确定了它。这里出了一些问题。首先,我在 RECEIVING_FACILITY_CODE 之后的创建或替换视图中忘记了“COMMENT”

本来应该

CREATE OR REPLACE VIEW SUPPLYCHAIN_LOGISTICS.DEMAND (   
    MATERIAL_NUM COMMENT 'Material or Part Number',
    RSF_INDICATOR COMMENT 'Rough(R), Semi-Finished(S), or Finished(F) Indicator',
    SOURCE_PLANT_CODE COMMENT 'Plant code for the sending facility related to SAP',
    SOURCE_FACILITY_CODE COMMENT 'Plant code for the sending facility non-SAP',
    SOURCE_VALUE_STREAM_CODE COMMENT 'Sending valuestream within the source facility',
    PO_NUMBER COMMENT 'Part Order Number',
    PO_SCHEDULE_DUE_DATE COMMENT 'Scheduled Due Date for the PO',
    SCHEDULED_QUANTITY COMMENT 'Scheduled Quantity of pieces',
    SHIP_QUANTITY COMMENT 'Quantity of pieces actually shipped',
    **RECEIVING_FACILITY_CODE COMMENT 'Receiving Facility Code',**
    DATA_SRC COMMENT 'Data Source',
    REFRESHED_TS COMMENT 'Refreshed Date. Last time the data was refreshed'
)
COMMENT = 'Data related to future demand' 

但是,最后,在我的 select 语句附近,它也会给出错误。因为我做到了

KKLD.SCTN

不是

KKLD.SOURCE_VALUE_STREAM_CODE

因为我从另一个表创建了一个新表

With KK_LEGACY_DEMAND AS 
( -- This is where I am creating the new table
    SELECT
        LEGACY_DEMAND.IDENT AS MATERIAL_NUM,
        LEGACY_DEMAND.RSF_I AS RSF_INDICATOR,
        NULL AS SOURCE_PLANT_CODE,
        'CZ' AS SOURCE_FACILITY_CODE,
        LEGACY_DEMAND.SCTN AS SOURCE_VALUE_STREAM_CODE,
        ....,
)

现在我有了名为“KK_LEGACY_DEMAND”的表,我需要选择我在该表上创建的列

原始表 = SCTN 列

我刚刚在上面的行中创建的新表 = SOURCE_VALUE_STREAM_CODE 列

于 2021-08-15T18:37:29.107 回答