Oracle脚本中的标识符错误无效

时间:2014-11-19 07:23:50

标签: oracle oracle-sqldeveloper

我有一个结合了insert和select的脚本,当我尝试运行它时,我收到了一个错误。

  SQL Error: ORA-00904: "A"."DATE_ENCODED": invalid identifier

我已经检查了创建表格中的拼写,这是正确的。

如何解决此错误?

谢谢

脚本

  insert into  import_temp(reference,col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13)
  select a.reference,a.MAIL_CODE,a.DATE_SENT,a.DATE_GENERATED,a.MAIL_ORDER,a.TEXT_CONTRACT_NUMBER,a.CLIENT_NAME_FULL,a.STREET_ADDRESS,a.REGISTRY_NO,a.DATE_RECEIVED,a.STATUS,a.REMARKS,a.ADDITIONAL_NOTES,a.DATE_ENCODED
from (
select distinct 'VAL-'||t.reference as reference
      ,case -- information validation
            when (row_number() over (order by id))=1 and trim(replace(col1,chr(13),''))='Letter_status' then 'tracker'
            -- header validation
            when (row_number() over (order by id))<3 then 'header1'
            when (row_number() over (order by id))=3 and trim(col1)<>'MAIL_CODE' then 'Unknown column '||t.col1
            when (row_number() over (order by id))=3 and trim(col2)<>'DATE_SENT' then 'Unknown column '||t.col2
            when (row_number() over (order by id))=3 and trim(col3)<>'DATE_GENERATED' then 'Unknown column '||t.col3
            when (row_number() over (order by id))=3 and trim(col4)<>'MAIL_ORDER' then 'Unknown column '||t.col4
            when (row_number() over (order by id))=3 and trim(col5)<>'TEXT_CONTRACT_NUMBER' then 'Unknown column '||t.col5
            when (row_number() over (order by id))=3 and trim(col6)<>'CLIENT_NAME_FULL' then 'Unknown column '||t.col6
            when (row_number() over (order by id))=3 and trim(col7)<>'STREET_ADDRESS' then 'Unknown column '||t.col7
            when (row_number() over (order by id))=3 and trim(col8)<>'REGISTRY_NO' then 'Unknown column '||t.col8
            when (row_number() over (order by id))=3 and trim(col9)<>'DATE_RECEIVED' then 'Unknown column '||t.col9
            when (row_number() over (order by id))=3 and trim(col10)<>'STATUS' then 'Unknown column '||t.col10
            when (row_number() over (order by id))=3 and trim(col11)<>'REMARKS' then 'Unknown column '||t.col11
            when (row_number() over (order by id))=3 and trim(col12)<>'ADDITIONAL_NOTES' then 'Unknown column '||t.col12
            when (row_number() over (order by id))=3 and trim(col13)<>'DATE_ENCODED' then 'Unknown column '||t.col13
            when (row_number() over (order by id))=3 then 'header'
            -- record validation
            when (row_number() over (order by id))>=4 then 'record'
            else 'unknown row '||(row_number() over (order by id))
       end as field_name
from params p
inner join import_temp t on p.GUID=t.reference
where not t.col1 is null 
) a
group by  a.reference,a.MAIL_CODE,a.DATE_SENT,a.DATE_GENERATED,a.MAIL_ORDER,a.TEXT_CONTRACT_NUMBER,a.CLIENT_NAME_FULL,a.STREET_ADDRESS,a.REGISTRY_NO,a.DATE_RECEIVED,a.STATUS,a.REMARKS,a.ADDITIONAL_NOTES,a.DATE_ENCODED;

2 个答案:

答案 0 :(得分:1)

您未从表中选择任何此值:

a.MAIL_CODE,a.DATE_SENT,a.DATE_GENERATED,a.MAIL_ORDER,a.TEXT_CONTRACT_NUMBER,a.CLIENT_NAME_FULL,a.STREET_ADDRESS,a.REGISTRY_NO,a.DATE_RECEIVED,a.STATUS,a.REMARKS,a.ADDITIONAL_NOTES,a.DATE_ENCODED

您应该在查询中添加以下内容:

     insert into  import_temp(reference,col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13)
      select a.reference,a.MAIL_CODE,a.DATE_SENT,a.DATE_GENERATED,a.MAIL_ORDER,a.TEXT_CONTRACT_NUMBER,a.CLIENT_NAME_FULL,a.STREET_ADDRESS,a.REGISTRY_NO,a.DATE_RECEIVED,a.STATUS,a.REMARKS,a.ADDITIONAL_NOTES,a.DATE_ENCODED
    from (

 -- calculate the values
select a.reference, 
       MAX(a.MAIL_CODE) as MAIL_CODE

  -- other parameters here

  from (


    select distinct 'VAL-'||t.reference as reference
          ,case -- information validation
                when (row_number() over (order by id))=1 and trim(replace(col1,chr(13),''))='Letter_status' then 'tracker'
                -- header validation
                when (row_number() over (order by id))<3 then 'header1'
                when (row_number() over (order by id))=3 and trim(col1)<>'MAIL_CODE' then 'Unknown column '||t.col1
                when (row_number() over (order by id))=3 and trim(col2)<>'DATE_SENT' then 'Unknown column '||t.col2
                when (row_number() over (order by id))=3 and trim(col3)<>'DATE_GENERATED' then 'Unknown column '||t.col3
                when (row_number() over (order by id))=3 and trim(col4)<>'MAIL_ORDER' then 'Unknown column '||t.col4
                when (row_number() over (order by id))=3 and trim(col5)<>'TEXT_CONTRACT_NUMBER' then 'Unknown column '||t.col5
                when (row_number() over (order by id))=3 and trim(col6)<>'CLIENT_NAME_FULL' then 'Unknown column '||t.col6
                when (row_number() over (order by id))=3 and trim(col7)<>'STREET_ADDRESS' then 'Unknown column '||t.col7
                when (row_number() over (order by id))=3 and trim(col8)<>'REGISTRY_NO' then 'Unknown column '||t.col8
                when (row_number() over (order by id))=3 and trim(col9)<>'DATE_RECEIVED' then 'Unknown column '||t.col9
                when (row_number() over (order by id))=3 and trim(col10)<>'STATUS' then 'Unknown column '||t.col10
                when (row_number() over (order by id))=3 and trim(col11)<>'REMARKS' then 'Unknown column '||t.col11
                when (row_number() over (order by id))=3 and trim(col12)<>'ADDITIONAL_NOTES' then 'Unknown column '||t.col12
                when (row_number() over (order by id))=3 and trim(col13)<>'DATE_ENCODED' then 'Unknown column '||t.col13
                when (row_number() over (order by id))=3 then 'header'
                -- record validation
                when (row_number() over (order by id))>=4 then 'record'
                else 'unknown row '||(row_number() over (order by id))
           end as field_name


,case -- information validation
                when (row_number() over (order by id))=3 and trim(col1)='MAIL_CODE' then 
                   p.text1 -- where the value is stored
                else null
           end as MAIL_CODE

 -- other parameters here

    from params p
    inner join import_temp t on p.GUID=t.reference
    where not t.col1 is null 

)a
 GROUP BY a.reference

    ) a
    group by  a.reference,a.MAIL_CODE,a.DATE_SENT,a.DATE_GENERATED,a.MAIL_ORDER,a.TEXT_CONTRACT_NUMBER,a.CLIENT_NAME_FULL,a.STREET_ADDRESS,a.REGISTRY_NO,a.DATE_RECEIVED,a.STATUS,a.REMARKS,a.ADDITIONAL_NOTES,a.DATE_ENCODED;

答案 1 :(得分:0)

如果您需要选择select语句中使用的所有值进行插入,请使用下面的

    insert into import_temp
  (reference,
   col1,
   col2,
   col3,
   col4,
   col5,
   col6,
   col7,
   col8,
   col9,
   col10,
   col11,
   col12,
   col13)
  select a.*
    from (select distinct 'VAL-' || t.reference as reference,
                          case -- information validation
                            when (row_number() over(order by id)) = 1 and
                                 trim(replace(col1, chr(13), '')) =
                                 'Letter_status' then
                             'tracker'
                          -- header validation
                            when (row_number() over(order by id)) < 3 then
                             'header1'
                            when (row_number() over(order by id)) = 3 and
                                 trim(col1) <> 'MAIL_CODE' then
                             'Unknown column ' || t.col1
                            when (row_number() over(order by id)) = 3 and
                                 trim(col2) <> 'DATE_SENT' then
                             'Unknown column ' || t.col2
                            when (row_number() over(order by id)) = 3 and
                                 trim(col3) <> 'DATE_GENERATED' then
                             'Unknown column ' || t.col3
                            when (row_number() over(order by id)) = 3 and
                                 trim(col4) <> 'MAIL_ORDER' then
                             'Unknown column ' || t.col4
                            when (row_number() over(order by id)) = 3 and
                                 trim(col5) <> 'TEXT_CONTRACT_NUMBER' then
                             'Unknown column ' || t.col5
                            when (row_number() over(order by id)) = 3 and
                                 trim(col6) <> 'CLIENT_NAME_FULL' then
                             'Unknown column ' || t.col6
                            when (row_number() over(order by id)) = 3 and
                                 trim(col7) <> 'STREET_ADDRESS' then
                             'Unknown column ' || t.col7
                            when (row_number() over(order by id)) = 3 and
                                 trim(col8) <> 'REGISTRY_NO' then
                             'Unknown column ' || t.col8
                            when (row_number() over(order by id)) = 3 and
                                 trim(col9) <> 'DATE_RECEIVED' then
                             'Unknown column ' || t.col9
                            when (row_number() over(order by id)) = 3 and
                                 trim(col10) <> 'STATUS' then
                             'Unknown column ' || t.col10
                            when (row_number() over(order by id)) = 3 and
                                 trim(col11) <> 'REMARKS' then
                             'Unknown column ' || t.col11
                            when (row_number() over(order by id)) = 3 and
                                 trim(col12) <> 'ADDITIONAL_NOTES' then
                             'Unknown column ' || t.col12
                            when (row_number() over(order by id)) = 3 and
                                 trim(col13) <> 'DATE_ENCODED' then
                             'Unknown column ' || t.col13
                            when (row_number() over(order by id)) = 3 then
                             'header'
                          -- record validation
                            when (row_number() over(order by id)) >= 4 then
                             'record'
                            else
                             'unknown row ' ||
                             (row_number() over(order by id))
                          end as field_name
            from params p
           inner join import_temp t on p.GUID = t.reference
           where not t.col1 is null) a