Oracle DB查询未返回预期结果

您能建议我如何执行查询以获得预期结果吗?下面我们可以看到实际和预期的输出结果。

WITH constants as (
    select  
        '' NA,'1.7' version,'test' needBrand,' ' needIdNbr,'cox  ' needFirstName,' ' needMiddleName,'simson' needLastName,' ' needNameSuffix,'10115 Jeffreys St' needAddrLine1,' ' needAddrLine2,'Las Vegas' needCity,'NV' needState,'89183' needZipCode,' ' needCountry,'1000047710' needPhoneNbr,'tcc_04@test.com' needEmailAddr,' ' USAGE
    from dual    
)
SELECT  constants.version AS version,TO_CHAR(current_timestamp,'YYYY/MM/DD hh24:mi:ss') AS extractDate,constants.needBrand AS needBrand,constants.needIdNbr AS needIdNbr,constants.needFirstName AS needFirstName,constants.needMiddleName AS needMiddleName,constants.needLastName AS needLastName,constants.needNameSuffix AS needNameSuffix,constants.needAddrLine1 AS needAddrLine1,constants.needAddrLine2 AS needAddrLine2,constants.needCity AS needCity,constants.needState AS needState,constants.needZipCode AS needZipCode,constants.needCountry AS needCountry,constants.needPhoneNbr AS needPhoneNbr,constants.needEmailAddr AS needEmailAddr,constants.USAGE AS USAGE,UPPER(user_status) AS Status,UPPER(user_type) AS Type,TO_CHAR(CREATED,'MM/DD/YYYY') AS Date 
     from usertitle ue,constants

实际输出:

version      needFirstName            Status                   Type 
--------     -------------           ------------             -------- ...etc
  1             David                Cancelled_pending        SHOEBOX 
  1             james                Subscribed_Pending       giftBox

预期的输出:在运行查询时,我们希望获得以下结果。状态为“ _”,并且在“类型”列中需要空格。

Version      needFirstName          Status                   Type 
--------     -------------        ------------              -------- ... etc
   1            David             Cancelled pending         SHOE BOX 
   1            james             Subscribed Pending        gift Box
c275896741 回答:Oracle DB查询未返回预期结果

状态和类型来自“选择UPPER(user_status)AS状态,从用户名选择UPPER(user_type)”(为简单起见,我删除了常量)。这些列上没有任何操作会增加空间或删除下划线。您需要对user_status和user_type列上的那些操作调用一个函数。

您可以使用REPLACE函数将“ _”替换为空格,将“ BOX”替换为“ BOX”。这将更改_和BOX的所有实例。

对于状态列,您可以这样做,

select REPLACE(UPPER(user_status),'_',' ') AS Status,REPLACE(UPPER(user_type),'BOX',' BOX') AS Type 
from usertitle;

如果要更改子字符串的特定实例,则- 1.您可以使用INSTR函数查找子字符串的位置 2.然后使用SUBSTR函数将该位置的列分为两部分。最终的字符串将是part1 || ' ' || part2添加一个空格,然后

本文链接:https://www.f2er.com/2876660.html

大家都在问