简体   繁体   中英

Check Oracle Version and Then run a sub-query

I am trying to run the sub-query based on version in Oracle. Since oracle released the new version 21c have to modify the query in that way.

I would like to check if the version is 19c then take the value from sys.aud$ else take the value AUDSYS.AUD$UNIFIED.

select version,
CASE 
WHEN version <= '19.0.0.0.0' THEN (select * from sys.aud$)


ELSE
(select * from AUDSYS.AUD$UNIFIED)
END version_group

from v$Instance;

I am getting ORA-00913: too many values as the error.

If you are using PL/SQL then you can use conditional compilation. For example:

DECLARE
  v_cur SYS_REFCURSOR;
BEGIN
  OPEN v_cur FOR
    select v.version, s.*
    from v$Instance v
         CROSS JOIN 
           $IF DBMS_DB_VERSION.VER_LE_19
           $THEN
             sys.aud$ s
           $ELSE
             AUDSYS.AUD$UNIFIED s
           $END
    ;
END;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM