--Program : syns.sql --Purpose : To find and display a list of all accessible synonyms and the objects referred by the synonyms that match a given criteria --Usage : SQL>@syns [owner[%].][[%]synonym_name|ALL|/] --Notes : The owner name, if omiited, defaults to the current user. --Example : SQL>@syns / -- displays a list of all synonyms owner by the current user. -- SQL>@syns ALL -- displays a list of all synonyms owner by the current user. -- SQL>@syns SCOTT.EMP -- displays a list of all synonyms named like EMP% and owned by all users named like SCOTT%. --Author : Ram Razdan , ramrazdan@yahoo.com --License : Free for public use, amendment and distribution. -- Please refer https://ramrazdan.tripod.com/termsofuse.txt for full details. --Revision : Version Date Server/OS Comments -- 1.0 Oct,2000 Oracle7.3/SunOS Initial Revision. -- 1.1 Apr,2001 Oracle8.1/Win98 Testing Only. -- 1.2 Apr,2001 Oracle8.1/Win98 Remove the outer join to check status of a synonym. -- Oracle never flags a synonym as an INVALID object even if -- the object it refers does not exist. This only causes problem -- at run time with errors like "Synonym translation no longer valid" -- The purpose of the outer join was to identify such synonyms and -- take corrective action. However the performance overhead is quite -- significant and thus has been commented out. -- --SET LINESIZE 132 PAGESIZE 200 SET FEEDBACK OFF UNDEFINE v_validate_synonyms_yn ACCEPT v_validate_synonyms_yn CHAR PROMPT 'Validate Synonyms (Y|[N]) (NOTE: Validation may take some time):' VARIABLE v_table_name VARCHAR2(30) EXECUTE :v_table_name := '&1'; COLUMN "Synonym Reference" FORMAT A35 COLUMN "Object Reference" FORMAT A35 COLUMN "Object Type" FORMAT A15 COLUMN "Obj. Status" FORMAT A10 COLUMN "Syn. Status" FORMAT A10 SELECT syn.owner||'.'||syn.synonym_name "Synonym Reference" ,syn.table_owner||'.'||syn.table_name "Object Reference" ,NVL(obj.object_type,'UNKNOWN') "Object Type" ,NVL(obj.status,'UNKNOWN') "Obj. Status" ,DECODE(obj.object_name ,NULL,'INVALID' ,'VALID') "Syn. Status" FROM all_synonyms syn ,all_objects obj WHERE syn.synonym_name LIKE DECODE(SUBSTR(UPPER(:v_table_name),INSTR(UPPER(:v_table_name),'.')+1) ,'ALL',NULL ,'/' ,NULL ,SUBSTR(UPPER(:v_table_name),INSTR(UPPER(:v_table_name),'.')+1))||'%' AND syn.owner LIKE NVL(SUBSTR(UPPER(:v_table_name),1,INSTR(UPPER(:v_table_name),'.')-1),USER)||'%' AND NVL('&v_validate_synonyms_yn','N') = 'Y' AND syn.table_owner = obj.owner(+) AND syn.table_name = obj.object_name(+) ORDER BY obj.object_type / SELECT syn.owner||'.'||syn.synonym_name "Synonym Reference" ,syn.table_owner||'.'||syn.table_name "Object Reference" FROM all_synonyms syn WHERE syn.synonym_name LIKE DECODE(SUBSTR(UPPER(:v_table_name),INSTR(UPPER(:v_table_name),'.')+1) ,'ALL',NULL ,'/' ,NULL ,SUBSTR(UPPER(:v_table_name),INSTR(UPPER(:v_table_name),'.')+1))||'%' AND syn.owner LIKE NVL(SUBSTR(UPPER(:v_table_name),1,INSTR(UPPER(:v_table_name),'.')-1),USER)||'%' AND NVL('&v_validate_synonyms_yn','N') != 'Y' / SET FEEDBACK ON -- Performance Logs used for amendment version 1.2 , these readings were taken from the System Monitor Log of Windows 98. -- Each Line Represents a reading taken at every second interval. The difference in the number of readings itself is significant --Kernel: Processor Usage (%),File System: Bytes read/second,File System: Reads/second,File System: Bytes written/second,File System: Writes/second --2,511109958,272734,123637650,29739 --2,511100872,272719,123633373,29707 -- start of query (approx) without the outer join --37,511099960,272713,123624997,29673 --100,511099960,272713,123625034,29679 --10,511100872,272719,123629168,29687 --4,511100872,272719,123629205,29693 -- end of query (approx) without the outer join --2,511100872,272719,123629241,29699 --4,511100872,272719,123633409,29713 --4,511100872,272719,123633445,29719 --3,511100872,272719,123637577,29727 --Kernel: Processor Usage (%),File System: Bytes read/second,File System: Reads/second,File System: Bytes written/second,File System: Writes/second --3,494559239,265230,120940328,27782 --1,494559239,265230,120948556,27792 --2,494559239,265230,120956784,27802 --2,494559239,265230,120960916,27810 -- start of query (approx) with outer join --90,495616719,265746,120977336,27824 --100,496788175,266318,120997853,27840 --100,497863375,266842,121090563,27892 --100,499119064,267434,121166377,27935 --100,500173784,267949,121170511,27943 --100,500513752,268115,121170549,27949 --100,500847576,268277,121178779,27961 --100,501167064,268434,121240257,27995 --100,501455832,268575,121244391,28003 --100,501765080,268726,121307917,28040 --100,502074328,268877,121307955,28046 --100,502381528,269027,121369433,28084 --100,502666200,269166,121379711,28094 --100,502981592,269320,121379749,28100 --100,503288792,269470,121383883,28108 --100,503606232,269625,121437169,28140 --100,503903192,269770,121437207,28146 --100,504216536,269923,121441341,28154 --100,504505304,270064,121441379,28160 --100,504814552,270215,121492617,28191 --100,505113560,270360,121496751,28199 --100,505455576,270528,121496789,28205 --100,505850840,270721,121613563,28268 --100,506258392,270920,121670945,28302 --100,506565592,271053,121785671,28364 --100,506762200,271149,121988461,28469 --100,506919896,271225,122148243,28554 --100,507288536,271391,122240441,28604 --22,507302104,271406,122245599,28612 --3,507302104,271406,122249732,28620 -- end of query (approx) with outer join --1,507302104,271406,122249768,28626 --2,507302104,271406,122249804,28632 --2,507302104,271406,122253936,28640 --2,507302104,271406,122253972,28646 --3,507302104,271406,122254008,28652