如何在 pl/sql 解析器中添加所需的列?

How to add desired column in pl/sql parser?

以下代码没有显示语法错误,但在报告中出现错误:

ORA-01722: invalid number

select line_number, col002 , case when exists (select null from cdr_personal_info c where c.phone_no=col002 ) then 'Yes' else null end as cdr
  from apex_application_temp_files f, 
       table( apex_data_parser.parse(
                  p_content                     => f.blob_content,
                  p_add_headers_row             => 'Y',
                  p_xlsx_sheet_name             => :P31_XLSX_WORKSHEET,
                  p_max_rows                    => 500,
                  p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
                  p_file_name                   => f.filename ) ) p
 where f.name = :P31_FILE

如果您使用的是 Oracle 12,则可以尝试使用 DEFAULT NULL ON CONVERSION ERROR 选项将值显式转换为数字:

select line_number,
       col002,
       case
       when exists (select null
                      from cdr_personal_info c
                     where TO_NUMBER(c.phone_no DEFAULT NULL ON CONVERSION ERROR)
                           = TO_NUMBER(col002 DEFAULT NULL ON CONVERSION ERROR)
                   )
       then 'Yes'
       else null
       end as cdr
  from apex_application_temp_files f, 
       table( apex_data_parser.parse(
                  p_content                     => f.blob_content,
                  p_add_headers_row             => 'Y',
                  p_xlsx_sheet_name             => :P31_XLSX_WORKSHEET,
                  p_max_rows                    => 500,
                  p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
                  p_file_name                   => f.filename ) ) p
 where f.name = :P31_FILE

如果可行,那么您知道 c_phone_nocol002 实际上不是一个数字,而可能是一个字符串,并且至少有一行字符串值无法解析为数.

然后您可以使用以下方法找到它:

select line_number,
       col002
  from apex_application_temp_files f, 
       table( apex_data_parser.parse(
                  p_content                     => f.blob_content,
                  p_add_headers_row             => 'Y',
                  p_xlsx_sheet_name             => :P31_XLSX_WORKSHEET,
                  p_max_rows                    => 500,
                  p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
                  p_file_name                   => f.filename ) ) p
 where f.name = :P31_FILE
   and TO_NUMBER(col002 DEFAULT NULL ON CONVERSION ERROR) IS NULL;

或:

select *
  from cdr_personal_info c
 where TO_NUMBER(c.phone_no DEFAULT NULL ON CONVERSION ERROR) IS NULL;