简体   繁体   中英

Oracle SQL syntax error (missing right parenthesis)

I don't understand why this provokes a syntax error (missing right parenthesis):

UPDATE table
SET doc =
  (SELECT 'table-2844-doc' || SUBSTR(doc_file, INSTR(doc_file, '.', -1))
   FROM docvers
   WHERE (docvers.table_name = 'other_table'
          AND docvers.field_name = 'doc')
     AND ROWNUM = 1
   ORDER BY VERSION DESC)
WHERE table_id = 2844

This looks right to me, does get executed correctly in SQL Server, and is similar to requests found, for example, in Oracle SQL: Update a table with data from another table .

Any tip?

Do it like this:

UPDATE table
SET doc = (
 select r.myval
 from (
 SELECT 'table-2844-doc' || SUBSTR(doc_file, INSTR(doc_file, '.', -1)) myval, ROWNUM RN
 FROM docvers
 WHERE docvers.table_name = 'other_table'
 AND docvers.field_name = 'doc'
 ORDER BY VERSION DESC
 ) r
 where r.RN = 1
)
WHERE table_id = 2844

Select the data set first including the ROWNUM , then select from that data set the first row.

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