开发者

Using "WITH AS" keywords when migrating data in SQL

开发者 https://www.devze.com 2022-12-12 03:46 出处:网络
Is it possible to do this in SQL? If I remove the INSERT statement the SELECT works, if I have the insert Oracle complains that \"missing SELECT keyword\".

Is it possible to do this in SQL?

If I remove the INSERT statement the SELECT works, if I have the insert Oracle complains that "missing SELECT keyword".

WITH tmpdata AS
(
//SOME arbitrary select statement
)

INSERT INTO myTable (someId, somevalue, someothervalue)
SELECT
 mysequence.nextval,
 tmpData.somevalue,
 tmpData.someothervalue,
FROM
 tmpdata,
 sometabletojoin
WHERE
 tmpdata.somevalue = sometabletojoin开发者_C百科.somevaluebutintheothertable


This should work:

INSERT INTO myTable (someId, somevalue, someothervalue)
WITH tmpdata AS
(
   ...
)
SELECT ...

Explanation: WITH and SELECT belong together; they are part of the same query. Therefore, in your example, Oracle complains about the "missing SELECT" when it reaches the (unexpected) INSERT after parsing the WITH clause.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号