The use of an ORDER BY
within an INSERT SELECT
is not pointless as long as it can change the content of the inserted data, i.e. with a sequence NEXTVAL
included in the SELECT
clause. And this even if the inserted rows won't be sorted when fetched - that's the role of your ORDER BY
clause in your SELECT
clause when accessing the rows.
For such a goal, you can use a work-around placing your ORDER BY
clause in a sub-query, and it works:
INSERT INTO myTargetTable
(
SELECT mySequence.nextval, sq.* FROM
( SELECT f1, f2, f3, ...fx
FROM mySourceTable
WHERE myCondition
ORDER BY mySortClause
) sq
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…