subquery-factoring

Oracle — WITH CLAUSE => MERGE? (Syntax error, )

拟墨画扇 提交于 2019-12-30 08:03:48
问题 I'm trying to get the WITH clause to work with merge in Oracle, but for some reason I can't get it working. I'm sure it is something obvious, but I just haven't seen it. -- behold, the wonders of fake data WITH X AS ( SELECT 'moo' AS COW, 'woof' AS CAT, (SELECT MAX( DECIBELS ) FROM ANIMALIA WHERE COW = 'moo' ) AS DECIBELS FROM DUAL ) MERGE INTO ANIMALIA D USING X WHEN MATCHED THEN UPDATE SET D.COW = X.COW; EDIT I actually found out how to manage this (before I submitted the question), but I

Oracle — WITH CLAUSE => MERGE? (Syntax error, )

£可爱£侵袭症+ 提交于 2019-12-01 02:58:29
I'm trying to get the WITH clause to work with merge in Oracle, but for some reason I can't get it working. I'm sure it is something obvious, but I just haven't seen it. -- behold, the wonders of fake data WITH X AS ( SELECT 'moo' AS COW, 'woof' AS CAT, (SELECT MAX( DECIBELS ) FROM ANIMALIA WHERE COW = 'moo' ) AS DECIBELS FROM DUAL ) MERGE INTO ANIMALIA D USING X WHEN MATCHED THEN UPDATE SET D.COW = X.COW; EDIT I actually found out how to manage this (before I submitted the question), but I think that since it took me quite some time to find the answer, hopefully leaving this question up will

Oracle DELETE statement with subquery factoring

放肆的年华 提交于 2019-11-30 12:10:15
Trying to do this (works in SQL Server): WITH X AS (), Y AS (), Z AS () DELETE FROM TBL WHERE TBL.ID IN (SELECT ID FROM Z); This works in Oracle: WITH X AS (), Y AS (), Z AS () SELECT * FROM TBL WHERE TBL.ID IN (SELECT ID FROM Z); But the DELETE does not: ORA-00928: missing SELECT keyword My subqueries are rather large, is there a different syntax to get this to work? You cannot use Subquery Factoring/CTE with anything but the SELECT statement. From the documentation: You can specify this clause in any top-level SELECT statement and in most types of subqueries. You could do this: DELETE FROM

Oracle DELETE statement with subquery factoring

老子叫甜甜 提交于 2019-11-29 18:02:48
问题 Trying to do this (works in SQL Server): WITH X AS (), Y AS (), Z AS () DELETE FROM TBL WHERE TBL.ID IN (SELECT ID FROM Z); This works in Oracle: WITH X AS (), Y AS (), Z AS () SELECT * FROM TBL WHERE TBL.ID IN (SELECT ID FROM Z); But the DELETE does not: ORA-00928: missing SELECT keyword My subqueries are rather large, is there a different syntax to get this to work? 回答1: You cannot use Subquery Factoring/CTE with anything but the SELECT statement. From the documentation: You can specify

How do you use the “WITH” clause in MySQL?

人盡茶涼 提交于 2019-11-25 22:38:05
问题 I am converting all my SQL Server queries to MySQL and my queries that have WITH in them are all failing. Here\'s an example: WITH t1 AS ( SELECT article.*, userinfo.*, category.* FROM question INNER JOIN userinfo ON userinfo.user_userid = article.article_ownerid INNER JOIN category ON article.article_categoryid = category.catid WHERE article.article_isdeleted = 0 ) SELECT t1.* FROM t1 ORDER BY t1.article_date DESC LIMIT 1, 3 回答1: MySQL prior to version 8.0 doesn't support the WITH clause