简体   繁体   中英

SQL query error REGEXP_INSTR with parenthesis in expression

I'm having an issue with my query where I have a parenthesis in the regular expression. My editor is associating the parenthesis in the expression with another parenthesis outside of the expression.

I'm wondering if this is causing the ORA-00907: missing right parenthesis error I'm receiving, or if it's something else?

WITH Stats AS
(
    SELECT 
        column1, column2
    FROM TABLE1
    UNION ALL
    SELECT
        column1, column2
    FROM TABLE2
),
Newest AS
(
    SELECT s.*
    ROW_NUMBER() OVER
    (   
        PARTITION BY
        column1, column2
        REPLACE(REPLACE('%(param)s', '5', '6'), '7', '8')
        ORDER BY colum2 DESC
    )   PRIORITY
    CASE WHEN REGEXP_INSTR('%(param)s', '/(//') 
    > 0 AND REGEXP_LIKE(column1, '%(param)s') 
    THEN 'Y' END PARAM_MATCH,
    CASE WHEN REGEXP_INSTR('%(param)s', '/(//') 
    = 0 AND column1 LIKE '%(param)s' THEN 'Y' 
    END LIKE_MATCH,
    FROM Stats s
    WHERE (REGEXP_INSTR('%(param)s', '/(//') > 0 
    AND REGEXP_LIKE(column1,'%(param)s')) OR
    (REGEXP_INSTR('%(param)s', '/(//') = 0 AND 
    REGEXP_LIKE'%(param)s')) OR
    '%(param)s' IS NULL
)

Zillion of errors; noted in comments:

WITH Stats AS
(
    SELECT 
        column1, column2
    FROM TABLE1
    UNION ALL
    SELECT
        column1, column2
    FROM TABLE2
),
Newest AS
(
    SELECT s.*                                      --> missing comma
    ROW_NUMBER() OVER
    (   
        PARTITION BY
        column1, column2                            --> missing comma
        REPLACE(REPLACE('%(param)s', '5', '6'), '7', '8')
        ORDER BY colum2 DESC
    )   PRIORITY                                    --> missing comma
    CASE WHEN REGEXP_INSTR('%(param)s', '/(//') 
    > 0 AND REGEXP_LIKE(column1, '%(param)s') 
    THEN 'Y' END PARAM_MATCH,
    CASE WHEN REGEXP_INSTR('%(param)s', '/(//') 
    = 0 AND column1 LIKE '%(param)s' THEN 'Y' 
    END LIKE_MATCH,                                 --> superfluous comma
    FROM Stats s
    WHERE (REGEXP_INSTR('%(param)s', '/(//') > 0 
    AND REGEXP_LIKE(column1,'%(param)s')) OR
    (REGEXP_INSTR('%(param)s', '/(//') = 0 AND 
    REGEXP_LIKE'%(param)s')) OR                     --> what is REGEXP_LIKE?
    '%(param)s' IS NULL
)
                                                    --> missing SELECT statement

This is now correct as far as syntax is concerned. Once again, as in your previous question: be more careful when you write queries as this is getting absurd.

WITH Stats
     AS (SELECT column1, column2 FROM TABLE1
         UNION ALL
         SELECT column1, column2 FROM TABLE2),
     Newest
     AS (SELECT s.*,
                ROW_NUMBER ()
                OVER (
                   PARTITION BY column1,
                                column2,
                                REPLACE (REPLACE ('%(param)s', '5', '6'),
                                         '7',
                                         '8')
                   ORDER BY colum2 DESC)
                   PRIORITY,
                CASE
                   WHEN     REGEXP_INSTR ('%(param)s', '/(//') > 0
                        AND REGEXP_LIKE (column1, '%(param)s')
                   THEN
                      'Y'
                END
                   PARAM_MATCH,
                CASE
                   WHEN     REGEXP_INSTR ('%(param)s', '/(//') = 0
                        AND column1 LIKE '%(param)s'
                   THEN
                      'Y'
                END
                   LIKE_MATCH
           FROM Stats s
          WHERE    (    REGEXP_INSTR ('%(param)s', '/(//') > 0
                    AND REGEXP_LIKE (column1, '%(param)s'))
                OR (    REGEXP_INSTR ('%(param)s', '/(//') = 0
                    AND REGEXP_LIKE ('???', '%(param)s'))
                OR '%(param)s' IS NULL)
SELECT *
  FROM newest;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM