The view V$FIXED_VIEW_DEFINITION contains the definition of all V$ views. However, the datatype is VARCHAR2(4000), so only the first 4000 characters of the view's body are displayed:
SELECT column_name, data_type, data_length
FROM dba_tab_cols
WHERE table_name = 'V_$FIXED_VIEW_DEFINITION';
COLUMN_NAME DATA_TYPE DATA_LENGTH
--------------- --------- -----------
VIEW_NAME VARCHAR2 128
VIEW_DEFINITION VARCHAR2 4000
CON_ID NUMBER 22
This works fine for views which are shorter, but for others, like V$SESSION, the query text stops right after character 4000:
SELECT * FROM v$fixed_view_definition WHERE view_name = 'GV$SESSION';
VIEW_NAME VIEW_DEFINITION
---------- --------------------------------------------
GV$SESSION select s.inst_id, ... ,decode(bitand(s.ksuse
here it stops abruptly ^
Now, obviously, Oracle has stored the full text somewhere, and the function DBMS_UTILITY. EXPAND_SQL_TEXT T reconstructs the full query, but not without doing strange things to the query like quoting all columns, introducing alias etc:
DECLARE
c CLOB;
i NUMBER := 1;
linelen CONSTANT NUMBER := 100;
BEGIN
DBMS_UTILITY.EXPAND_SQL_TEXT('SELECT * FROM V$SESSION', c);
LOOP
EXIT WHEN i > DBMS_LOB.GETLENGTH(c);
DBMS_OUTPUT.PUT_LINE(DBMS_LOB.SUBSTR(c, linelen, i));
i := i + linelen;
END LOOP;
END;
/
SELECT "A1"."SADDR" "SADDR","A1"."SID" "SID","A1"."SERIAL#" "SERIAL#","A1"."AUDS
ID" "AUDSID","A1"."PADDR" "PADDR","A1"."USER#" "USER#","A1"."USERNAME" "USERNAME
...
So, where is the rest of the V$ query bodies?