如何在输出后修复它

how to fix it following output

无规则,可用于任何内置函数,我有多种形式和不同的版本日期,因此我展示了示例数据。首先,我匹配检查 FORM_NO 列的最后四位数字与 Edition_Date 列。如果匹配,则跳过 FORM_NO 列的最后四位数字并与 Edition_Date 列连接,因为它是 show.For 示例,当我尝试执行以下查询时。

 with FOrm as (select 'GL-GEN-CHANGE-ENDT-MISC-OLD' Form_No, '05-05' Edition_Date from dual
union all
select 'CM59930202' Form_No, '02-02' Edition_Date from dual
union all
select '99109 06 08' Form_No, '06-08' Edition_Date from dual
union all
select 'IM 7978 08 12' Form_No, '08-12' Edition_Date from dual
union all
select 'IL01220907' Form_No, '09-07' Edition_Date from dual
union all
select 'PRG 2023 05 14' Form_No, '05-14' Edition_Date from dual)
select Form_No,case when SUBSTR(REGEXP_REPLACE( Form_No, '[^[:alnum:]]', NULL ),-4)=REGEXP_REPLACE( Edition_Date, '[^[:alnum:]]', NULL )
then substr(Form_No, 0, length(Form_No)-4)||' '||Edition_Date end as REC1,

 case when SUBSTR(REGEXP_REPLACE( Form_No, '[^[:alnum:]]', NULL ),-4)=REGEXP_REPLACE( Edition_Date, '[^[:alnum:]]', NULL )
 then substr(Form_No, 0, length(REGEXP_REPLACE( Form_No, '[^[:alnum:]]', NULL ))-4)||' '||Edition_Date 
  when  regexp_count(Form_No,'[^ [:alnum:]]')>2  then Form_No||' '||Edition_Date 
  when  regexp_count(Form_No,'[^-[:alnum:]]')>2  then SUBSTR(REGEXP_REPLACE( Form_No, '[^[:alnum:]]', NULL ),-5)||' '||Edition_Date 
 end REC2 from FOrm

我在执行查询后显示了以下输出

        FORM_NO                         Edition_Date        REC1                REC2
----------------------------    -------------   ----------------    --------------------
GL-GEN-CHANGE-ENDT-MISC-OLD     05-05               NULL                GL-GEN-CHANGE-ENDT-MISC-OLD 05-05
CM59930202                      02-02               CM5993 02-02        CM5993 02-02
99109 06 08                     06-08               99109 0 06-08       99109 06-08
IM 7978 08 12                   08-12               IM 7978 0 08-12     IM 797 08-12
IL01220907                      09-07               IL0122 09-07        IL0122 09-07
PRG 2023 05 14                  05-14               PRG 2023 0 05-14    PRG 202 05-14

期望结果

 FORM_NO                         REC1                           REC2
 -----------------------------------------------------------    ------------------------------------ 
GL-GEN-CHANGE-ENDT-MISC-OLD     GL-GEN-CHANGE-ENDT-MISC-OLD     GL-GEN-CHANGE-ENDT-MISC-OLD
CM59930202                      CM5993 02-02                    CM5993 02-02
99109 06 08                     99109 06-08                     99109 06-08
IM 7978 08 12                   IM7978 08-12                    IM 7978 08-12
IL01220907                      IL0122 09-07                    IL0122 09-07
PRG 2023 05 14                  PRG2023 05-14                   PRG 2023 05-14

这是一个正则表达式,可以提供您想要的输出,您没有提到任何规则只需要输出,所以这里是:

with FOrm as 
(
select 'GL-GEN-CHANGE-ENDT-MISC-OLD' Form_No, '05-05' Edition_Date from dual
union all
select 'CM59930202' Form_No, '02-02' Edition_Date from dual
union all
select '99109 06 08' Form_No, '06-08' Edition_Date from dual
union all
select 'IM 7978 08 12' Form_No, '08-12' Edition_Date from dual
union all
select 'IL01220907' Form_No, '09-07' Edition_Date from dual
union all
select 'PRG 2023 05 14' Form_No, '05-14' Edition_Date from dual)

select Form_No,
case
    when not regexp_like(Form_No,'[0-9]{1}') then Form_No

    when regexp_like(trim(Form_No),'^[A-Za-z]{1,}[[:space:]]{1,}') then 
        regexp_substr(Form_No,'^[A-Za-z]{1,}')||regexp_substr(Form_No,'[0-9]{1,}')||' '||
        Edition_Date
    
    when regexp_like(Form_No,'^[0-9]{1,}') then Form_No
    
    when regexp_like(Form_No,'^[A-Za-z]{1,}[0-9]{1,}') then
        regexp_substr(Form_No,'^[A-Za-z]{1,}')||regexp_substr(Form_No,'[0-9]{4}')||' '||
        Edition_Date
end as rec1,
case
    when not regexp_like(Form_No,'[0-9]{1}') then Form_No

    when regexp_like(trim(Form_No),'^[A-Za-z]{1,}[[:space:]]{1,}') then 
        regexp_substr(Form_No,'^[A-Za-z]{1,}')||' '||regexp_substr(Form_No,'[0-9]{1,}')||' '||
        Edition_Date
    
    when regexp_like(Form_No,'^[0-9]{1,}') then Form_No
    
    when regexp_like(Form_No,'^[A-Za-z]{1,}[0-9]{1,}') then
        regexp_substr(Form_No,'^[A-Za-z]{1,}')||regexp_substr(Form_No,'[0-9]{4}')||' '||
        Edition_Date
end as rec2
from FOrm

结果:

FORM_NO                      REC1                        REC2
------------------------------------------------------------------------------------
GL-GEN-CHANGE-ENDT-MISC-OLD  GL-GEN-CHANGE-ENDT-MISC-OLD GL-GEN-CHANGE-ENDT-MISC-OLD
CM59930202                   CM5993 02-02                CM5993 02-02
99109 06 08                  99109 06 08                 99109 06 08
IM 7978 08 12                IM7978 08-12                IM 7978 08-12
IL01220907                   IL0122 09-07                IL0122 09-07
PRG 2023 05 14               PRG2023 05-14               PRG 2023 05-14