Oracle SQL: Understanding the behavior of SYS_GUID() when present in an inline view?

后端 未结 3 1231
失恋的感觉
失恋的感觉 2020-12-29 05:57

Here is the example SQL in question; The SQL should run on any Oracle DBMS (I\'m running 11.2.0.2.0).

Note how the UUID values are different (one has 898 the other

3条回答
  •  清歌不尽
    2020-12-29 06:26

    The NO_MERGE hint "fixes" it. Prevents Oracle from re-writing the inline view.

    WITH data AS (SELECT /*+ NO_MERGE */
                        SYS_GUID () uuid FROM DUAL)
    SELECT uuid, uuid
      FROM data
    

    From the docs:

    The NO_MERGE hint instructs the optimizer not to combine the outer query and any inline view queries into a single query.This hint lets you have more influence over the way in which the view is accessed.

    SQL Fiddle with the NO_MERGE hint applied:

    I'm still struggling to understand/articulate how the query is being re-written in such a way that sys_guid() would be called twice. Perhaps it is a bug; but I tend to assume it is a bug in my own thoughts/code.

提交回复
热议问题