0

我几乎已经完成了下面的查询,但是 qcare_end 和warranty_end 这两个字段在执行脚本时都生成了一个无效的标识符错误另外 - 我希望使用这个脚本(以及一些类似的脚本)来生成一系列操作这将从我们的 oracle 合同和零件管理数据库中获取一部分数据,并将其喷射到 mysql 数据库中,我们在记录事件时使用该数据库来支持

    Select
    'Insert Into mysqldbtable (system_id, customer_code,, serial_no, system_type, description, qcare_end, warranty_end) Values (''' 
    || system_id || ''',''' || customer_code || ''',''' || serial_no || ''',''' || system_type || ''',''' || description ||  ''')'
  FROM (SELECT SYSTEMS.SYSTEM_ID
               --            ,SYSTEMS.SITE_NAME
              , CUSTOMER_ADDRESSES.CUSTOMER_CODE
               --            , CUSTOMER_ADDRESSES.NAME
              , SYSTEMS.SERIAL_NO
              , SYSTEMS.SYSTEM_TYPE
              , PM.DESCRIPTION
               --            ,MAX(EI.END_DATE)
              , TO_DATE(NULL) AS "qcare_end"
              , MAX(systems.warranty_end) AS "warranty_end"
        --            ,systems.warranty_code
          FROM LEO.CUSTOMER_ADDRESSES CUSTOMER_ADDRESSES
               -- , LEO.CUSTOMERS CUSTOMERS
              , LEO.SYSTEMS SYSTEMS
               -- , LEO.EXHIBIT_ITEMS EI
              , LEO.PART_MASTER PM
         WHERE SYSTEMS.ADDRESS_CODE = CUSTOMER_ADDRESSES.ADDRESS_CODE
              -- AND CUSTOMER_ADDRESSES.CUSTOMER_CODE = CUSTOMERS.CUSTOMER_CODE 
              -- AND SYSTEMS.SYSTEM_ID = EI.SYSTEM_ID
           AND SYSTEMS.SYSTEM_TYPE = PM.PART_NO
         GROUP BY SYSTEMS.SYSTEM_ID,
                  SYSTEMS.SERIAL_NO,
                  CUSTOMER_ADDRESSES.CUSTOMER_CODE,
                  CUSTOMER_ADDRESSES.NAME,
                  SYSTEMS.SITE_NAME,
                  SYSTEMS.SYSTEM_TYPE,
                  PM.DESCRIPTION
        HAVING(SYSTEMS.SYSTEM_TYPE NOT IN('COMPLETE', 'ESSENTIAL', 'LOAN DEMO', 'LOAN CUSTOMER', 'MISC', 
        'ORPH-CHILD-SYS', 'ORPH_CHILD_SYS', 'PROD-BOM', 'QCARE', 'QSUPPORT', 'SPARES', 'STANDARD', 'WARRANTY', 'SOFT CARE')) 
        AND (SYSTEMS.SITE_NAME NOT LIKE '%DO NOT USE%' AND CUSTOMER_ADDRESSES.NAME NOT LIKE 'QUANTEL%' AND CUSTOMER_ADDRESSES.NAME NOT LIKE '%LOCATION NOT KNOWN%')
       UNION SELECT SYSTEMS.SYSTEM_ID
               --            ,SYSTEMS.SITE_NAME
              , CUSTOMER_ADDRESSES.CUSTOMER_CODE
               --            , CUSTOMER_ADDRESSES.NAME
              , SYSTEMS.SERIAL_NO
              , SYSTEMS.SYSTEM_TYPE
              , PM.DESCRIPTION
               --            ,MAX(EI.END_DATE)
              , MAX(EI.END_DATE) AS "QCare_End"
              , TO_DATE(NULL) "Warranty_End"
        --            ,MAX(systems.warranty_end)
        --            ,systems.warranty_code
          FROM LEO.CUSTOMER_ADDRESSES CUSTOMER_ADDRESSES
               -- , LEO.CUSTOMERS CUSTOMERS
              , LEO.SYSTEMS       SYSTEMS
              , LEO.EXHIBIT_ITEMS EI
              , LEO.PART_MASTER   PM
         WHERE SYSTEMS.ADDRESS_CODE = CUSTOMER_ADDRESSES.ADDRESS_CODE
              -- AND CUSTOMER_ADDRESSES.CUSTOMER_CODE = CUSTOMERS.CUSTOMER_CODE 
           AND SYSTEMS.SYSTEM_ID = EI.SYSTEM_ID
           AND SYSTEMS.SYSTEM_TYPE = PM.PART_NO
         GROUP BY SYSTEMS.SYSTEM_ID,
                  SYSTEMS.SERIAL_NO,
                  CUSTOMER_ADDRESSES.CUSTOMER_CODE,
                  CUSTOMER_ADDRESSES.NAME,
                  SYSTEMS.SITE_NAME,
                  SYSTEMS.SYSTEM_TYPE,
                  PM.DESCRIPTION
        HAVING(SYSTEMS.SYSTEM_TYPE NOT IN('COMPLETE',  'ESSENTIAL', 'LOAN DEMO', 'LOAN CUSTOMER'
        , 'MISC', 'ORPH-CHILD-SYS', 'ORPH_CHILD_SYS', 'PROD-BOM', 'QCARE', 'QSUPPORT', 'SPARES', 'STANDARD', 'WARRANTY', 'SOFT CARE')) 
        AND (SYSTEMS.SITE_NAME NOT LIKE '%DO NOT USE%' AND CUSTOMER_ADDRESSES.NAME NOT LIKE 'QUANTEL%' AND CUSTOMER_ADDRESSES.NAME NOT LIKE '%LOCATION NOT KNOWN%'))
where ROWNUM <= 10 ORDER BY SERIAL_NO;

这只会返回 10 个结果,看起来很正常 - 但如果我重新添加 qcare 和保修结束日期,它会失败并出现以下错误:

65 其中 ROWNUM <= 10 ORDER BY SERIAL_NO; || 系统标识 || ''',''' || 客户代码 || ''',''' || 序列号 || ''',''' || 系统类型 || ''',''' || 说明 || ''',''' ||qcare_end|| ''',''' ||warranty_end|| ''')' * 第 3 行出现错误:ORA-00904:“WARRANTY_END”:标识符无效

SQL>

我不确定为什么表别名不起作用 - 在常规查询中似乎很好,但当我尝试生成导入语句时,我可以定期将其导入 mysql。

对我所缺少的有什么想法吗?干杯斯科特

4

1 回答 1

1

斯科特,

别名不起作用,因为您已将它们放在双引号和混合大小写中(提示:不要这样做)。这意味着您必须以这种方式引用它们:

SELECT "qcare" FROM (your_query)

您可能想要这个,这会使您的别名全部大写:

, TO_DATE(NULL) AS qcare_end
, MAX(systems.warranty_end) AS warranty_end

, MAX(EI.END_DATE) AS QCare_End
, TO_DATE(NULL) Warranty_End

从技术上讲,无论如何您都不需要联合后半部分的别名,它是联合的前半部分驱动内联视图的列名。

于 2013-02-01T01:05:15.900 回答