ORA-00928:缺少SELECT关键字00928。00000-在Oracle DB上执行时“缺少SELECT关键字”出错

时间:2019-12-12 01:00:05

标签: oracle oracledb

在oracle db中执行此查询时出现错误,但在Postgresssql上相同的查询工作正常,请您提示我在哪里做错了。

查询:

WITH constants(
    NA, version, needBrand, needIdNbr, needFirstName, needMiddleName, needLastName, 
    needNameSuffix, needAddrLine1, needAddrLine2, needCity, needState, needZipCode, 
    needCountry, needPhoneNbr, needEmailAddr, USAGE
)AS ( 
    values('', '1.7', 'test', ' ', 'cox  ', ' ', 'simson', ' ', '10115 Jeffreys St', ' ', 
    'Las Vegas', 'NV', '89183', ' ', '1000047710', 'tcc_04@test.com', ' ')
) 
     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  needBrand  needIdNbr  needFirstName  needMiddleName needLastName 
 -------  ----------  --------  -------------  --------------  ------------
 1.1     samsung    111      James           Andy              snow   
 1.1     dell       123      tony            smith             adams

1 个答案:

答案 0 :(得分:0)

对于Oracle,以下方法将起作用。但是我看到用户名ue和常量之间的笛卡尔积。这就是你想要的吗?

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;