home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / CATEXP.SQL < prev    next >
Encoding:
Text File  |  1995-05-09  |  44.4 KB  |  1,108 lines

  1. rem 
  2. rem $Header: catexp.sql 7020100.1 94/09/23 22:14:46 cli Generic<base> $ expvew.sql 
  3. rem 
  4. Rem Copyright (c) 1987 by Oracle Corporation
  5. Rem NAME
  6. REM    CATEXP.SQL - CATalog EXPort/import sql script
  7. Rem  FUNCTION
  8. Rem    Creates internal views for Export/Import utility
  9. Rem  NOTES
  10. Rem    Must be run when connected to SYS or INTERNAL.
  11. Rem
  12. Rem    This file is organized into 3 sections:
  13. Rem    Section 1: Views needed by BOTH export and import
  14. Rem    Section 2: Views required by import ONLY
  15. Rem     Section 3: Views required by export ONLY
  16. Rem
  17. Rem     Import does not currently require any views of its own. The views
  18. Rem     used by both tools are moved to the top so that a user doing an import
  19. Rem     only has to run part of this file. Since there are common views
  20. Rem     a separate file called catimp.sql was not created for now for
  21. Rem    maintenance reasons.
  22. Rem
  23. Rem    No views depend on catalog.sql. This script can be run standalone.
  24. Rem
  25. Rem  MODIFIED
  26. Rem     vraghuna   08/19/94 -  move views reqd by both imp and exp to the top
  27. Rem     vraghuna   08/18/94 -  move compatibility checks from sql.bsq
  28. Rem     vraghuna   08/15/94 -  bug 227714 - add exu7cpo
  29. Rem     jloaiza    07/08/94 -  bitand modified column
  30. Rem     vraghuna   06/20/94 -  add support for hash cluster functions
  31. Rem     vraghuna   06/10/94 -  bug 218372 - speed up exu7del
  32. Rem     vraghuna   06/09/94 -  bug 219654 - add NVLs for ||l and cache params
  33. Rem     vraghuna   05/16/94 -  bug 215597 - change exu7snaplu also
  34. Rem     vraghuna   05/12/94 -  bug 215597 - change exu7snapl to exclude slog
  35. Rem     vraghuna   04/24/94 -  bug 211989 - add create roles but not drop
  36. Rem     ltung      03/02/94 -  merge changes from branch 1.15.710.1
  37. Rem     vraghuna   02/09/94 -  add exu7ver for version control
  38. Rem     vraghuna   02/02/94 -  bug 190236 - add outer join to exu7ord in exu7ve
  39. Rem     vraghuna   01/17/94 -  bug 191751 - add support for deferred RPC/RepCat
  40. Rem     vraghuna   01/12/94 -  bug 191750 - add support for refresh groups
  41. Rem     vraghuna   01/11/94 -  bug 191749 - add support for job queues exu7jbq
  42. Rem     vraghuna   01/11/94 -  bug 193733 - use basename in incr trigger views
  43. Rem     vraghuna   01/11/94 -  bug 193732 - fix exu7del for trigs, pkg bodies
  44. Rem     vraghuna   01/10/94 -  bug 192781 - add basetable name for trigger view
  45. Rem     vraghuna   12/30/93 -  bug 192652 - change MM to MI for exu7spr
  46. Rem     vraghuna   12/21/93 -  bug 191879 - grants issued twice
  47. Rem     vraghuna   12/06/93 -  bug 186073 - add read only tablespaces
  48. Rem     vraghuna   08/18/93 -  bug 174029 - moving role creation to sql.bsq
  49. Rem     vraghuna   07/07/93 -  add support for updatable snapshots
  50. Rem     vraghuna   06/17/93 -  bug 166480 - add exu7erc for resource costs
  51. Rem     vraghuna   06/17/93 -  bug 168261 - imp_full_database needs insert priv
  52. Rem     vraghuna   06/17/93 -  bug 166482 - export role passwords
  53. Rem     vraghuna   05/27/93 -  bug 166484 - add audt to exu7spr
  54. Rem     ltung      05/16/93 -  export parallel/cache parameters 
  55. Rem     vraghuna   03/15/93 -  bug 140485 - incrementals on tables with constra
  56. Rem     vraghuna   03/12/93 -  bug 152906 - add tspname to exu7uscu 
  57. Rem     vraghuna   01/27/93 -  bug 146283 - add exu7usc 
  58. Rem     vraghuna   12/18/92 -  bug 143375 - break up exu7col 
  59. Rem     vraghuna   12/02/92 -  bug 139302 - speed up exu7colnn 
  60. Rem     tpystyne   11/07/92 -  use create or replace view 
  61. Rem     vraghuna   10/28/92 -  bug 130560 - add exu7ful 
  62. Rem     vraghuna   10/23/92 -  bug 135594 - remove exu7inv and exu7invu 
  63. Rem     glumpkin   10/20/92 -  Renamed from EXPVEW.SQL 
  64. Rem     vraghuna   10/14/92 -  bug 131957 - add field to exu7sto and exu7stou 
  65. Rem     vraghuna   07/14/92 -  bug 115048 - support for analyze statement 
  66. Rem     cheigham   06/24/92 -  add exu7colnn view 
  67. Rem     cheigham   06/22/92 -  fix cdef$,col$ joins to accommodate changes for 
  68. Rem     jbellemo   06/12/92 -  add mapping for MLSLABEL 
  69. Rem     vraghuna   06/03/92 -  bug 39511 - add exu7grs 
  70. Rem     cheigham   05/27/92 -  speed up exu7vew 
  71. Rem     cheigham   02/13/92 -  add select any to imp_full_database 
  72. Rem     cheigham   02/13/92 -  grant alter any table to imp_full_database 
  73. Rem     cheigham   01/29/92 -  export altered clusters in inc. exports 
  74. Rem     cheigham   01/09/92 -  add more privs to imp_full_database 
  75. Rem     cheigham   11/15/91 -  fix object codes 
  76. Rem     cheigham   11/06/91 -  fix inc. trigger views 
  77. Rem     cheigham   11/02/91 -  merge in hash changes 
  78. Rem     cheigham   10/11/91 -  view names: exu -> exu7
  79. Rem     cheigham   09/27/91 -  add snapshot views 
  80. Rem     sksingh    09/30/91 -  merge changes from branch 1.13.50.1 
  81. Rem     sksingh    09/23/91 -  replace spare1,2,3 with match, refact, enabled
  82. Rem     agupta     09/20/91 -  add support for lists/groups storage params 
  83. Rem     agupta     08/16/91 -  enable|disable constraints 
  84. Rem     agupta     07/30/91 -  7037 - views not created in dependency or
  85. Rem     agupta     07/02/91 -  timestamp syntax for procedures 
  86. Rem     agupta     06/21/91 -  fix errors in exurlg 
  87. Rem     agupta     06/14/91 -  user$ column name changes 
  88. Rem     agupta     05/31/91 -  add userid to tablespace quota view 
  89. Rem     agupta     05/04/91 -  fix unique constraints bug 
  90. Rem     agupta     04/16/91 -  fix auditing views 
  91. Rem     jwijaya    04/12/91 -  remove LINKNAME IS NULL 
  92. Rem     rkooi      04/01/91 -  add 'o.linkname IS NULL' clause 
  93. Rem     Gupta      02/26/90 -  Lots of modifications for V7
  94. Rem     Hong       10/31/88 -  don't export quotas of 0
  95. Rem     Hong       09/21/88 -  allow null precision/scale
  96. Rem     Hong       09/10/88 -  fix outer joins
  97. Rem     Hong       08/10/88 -  get default/temp tablespace in exuusr
  98. Rem     Hong       07/01/88 -  get obj id in some views
  99. Rem     Hong       06/10/88 -  remove userid != 0 from views
  100. Rem     Hong       04/28/88 -  comment$ moved to com$
  101. Rem     Hong       03/24/88 -  add audit field to exu7seq
  102. Rem     Hong       03/07/88 -  deal with initrans, maxtrans
  103. Rem                            add views for constraints, sequence #
  104. Rem     Hong       02/01/88 -  add exuico and exuicou
  105. Rem                            temporary commented out col$.default$
  106. Rem     Hong       02/01/88 -  fix exufil to use v$dbfile directly
  107. Rem     Hong       12/12/87 -  fix exutbs
  108. Rem     Hong       12/07/87 -  handle min extents 
  109. Rem
  110.  
  111. set echo on;
  112.  
  113. rem this role allows the grantee to perform full database exports
  114. rem including incremental exports
  115. CREATE ROLE exp_full_database;
  116. grant select any table to exp_full_database;
  117. grant backup any table to exp_full_database;
  118. GRANT insert,update,delete
  119.  ON sys.incexp
  120.  TO exp_full_database;
  121. GRANT insert,update,delete
  122.  ON sys.incvid
  123.  TO exp_full_database;
  124. GRANT insert,update,delete
  125.  ON sys.incfil
  126.  TO exp_full_database;
  127. grant exp_full_database to dba;
  128.  
  129. rem this role allows the grantee to perform full database imports
  130. CREATE ROLE imp_full_database;
  131. grant become user to imp_full_database;
  132. grant create any cluster to imp_full_database;
  133. grant create any index to imp_full_database;
  134. grant create any table to imp_full_database;
  135. grant create any procedure to imp_full_database;
  136. grant create any sequence to imp_full_database;
  137. grant create any snapshot to imp_full_database;
  138. grant create any synonym to imp_full_database;
  139. grant create any trigger to imp_full_database;
  140. grant create any view to imp_full_database;
  141. grant create profile to imp_full_database;
  142. grant create public database link to imp_full_database;
  143. grant create database link to imp_full_database;
  144. grant create public synonym to imp_full_database;
  145. grant create rollback segment to imp_full_database;
  146. grant create role to imp_full_database;
  147. grant create tablespace to imp_full_database;
  148. grant create user to imp_full_database;
  149. grant audit any to imp_full_database;
  150. grant comment any table to imp_full_database;
  151. grant alter any table to imp_full_database;
  152. grant select any table to imp_full_database;
  153. grant execute any procedure to imp_full_database;
  154. grant insert any table to imp_full_database;
  155.  
  156. rem for import of incremental export files
  157. grant drop any cluster to imp_full_database;
  158. grant drop any index to imp_full_database;
  159. grant drop any table to imp_full_database;
  160. grant drop any procedure to imp_full_database;
  161. grant drop any sequence to imp_full_database;
  162. grant drop any snapshot to imp_full_database;
  163. grant drop any synonym to imp_full_database;
  164. grant drop any trigger to imp_full_database;
  165. grant drop any view to imp_full_database;
  166. grant drop profile to imp_full_database;
  167. grant drop public database link to imp_full_database;
  168. grant drop public synonym to imp_full_database;
  169. grant drop rollback segment to imp_full_database;
  170. grant drop any role to imp_full_database;
  171. grant drop tablespace to imp_full_database;
  172. grant drop user to imp_full_database;
  173.  
  174. grant imp_full_database to dba;
  175.  
  176. Rem
  177. Rem  ***************************************************
  178. Rem  Section 1: Views required by BOTH export and import
  179. Rem  ***************************************************
  180. Rem 
  181. rem block size
  182. CREATE OR REPLACE view exu7bsz(blocksize) AS
  183.        SELECT ts$.blocksize
  184.        FROM   sys.ts$ ts$
  185. /
  186. grant select on exu7bsz to public;
  187.  
  188. rem all users
  189. CREATE OR REPLACE view exu7usr 
  190.                    (name, userid, passwd, defrole, datats, tempts, profile#, 
  191.                 profname) AS 
  192.        SELECT u.name, u.user#, DECODE(u.password, 'N', '', u.password), 
  193.               DECODE(u.defrole, 0, 'N', 1, 'A', 'L'), ts1.name, ts2.name,
  194.           u.resource$, p.name
  195.        FROM sys.user$ u, sys.ts$ ts1, sys.ts$ ts2, sys.profname$ p
  196.        WHERE u.datats# = ts1.ts# and u.tempts# = ts2.ts# and u.type = 1 and
  197.              u.resource$ = p.profile#
  198. /
  199. CREATE OR REPLACE view exu7usru AS                 /* current user */
  200.        SELECT * from exu7usr WHERE userid = UID
  201. /
  202. grant select on exu7usru to public;
  203.  
  204. rem check if user has priv to do a full db export
  205. CREATE OR REPLACE view exu7ful(role) as
  206. select u.name
  207. from x$kzsro, user$ u
  208. where kzsrorol!=uid and kzsrorol!=1 and u.user#=kzsrorol
  209. /
  210. grant select on sys.exu7ful to public;
  211.  
  212.  
  213. Rem
  214. Rem  ****************************************
  215. Rem  Section 2: Views required by import ONLY
  216. Rem  ****************************************
  217. Rem 
  218. Rem  None for now.
  219. Rem
  220. Rem  ****************************************
  221. Rem  Section 3: Views required by export ONLY
  222. Rem  ****************************************
  223. Rem 
  224. rem all tables
  225. CREATE OR REPLACE view exu7tab 
  226.                    (objid,name, owner, ownerid, tablespace, fileno, blockno,
  227.             audit$, comment$, clusterflag, mtime, modified, 
  228.                 pctfree$,
  229.                     pctused$, initrans, maxtrans, parallel, cache) AS
  230.        SELECT o$.obj#,o$.name, u$.name, o$.owner#, ts$.name, t$.file#, 
  231.           t$.block#, t$.audit$, c$.comment$, NVL(t$.clu#, 0), o$.mtime,
  232.           bitand(t$.modified,1), t$.pctfree$, t$.pctused$, t$.initrans, 
  233.           t$.maxtrans, NVL(t$.spare1,0), NVL(t$.spare2,0)
  234.        FROM sys.tab$ t$, sys.obj$ o$, sys.ts$ ts$, sys.user$ u$, sys.com$ c$
  235.        WHERE  t$.obj# = o$.obj# and t$.ts# = ts$.ts# and 
  236.               u$.user# = o$.owner# and o$.obj# = c$.obj#(+) 
  237.           and c$.col#(+) is null
  238. /
  239. rem tables for incremental export: modified, altered or new
  240. CREATE OR REPLACE view exu7tabi AS 
  241.        SELECT t.* from exu7tab t,incexp i, incvid v
  242.        WHERE t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND
  243.              NVL(i.type,2) = 2 AND  
  244.              (bitand(t.modified,1) = 1 OR t.mtime > i.itime OR 
  245.               NVL(i.expid,9999) > v.expid)
  246. /         
  247. rem tables for cumulative export: modified, last export was inc, altered or new
  248. CREATE OR REPLACE view exu7tabc AS 
  249.        SELECT t.* from exu7tab t,incexp i, incvid v
  250.        WHERE  t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND 
  251.              NVL(i.type,2) = 2 AND 
  252.               (bitand(t.modified,1) = 1 OR i.itime > NVL(i.ctime,
  253.                                                 TO_DATE('01-01-00','DD-MM-YY'))
  254.                OR t.mtime > i.itime OR NVL(i.expid,9999) > v.expid)
  255. /
  256. rem current user's tables 
  257. CREATE OR REPLACE view exu7tabu AS
  258.        SELECT * from exu7tab WHERE ownerid = uid
  259. /
  260. grant select on exu7tabu to public;
  261.  
  262. rem not null constraints on columns
  263. CREATE OR REPLACE view exu7colnn (tobjid, colid, conname, isnull, enabled) AS
  264.       SELECT cc$.obj#, cc$.col#, 
  265.               DECODE(SUBSTR(con$.name,1,5), 'SYS_C', '', NVL(con$.name, '')),
  266.           1, NVL(cd$.enabled, 0)
  267.       FROM  sys.con$ con$, sys.cdef$ cd$, sys.ccol$ cc$
  268.       WHERE cc$.con# = cd$.con# and
  269.             cd$.con# = con$.con# and cd$.type =7
  270. /
  271. CREATE OR REPLACE view exu7col_temp
  272.                    (tobjid, towner, townerid, tname, name, length, precision, 
  273.             scale, type, isnull, conname, colid, comment$, --default$, 
  274.                 dfltlen, enabled) AS
  275.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  276.               c$.precision, c$.scale, c$.type#, NVL(cn.isnull,0), 
  277.               cn.conname, c$.col#, com$.comment$,-- c$.default$, 
  278.           NVL(c$.deflength, 0), cn.enabled
  279.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$, sys.com$ com$,
  280.         sys.exu7colnn cn
  281.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  282.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+) and
  283.          c$.obj# = cn.tobjid and c$.col# = cn.colid
  284.   union all
  285.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  286.               c$.precision, c$.scale, c$.type#, 0,
  287.               null, c$.col#, com$.comment$,-- c$.default$, 
  288.           NVL(c$.deflength, 0), to_number(null)
  289.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$, sys.com$ com$
  290.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  291.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+)
  292.              and not exists 
  293.               (select null from sys.exu7colnn cn
  294.              where c$.obj# = cn.tobjid and c$.col# = cn.colid)
  295. /
  296. create or replace view exu7col
  297.    (tobjid, towner, townerid, tname, name, length, precision,
  298.     scale, type, isnull, conname, colid, comment$, default$,
  299.     dfltlen, enabled) AS
  300.  select tobjid, towner, townerid, v$.tname, v$.name, v$.length, v$.precision,
  301.                     v$.scale, type, isnull, conname, colid, comment$, default$,
  302.                     dfltlen, enabled
  303.    from exu7col_temp v$, sys.col$ c$
  304.     where c$.obj# = v$.tobjid and c$.col# = v$.colid
  305. /
  306.  
  307. CREATE OR REPLACE view exu7colu AS                 /* current user's columns */
  308.        SELECT * from exu7col WHERE townerid = uid
  309. /
  310. grant select on exu7colu to public;
  311.  
  312. rem all columns for index
  313. CREATE OR REPLACE view exu7ico 
  314.                    (tobjid, towner, townerid, tname, name, length, precision,
  315.             scale, type, isnull, conname, colid, comment$, default$, 
  316.             dfltlen, enabled) AS
  317.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, 0, 0, 0, 0, 0, '',
  318.               i$.pos#, NULL, NULL, 0, 0
  319.        FROM sys.col$ c$, sys.icol$ i$, sys.obj$ o$, sys.user$ u$
  320.        WHERE c$.obj# = i$.bo# and c$.col# = i$.col# and 
  321.          i$.obj# = o$.obj# and o$.owner# = u$.user#
  322. /
  323. CREATE OR REPLACE view exu7icou AS           /* current user's columns */
  324.        SELECT * from exu7ico WHERE townerid = uid
  325. /
  326. grant select on exu7icou to public;
  327.  
  328. rem all users' default roles
  329. CREATE OR REPLACE view exu7dfr (name, userid, role, roleid) AS
  330.        SELECT u$.name, u$.user#, u1$.name, u1$.user#
  331.        FROM sys.user$ u$, sys.user$ u1$, sys.defrole$ d$
  332.        WHERE u$.user# = d$.user# and u1$.user# = d$.role#
  333. /
  334. rem all roles
  335. CREATE OR REPLACE view exu7rol (role, password) AS    /* enumerate all roles */
  336.        SELECT name, password
  337.        FROM sys.user$ 
  338.        WHERE type = 0 and name not in 
  339.             ('CONNECT', 'RESOURCE', 'DBA', 'PUBLIC', '_NEXT_USER', 
  340.          'EXP_FULL_DATABASE', 'IMP_FULL_DATABASE')
  341. /
  342. rem all role grants
  343. CREATE OR REPLACE view exu7rlg
  344.                    (grantee, granteeid, role, roleid, admin, sequence) AS
  345.     SELECT u1$.name, u1$.user#, u2$.name, u2$.user#, 
  346.            NVL(g$.option$, 0), g$.sequence#
  347.        FROM sys.user$ u1$, sys.user$ u2$, sys.sysauth$ g$ 
  348.     WHERE u1$.user# = g$.grantee# AND u2$.user# = g$.privilege# AND 
  349.           g$.privilege# > 0
  350. /
  351. rem all system privs, type is 1 for user, 0 for role
  352. CREATE OR REPLACE view exu7spv (grantee, granteeid, priv, wgo, sequence) AS
  353.        SELECT u1$.name, u1$.user#, m$.name, NVL(a$.option$,0), a$.sequence#
  354.        FROM sys.sysauth$ a$, sys.system_privilege_map m$, sys.user$ u1$
  355.        WHERE a$.grantee# = u1$.user# and a$.privilege# = m$.privilege AND 
  356.          u1$.name not in 
  357.          ('CONNECT', 'RESOURCE', 'DBA', 'PUBLIC', '_NEXT_USER', 
  358.          'EXP_FULL_DATABASE', 'IMP_FULL_DATABASE')
  359. /
  360. rem all grants
  361. CREATE OR REPLACE view exu7grn (objid, grantor, grantorid, grantee, priv, wgo,
  362.                     creatorid, sequence) AS
  363.        SELECT t$.obj#, ur$.name, t$.grantor#, ue$.name, 
  364.               m$.name, NVL(t$.option$,0), o$.owner#, t$.sequence#
  365.        FROM sys.objauth$ t$, sys.obj$ o$, sys.user$ ur$,
  366.             sys.table_privilege_map m$, sys.user$ ue$
  367.        WHERE o$.obj# = t$.obj# AND t$.privilege# = m$.privilege AND
  368.              t$.col# IS NULL AND t$.grantor# = ur$.user# AND
  369.              t$.grantee# = ue$.user#
  370. /
  371.  
  372. rem just SYS's grants
  373. CREATE OR REPLACE view exu7grs (objid, name) AS
  374.        SELECT t$.obj#, o$.name
  375.        FROM sys.objauth$ t$, sys.obj$ o$
  376.        WHERE o$.obj# = t$.obj# 
  377.     AND t$.col# is null
  378.     AND t$.grantor# = 0
  379. /
  380.  
  381. rem first level grants
  382. CREATE OR REPLACE view exu7grnu AS
  383.        SELECT * from exu7grn WHERE grantorid = UID AND creatorid = UID
  384. /
  385. grant select on exu7grnu to public;
  386.  
  387. rem all column grants
  388. CREATE OR REPLACE view exu7cgr 
  389.                    (objid, grantor, grantorid, grantee, creatorid, cname, 
  390.                 priv, sequence, wgo) AS
  391.        SELECT c$.obj#, ur$.name, c$.grantor#, ue$.name, o$.owner#, cl$.name,
  392.               m$.name, c$.sequence#, NVL(c$.option$,0)
  393.        FROM sys.objauth$ c$, sys.obj$ o$, sys.user$ ur$, sys.user$ ue$,
  394.             sys.table_privilege_map m$, sys.col$ cl$
  395.        WHERE c$.grantor# = ur$.user# AND c$.grantee# = ue$.user# AND
  396.              c$.obj# = o$.obj# AND c$.privilege# = m$.privilege AND 
  397.              c$.obj# = cl$.obj# AND c$.col# = cl$.col#
  398. /
  399. rem first level grants
  400. CREATE OR REPLACE view exu7cgru AS
  401.        SELECT * from exu7cgr WHERE grantorid = UID AND creatorid = UID
  402. /
  403. grant select on exu7cgru to public;
  404.  
  405. rem all indexes
  406. CREATE OR REPLACE view exu7ind 
  407.                    (iobjid, iname, iowner, iownerid, ispace, ifileno, iblockno,
  408.             btname, btobjid, btowner, btownerid, unique$,
  409.             cluster$, pctfree$, initrans, maxtrans, blevel)  AS
  410.        SELECT i$.obj#, i$.name, ui$.name, i$.owner#, ts$.name, ind$.file#,
  411.           ind$.block#, t$.name, t$.obj#, ut$.name, t$.owner#,
  412.               ind$.unique$, DECODE(t$.type, 3, 1, 0), ind$.pctfree$, 
  413.           ind$.initrans, ind$.maxtrans, NVL(ind$.blevel,-1)
  414.        FROM  sys.obj$ t$, sys.obj$ i$, sys.ind$ ind$,
  415.          sys.user$ ui$, sys.user$ ut$, sys.ts$ ts$
  416.        WHERE ind$.bo# = t$.obj# AND ind$.obj# = i$.obj# AND
  417.          ts$.ts# = ind$.ts# AND i$.owner# = ui$.user# AND
  418.              t$.owner# = ut$.user# AND (unique$=0 OR 
  419.          NOT EXISTS (SELECT * from sys.con$ c$
  420.              WHERE c$.owner# = i$.owner#
  421.                          AND   c$.name = i$.name))
  422. /
  423. rem current user indexes
  424. CREATE OR REPLACE view exu7indu AS
  425.        SELECT * from exu7ind WHERE iownerid = UID and btownerid = UID
  426. /
  427. grant select on exu7indu to public;
  428. rem dependency order
  429. CREATE OR REPLACE view exu7ord (dlevel, obj#) AS
  430.        SELECT MAX(LEVEL), d_obj# from sys.dependency$
  431.        CONNECT BY PRIOR d_obj# = p_obj#
  432.        GROUP BY d_obj#
  433. /
  434. grant select on exu7ord to public;
  435. rem all views 
  436. CREATE OR REPLACE view exu7vew (vobjid,vname, vlen, vtext, vowner, vownerid,
  437.             vaudit, vcomment, vcname, vlevel) AS
  438.        SELECT
  439.     o$.obj#, o$.name, v$.textlength, v$.text, u$.name, o$.owner#, 
  440.             v$.audit$, com$.comment$, 
  441.           DECODE(SUBSTR(c$.name,1,5), 'SYS_C', '', NVL(c$.name, '')),
  442.           d$.dlevel
  443.        FROM sys.obj$ o$, sys.view$ v$, sys.user$ u$, sys.cdef$ cd$,
  444.             sys.con$ c$, sys.com$ com$, exu7ord d$
  445.        WHERE v$.obj# = o$.obj# AND o$.owner# = u$.user# AND
  446.          o$.obj# = cd$.obj#(+) AND cd$.con# = c$.con#(+) AND 
  447.              o$.obj# = com$.obj#(+) AND com$.col#(+) IS NULL AND
  448.          o$.obj# = d$.obj#(+)
  449. /
  450. rem views for incremental export: new or last export not valid
  451. rem cannot use union as in exutabi because of long field
  452. CREATE OR REPLACE view exu7vewi AS 
  453.        SELECT vw.* from exu7vew vw, incexp i, incvid v
  454.        WHERE i.name(+) = vw.vname AND i.owner#(+) = vw.vownerid
  455.              AND v.expid < NVL(i.expid, 9999) AND NVL(i.type, 4) = 4
  456. /         
  457. rem views for cumulative export: new, last export was inc or not valid
  458. CREATE OR REPLACE view exu7vewc AS 
  459.        SELECT vw.* from exu7vew vw, incexp i, incvid v
  460.        WHERE vw.vname = i.name(+) AND vw.vownerid = i.owner#(+) AND 
  461.              NVL(i.type,4) = 4 AND
  462.              (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  463.               v.expid < NVL(i.expid, 9999))
  464. /
  465. rem current user's view
  466. CREATE OR REPLACE view exu7vewu AS
  467.        SELECT *    from exu7vew WHERE vownerid = UID
  468. /
  469. grant select on exu7vewu to public;
  470.  
  471. rem all synonyms
  472. CREATE OR REPLACE view exu7syn (synnam, syntab, tabown, tabnode,
  473.                 public$, synown, synownid, syntime) AS
  474.        SELECT o$.name, s$.name, s$.owner, s$.node,
  475.             DECODE(o$.owner#, 1, 1, 0),
  476.              uo$.name, o$.owner#, TO_CHAR(o$.ctime, 'YYMMDDHH24MISS')
  477.        FROM sys.obj$ o$, sys.syn$ s$, sys.user$ us$, sys.user$ uo$
  478.        WHERE s$.obj# = o$.obj# AND o$.owner# = uo$.user# AND
  479.          s$.owner = us$.name(+)
  480. /
  481. rem synonyms for incremental export: new or last export not valid
  482. CREATE OR REPLACE view exu7syni AS 
  483.        SELECT s.* from exu7syn s, incexp i, incvid v
  484.        WHERE s.synnam = i.name(+) AND s.synownid = i.owner#(+) AND 
  485.              NVL(i.type,5) = 5 AND NVL(i.expid,9999) > v.expid
  486. /         
  487. rem synonyms for cumulative export: new, last export was inc or not valid
  488. CREATE OR REPLACE view exu7sync AS 
  489.        SELECT s.* from exu7syn s, incexp i, incvid v
  490.        WHERE  s.synnam  = i.name(+) AND s.synownid = i.owner#(+) AND 
  491.               NVL(i.type,5) = 5 AND
  492.           (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  493.                NVL(i.expid,9999) > v.expid)
  494. /
  495. rem user's synnonyms
  496. CREATE OR REPLACE view exu7synu AS
  497.        SELECT * from exu7syn WHERE synownid = UID
  498. /
  499. grant select on exu7synu to public;
  500.  
  501. rem clustered tables' columns
  502. CREATE OR REPLACE view exu7cco
  503.                    (tname, towner, townerid, cluster$, tcolnam, seq) AS
  504.        SELECT t$.name, u$.name, t$.owner#, c$.name, tc$.name, cc$.col#
  505.        FROM sys.obj$ t$, sys.tab$ tab$, sys.obj$ c$,
  506.         sys.col$ tc$, sys.col$ cc$, sys.user$ u$
  507.        WHERE t$.type = 2 AND t$.obj# = tab$.obj# AND
  508.            tab$.clu# = cc$.obj# AND tab$.obj# = tc$.obj# AND 
  509.              tab$.clu# = c$.obj# AND 
  510.              cc$.segcol# = tc$.segcol# AND t$.owner# = u$.user#
  511. /
  512. rem current user's clustered tables' columns
  513. CREATE OR REPLACE view exu7ccou AS
  514.        SELECT * from exu7cco WHERE townerid = UID
  515. /
  516. grant select on exu7ccou to public;
  517.  
  518. rem all clusters
  519. CREATE OR REPLACE view exu7clu 
  520.                    (objid, owner, ownerid, name, tblspace, size$, fileno,
  521.                 blockno, mtime, pctfree$, pctused$, initrans, maxtrans,
  522.             hashkeys, function, spare4, parallel, cache, 
  523.             functxt , funclen ) AS
  524.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, ts$.name, 
  525.           NVL(c$.size$, -1), c$.file#, c$.block#, o$.mtime, c$.pctfree$, 
  526.               c$.pctused$, c$.initrans, c$.maxtrans, NVL(c$.hashkeys, 0), 
  527.           NVL(c$.func, 1), NVL(c$.spare4,-1), 
  528.           NVL(c$.spare5, 0), NVL(c$.spare6,0),
  529.           cd$.condition, cd$.condlength
  530.        FROM sys.obj$ o$, sys.clu$ c$, sys.ts$ ts$, sys.user$ u$,
  531.         sys.cdef$ cd$
  532.        WHERE o$.obj# = c$.obj# AND c$.ts# = ts$.ts# AND o$.owner# = u$.user#
  533.          AND cd$.obj#(+) = c$.obj# 
  534. /
  535. rem clusters for incremental export: new or last export invalid
  536. rem altered cluster is now exported because its tables are also exported
  537. CREATE OR REPLACE view exu7clui AS 
  538.        SELECT c.* from exu7clu c,incexp i, incvid v
  539.        WHERE c.name  = i.name(+) AND c.ownerid = i.owner#(+) AND
  540.         (c.mtime > i.itime OR NVL(i.expid,9999) > v.expid)
  541. /         
  542. rem clusters for cumulative export: last export was inc or new
  543. rem altered cluster is now exported because its tables are also exported
  544. CREATE OR REPLACE view exu7cluc AS 
  545.        SELECT c.* from exu7clu c,incexp i, incvid v
  546.        WHERE c.name = i.name(+) AND c.ownerid = i.owner#(+) AND 
  547.              NVL(i.type,3) = 3 AND
  548.           (i.itime > NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY'))
  549.         OR c.mtime > i.itime OR NVL(i.expid,9999) > v.expid)
  550. /
  551. rem current user's clusters
  552. CREATE OR REPLACE view exu7cluu AS
  553.        SELECT * from exu7clu WHERE ownerid = UID
  554. /
  555. grant select on exu7cluu to public;
  556.  
  557. rem all storage parameters
  558. CREATE OR REPLACE view exu7sto (ownerid, fileno, blockno, iniext, sext, minext,
  559.                     maxext, pctinc, blocks, lists, groups, extents) AS
  560.        SELECT user#, file#, block#, iniexts, extsize, minexts, maxexts, 
  561.               extpct, blocks, NVL(lists,1), NVL(groups,1), extents
  562.        FROM sys.seg$
  563.  
  564. rem storage parameters for current user's segments
  565. CREATE OR REPLACE view exu7stou AS
  566.        SELECT * from exu7sto WHERE ownerid = UID
  567. /
  568. grant select on exu7stou to public;
  569.  
  570. rem find out correct size of second extent using uet$
  571. CREATE OR REPLACE view exu7tne (fileno, blockno, length) AS
  572.     SELECT segfile#, segblock#, length
  573.     from uet$ where ext# = 1
  574. /
  575. grant select on exu7tne to public;
  576.  
  577. rem all tablespaces
  578. CREATE OR REPLACE view exu7tbs 
  579.                    (id, owner, name, isonline, iniext, sext, pctinc,
  580.             minext, maxext) AS
  581.        SELECT ts$.ts#, 'SYSTEM', ts$.name, 
  582.           DECODE(ts$.online$, 1, 'ONLINE', 4, 'ONLINE', 'OFFLINE'), 
  583.           ts$.dflinit,
  584.              ts$.dflincr, ts$.dflextpct, ts$.dflminext, ts$.dflmaxext
  585.        FROM sys.ts$ ts$ 
  586.        WHERE ts$.online$ in (1, 2, 4) and ts$.ts# != 0
  587. /
  588.  
  589. rem tablespace quotas
  590. CREATE OR REPLACE view exu7tsq(tsname, tsid, uname, userid, maxblocks) AS
  591.        SELECT t$.name, q$.ts#, u$.name, u$.user#, q$.maxblocks
  592.        FROM  sys.ts$ t$, sys.tsq$ q$, sys.user$ u$
  593.        WHERE  q$.user# = u$.user# AND q$.ts# = t$.ts# AND q$.maxblocks != 0
  594. /
  595.  
  596. rem all files
  597. CREATE OR REPLACE view exu7fil(fname, fsize, tsid) AS
  598.        SELECT v$.name, f$.blocks, f$.ts#
  599.        FROM   sys.file$ f$, sys.v$dbfile v$
  600.        WHERE  f$.file# = v$.file#
  601. /
  602.  
  603. rem all database links
  604. CREATE OR REPLACE view exu7lnk 
  605.                    (owner, ownerid, name, user$, passwd, host, public$) AS
  606.        SELECT DECODE(l$.owner#, 1, 'SYSTEM', u$.name), l$.owner#, l$.name, 
  607.               l$.userid, l$.password, l$.host, DECODE(l$.owner#, 1, 1, 0)
  608.        FROM sys.user$ u$, sys.link$ l$
  609.        WHERE u$.user# = l$.owner#
  610. /
  611. CREATE OR REPLACE view exu7lnku AS        /* current user's database links */
  612.        SELECT * from exu7lnk WHERE ownerid = UID
  613. /
  614. grant select on exu7lnku to public;
  615.  
  616. rem all rollback segments
  617. CREATE OR REPLACE view exu7rsg 
  618.                    (owner, name, space$, fileno , blockno, minext, public$) AS 
  619.        SELECT 'SYSTEM', r$.name, ts$.name, r$.file#, r$.block#, s$.minexts,
  620.              DECODE(r$.user#, 1, 1, 0)
  621.        FROM sys.ts$ ts$, sys.undo$ r$, sys.seg$ s$
  622.        WHERE r$.status$ != 1 AND r$.file# = s$.file# AND r$.block# = s$.block#
  623.              AND s$.ts# = ts$.ts# and r$.us# != 0
  624. /
  625.  
  626. rem info on deleted objects EXCEPT snapshots, snapshot logs
  627. CREATE OR REPLACE view exu7del (owner, name, type, type#) AS 
  628.        SELECT u$.name, i$.name, DECODE(i$.type, 2, 'TABLE', 3,
  629.               'CLUSTER', 4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
  630.               7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
  631.              -1, 'TRIGGER', -4, 'PACKAGE BODY'), i$.type
  632.        FROM sys.incexp i$, sys.user$ u$, sys.obj$ o$
  633.        WHERE i$.owner# = u$.user#
  634.              AND i$.type NOT IN (-2,-3)
  635.              AND i$.owner# = o$.owner# (+) /* "+ 0" for sort-merge outer jn */
  636.              AND i$.name   = o$.name (+)
  637.              AND i$.type   = DECODE(o$.type (+), 12, -1, 11, -4, o$.type (+))
  638.              AND o$.owner# is NULL AND o$.linkname is NULL
  639. /
  640.  
  641. rem info on sequence number
  642. CREATE OR REPLACE view exu7seq 
  643.                    (owner, ownerid, name, objid, curval, minval, maxval, 
  644.             incr, cache, cycle, order$, audt) AS
  645.        SELECT u.name, u.user#, o.name, o.obj#, s.highwater, s.minvalue, 
  646.           s.maxvalue, s.increment$, s.cache, s.cycle, s.order$, s.audit$
  647.        FROM sys.obj$ o, sys.user$ u, sys.seq$ s
  648.        WHERE o.obj# = s.obj# AND o.owner# = u.user#
  649. /
  650. CREATE OR REPLACE view exu7sequ AS 
  651.        SELECT * from sys.exu7seq WHERE UID = ownerid
  652. /
  653. grant select on sys.exu7sequ to public;
  654.  
  655. rem contraints on table
  656. CREATE OR REPLACE view exu7con 
  657.                    (objid, owner, ownerid, tname, type, cname, cno, condition,
  658.                     condlength, enabled) AS
  659.        SELECT o.obj#, u.name, c.owner#, o.name, cd.type, c.name,
  660.               c.con#, cd.condition, cd.condlength, NVL(cd.enabled,0)
  661.        FROM sys.obj$ o, sys.user$ u, sys.con$ c, sys.cdef$ cd
  662.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND cd.con# = c.con#
  663. /
  664. CREATE OR REPLACE view exu7conu AS 
  665.        SELECT * from sys.exu7con WHERE UID = ownerid
  666. /
  667. grant select on sys.exu7conu to public;
  668.  
  669. rem referential constraints
  670. CREATE OR REPLACE view exu7ref 
  671.                    (objid, owner, ownerid, tname, rowner, rtname, cname, cno,
  672.                 rcno, action, enabled) AS
  673.        SELECT o.obj#, u.name, c.owner#, o.name, ru.name, ro.name, 
  674.               DECODE(SUBSTR(c.name, 1, 5), 'SYS_C', '', NVL(c.name, '')),
  675.           c.con#, cd.rcon#, NVL(cd.refact,0), NVL(cd.enabled,0)
  676.        FROM sys.user$ u, sys.user$ ru, sys.obj$ o, sys.obj$ ro, 
  677.             sys.con$ c, sys.cdef$ cd
  678.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND ro.obj# = cd.robj# AND
  679.              cd.con# = c.con# AND cd.type = 4 AND ru.user# = ro.owner#
  680. /
  681. CREATE OR REPLACE view exu7refu AS SELECT * from sys.exu7ref WHERE UID = ownerid
  682. /
  683. grant select on sys.exu7refu to public;
  684. rem referential constraints for incremental and cumulative export
  685. rem for tables just exported, i.expid will be greater than v.expid
  686. rem as v.expid is incremented only at the end of the incremental export
  687. rem but i.expid is incremented when the table is exported.
  688. rem USED ONLY WHEN REOCRD = YES
  689. CREATE OR REPLACE view exu7refic AS
  690.        SELECT * from sys.exu7ref 
  691.        WHERE (ownerid, tname) in 
  692.              (SELECT i.owner#, i.name 
  693.               FROM sys.incexp i, sys.incvid v
  694.               WHERE i.expid > v.expid AND i.type = 2)
  695. /
  696. rem referentail constraints for incremental export
  697. rem exutabi will return the correct table name because RECORD = NO
  698. CREATE OR REPLACE view exu7refi AS
  699.        SELECT * from sys.exu7ref
  700.        WHERE (ownerid, tname) in (SELECT ownerid, name from sys.exu7tabi)
  701. /
  702. rem referentail constraints for cumulative export, assuming
  703. rem exutabc will return the correct table name because RECORD = NO
  704. CREATE OR REPLACE view exu7refc AS
  705.        SELECT * from sys.exu7ref
  706.        WHERE (ownerid, tname) in (SELECT ownerid, name from sys.exu7tabc)
  707. /
  708.  
  709. rem contraint column list
  710. CREATE OR REPLACE view exu7ccl (ownerid, cno, colname, colno) AS
  711.        SELECT o.owner#, cc.con#, c.name, cc.pos#
  712.        FROM sys.obj$ o, sys.col$ c, sys.ccol$ cc
  713.        WHERE o.obj# = cc.obj# AND c.obj# = cc.obj# AND cc.col# = c.col#
  714. /
  715. CREATE OR REPLACE view exu7cclu AS
  716.        SELECT * from sys.exu7ccl WHERE UID = ownerid
  717. /
  718. grant select on sys.exu7cclu to public
  719. /
  720. CREATE OR REPLACE view exu7cclo (ownerid, cno, colname, colno) AS
  721.     SELECT a.ownerid, a.cno, a.colname, a.colno
  722.     from sys.exu7ccl a, sys.con$ b , sys.cdef$ c
  723.     WHERE b.owner#=UID
  724.     AND   b.con# = c.con#
  725.     AND   c.rcon# = a.cno
  726. /
  727. grant select on sys.exu7cclo to public
  728. /
  729. rem triggers
  730. CREATE OR REPLACE view exu7tgr 
  731.                    (ownerid, owner, baseobject, definition, whenclause, 
  732.                 actionsize, action, enabled, name, basename) AS
  733.         SELECT o.owner#, u.name, t.baseobject, t.definition, t.whenclause, 
  734.            t.actionsize, t.action, t.enabled, o.name, o2.name
  735.         FROM sys.obj$ o, sys.trigger$ t, sys.user$ u, sys.obj$ o2
  736.         WHERE o.obj# = t.obj# AND u.user# = o.owner# AND
  737.           o2.obj# = t.baseobject
  738. /
  739. CREATE OR REPLACE view exu7tgru AS
  740.         SELECT * from sys.exu7tgr WHERE UID = ownerid
  741. /
  742. grant select on sys.exu7tgru to public
  743. /
  744. rem triggers for incremental and cumulative export for table just 
  745. rem exported.  See comment on exu7refic.
  746. CREATE OR REPLACE view exu7tgric as 
  747.     SELECT * from sys.exu7tgr 
  748.     WHERE (ownerid, basename) in
  749.              (SELECT i.owner#, i.name
  750.               from sys.incexp i, sys.incvid v
  751.               WHERE i.expid > v.expid AND i.type = 2)
  752. /
  753. rem triggers for incremental export: record=no
  754. CREATE OR REPLACE view exu7tgri as 
  755.        SELECT * from sys.exu7tgr
  756.     WHERE (ownerid, basename) in (SELECT ownerid, name from sys.exu7tabi)
  757. /
  758. rem triggers for cumulative export: record=no
  759. CREATE OR REPLACE view exu7tgrc as 
  760.        SELECT * from sys.exu7tgr 
  761.     WHERE (ownerid, basename) in (SELECT ownerid, name from sys.exu7tabc)
  762. /
  763. CREATE OR REPLACE view exu7spr(ownerid, uname, id, name, time, typeid, type,
  764.      audt) AS
  765.    SELECT o.owner#, u.name, o.obj#, o.name, 
  766.       TO_CHAR(o.mtime, 'YYYY-MM-DD:HH24:MI:SS'), o.type,
  767.           DECODE(o.type, 7, 'PROCEDURE', 8, 'FUNCTION', 
  768.              9, 'PACKAGE', 11, 'PACKAGE BODY'), p.audit$
  769.    FROM sys.obj$ o, sys.user$ u, sys.procedure$ p
  770.    WHERE o.owner# = u.user# AND (o.type=7 OR o.type=8 OR o.type=9 OR o.type=11)
  771.     AND o.obj# = p.obj#
  772. /
  773. CREATE OR REPLACE view exu7spu(ownerid, uname, id, name, time, typeid, type,
  774.     audt) AS
  775.    SELECT * from sys.exu7spr WHERE UID = ownerid
  776. /
  777. grant select on sys.exu7spu to public
  778. /
  779. rem stored procedures for incremental export: modified, altered or new
  780. CREATE OR REPLACE view exu7spri AS
  781.        SELECT s.* from exu7spr s,incexp i, incvid v
  782.        WHERE s.name  = i.name(+) AND s.ownerid = i.owner#(+) AND
  783.              NVL(i.type,7) = 7 AND
  784.              NVL(i.expid,9999) > v.expid
  785. /
  786. rem stored procedures for incremental export: modified, altered or new
  787. CREATE OR REPLACE view exu7sprc AS
  788.        SELECT s.* from exu7spr s,incexp i, incvid v
  789.        WHERE s.name  = i.name(+) AND s.ownerid = i.owner#(+) AND
  790.              NVL(i.type,7) = 7 AND
  791. (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR
  792.                NVL(i.expid,9999) > v.expid)
  793. /
  794. CREATE OR REPLACE view exu7sps(obj#, line, source) AS
  795.    SELECT obj#,line,source 
  796.    FROM sys.source$ 
  797. /
  798. CREATE OR REPLACE view exu7spsu(obj#, line, source) AS
  799.    SELECT s.obj#, s.line, s.source
  800.    FROM sys.source$ s, sys.obj$ o
  801.    WHERE s.obj# = o.obj# and o.owner# = UID
  802. /
  803. grant select on sys.exu7spsu to public
  804. /
  805. rem system auditting options
  806. CREATE OR REPLACE view exu7aud (userid, name, action, success, failure) AS
  807.     SELECT a.user#, u.name, m.name, NVL(a.success,0), NVL(a.failure,0)
  808.     FROM sys.audit$ a, sys.user$ u, sys.stmt_audit_option_map m
  809.     WHERE a.user# = u.user# AND a.option# = m.option#
  810. /
  811. rem profiles
  812. CREATE OR REPLACE view exu7prf(profile#, name) AS
  813.     SELECT profile#, name 
  814.     FROM sys.profname$
  815.     WHERE profile# != 0
  816. /
  817. CREATE OR REPLACE view exu7prr(profile#, resname, limit) AS
  818.     SELECT profile#, DECODE(resource#,
  819.         0, 'COMPOSITE_LIMIT',
  820.         1, 'SESSIONS_PER_USER',
  821.         2, 'CPU_PER_SESSION',
  822.         3, 'CPU_PER_CALL',
  823.         4, 'LOGICAL_READS_PER_SESSION',
  824.         5, 'LOGICAL_READS_PER_CALL',
  825.         6, 'IDLE_TIME',
  826.         7, 'CONNECT_TIME',
  827.         8, 'PRIVATE_SGA', 'UNDEFINED'), limit
  828.     FROM sys.profile$
  829.     WHERE resource# != 9 and type = 0
  830. /
  831. rem snapshots
  832. CREATE OR REPLACE view exu7snap
  833. ( OWNER, OWNERID, NAME, TABLE_NAME, MASTER_VIEW, MASTER_OWNER, MASTER, 
  834.   MASTER_LINK, CAN_USE_LOG, LAST_REFRESH, ERROR, TYPE, NEXT, START_WITH, QUERY,
  835.   UPDATABLE, UPDATE_TRIG, UPDATE_LOG)
  836. as
  837. SELECT sowner, u.user#, vname, tname, mview, mowner, master, mlink,
  838.        decode(can_use_log, null, 'NO', 'YES'), 
  839.        snaptime, error#, 
  840.        decode(auto_fast, 
  841.               'C', 'COMPLETE', 
  842.               'F', 'FAST', 
  843.               '?', 'FORCE', 
  844.               null, 'FORCE', 'ERROR'), 
  845.        auto_fun, auto_date, query_txt, mod(trunc(flag/2),2), ustrg, uslog
  846. from sys.snap$ s, sys.user$ u
  847. WHERE u.name = s.sowner
  848. /
  849. CREATE OR REPLACE view exu7snapu
  850. ( OWNER, OWNERID, NAME, TABLE_NAME, MASTER_VIEW, MASTER_OWNER, MASTER, 
  851.   MASTER_LINK, CAN_USE_LOG, LAST_REFRESH, ERROR, TYPE, NEXT, START_WITH, QUERY,
  852.   UPDATABLE, UPDATE_TRIG, UPDATE_LOG)
  853. as
  854. SELECT sowner, u.user#, vname, tname, mview, mowner, master, mlink,
  855.        decode(can_use_log, null, 'NO', 'YES'), 
  856.        snaptime, error#, 
  857.        decode(auto_fast, 
  858.               'C', 'COMPLETE', 
  859.               'F', 'FAST', 
  860.               '?', 'FORCE', 
  861.               null, 'FORCE', 'ERROR'), 
  862.        auto_fun, auto_date, query_txt, mod(trunc(flag/2),2), ustrg, uslog
  863. from sys.snap$ s, sys.user$ u
  864. WHERE u.name = s.sowner
  865. and UID = u.user#
  866. /
  867. grant SELECT on sys.exu7snapu to public;
  868.  
  869. rem snapshots for incremental export: modified, altered or new
  870. CREATE OR REPLACE view exu7snapi AS
  871.         SELECT s.* from exu7snap s,incexp i, incvid v
  872.        WHERE s.name  = i.name(+) AND s.ownerid = i.owner#(+) AND
  873.              NVL(i.type,-2) = -2 AND
  874.              NVL(i.expid,9999) > v.expid
  875. /
  876. rem snapshots for cumulative export: new, last export was inc or not valid
  877. CREATE OR REPLACE view exu7snapc AS
  878.        SELECT s.* from exu7snap s, incexp i, incvid v
  879.        WHERE  s.name  = i.name(+) AND s.ownerid = i.owner#(+) AND
  880.               NVL(i.type,-2) = -2 AND
  881.               (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR
  882.                NVL(i.expid,9999) > v.expid)
  883. /
  884. rem snapshot logs
  885. CREATE OR REPLACE view exu7snapl
  886. ( LOG_OWNER, LOG_OWNERID, MASTER, LOG_TABLE, LOG_TRIGGER)
  887. as
  888. SELECT m.mowner, u.user#, m.master, m.log, m.trig
  889. from sys.mlog$ m, sys.user$ u
  890. WHERE m.mowner = u.name
  891. /
  892.  
  893. CREATE OR REPLACE view exu7snaplu
  894. ( LOG_OWNER, LOG_OWNERID, MASTER, LOG_TABLE, LOG_TRIGGER)
  895. as
  896. SELECT m.mowner, u.user#, m.master, m.log, m.trig
  897. from sys.mlog$ m,  sys.user$ u
  898. WHERE  m.mowner = u.name
  899.   and UID = u.user#
  900. /
  901. grant SELECT on sys.exu7snaplu to public;
  902.  
  903. rem snapshot logs for incremental export: modified, altered or new
  904. CREATE OR REPLACE view exu7snapli AS
  905.         SELECT s.* from exu7snapl s,incexp i, incvid v
  906.        WHERE s.master  = i.name(+) AND s.log_ownerid = i.owner#(+) AND
  907.              NVL(i.type,-3) = -3 AND
  908.              NVL(i.expid,9999) > v.expid
  909. /
  910. rem snapshot logs for cumulative export: new, last export was inc or not valid
  911. CREATE OR REPLACE view exu7snaplc AS
  912.        SELECT s.* from exu7snapl s, incexp i, incvid v
  913.        WHERE s.master  = i.name(+) AND s.log_ownerid = i.owner#(+) AND
  914.               NVL(i.type,-3) = -3 AND
  915.               (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR
  916.                NVL(i.expid,9999) > v.expid)
  917. /
  918.  
  919. rem info on deleted snapshots -- they aren't in obj$
  920. CREATE OR REPLACE view exu7delsnap (owner, name, type) as
  921.        SELECT u$.name, i$.name, 'SNAPSHOT'
  922.        from sys.incexp i$, sys.user$ u$
  923.        WHERE i$.owner# = u$.user# and
  924.          i$.type = -2 and
  925.              (u$.name, i$.name)
  926.              NOT IN (SELECT s$.sowner, s$.vname
  927.              from sys.snap$ s$)
  928. /
  929. rem info on deleted snapshot logs -- they aren't in obj$
  930. CREATE OR REPLACE view exu7delsnapl (owner, name, type) as
  931.        SELECT u$.name, i$.name, 'SNAPSHOT LOG'
  932.        from sys.incexp i$, sys.user$ u$
  933.        WHERE i$.owner# = u$.user# and
  934.          i$.type = -3 and
  935.              (u$.name, i$.name)
  936.              NOT IN (SELECT m$.mowner, m$.master
  937.              from sys.mlog$ m$)
  938. /
  939.  
  940. rem info on analyzed objects
  941. CREATE OR REPLACE view exu7anal(id,rowcnt) as
  942.     select obj#, NVL(rowcnt,-1) from sys.tab$;
  943. grant select on exu7anal to public
  944. /
  945.  
  946. rem add a view to determine storage clause for unique constraint
  947. rem need for it to be user level because two different users can have the
  948. rem same index name 
  949. CREATE OR REPLACE view exu7uscu 
  950. (iobjid, iname, ifileno, iblockno, ibobjid, tspname) as
  951.     SELECT o$.obj#, o$.name, i$.file#, i$.block#, i$.bo#, t$.name
  952.     from sys.obj$ o$, sys.ind$ i$, sys.file$ f$, sys.ts$ t$
  953.     where o$.obj# = i$.obj# and unique$ = 1 and f$.file#=i$.file#
  954.     and f$.ts# = t$.ts#
  955. /
  956. grant select on sys.exu7uscu to public; 
  957.  
  958. rem referential constraints
  959. CREATE OR REPLACE view exu7rif 
  960.                    (objid, owner, ownerid, tname, rowner, rtname, cname, cno,
  961.                 rcno, action, enabled, robjid) AS
  962.        SELECT o.obj#, u.name, c.owner#, o.name, ru.name, ro.name, 
  963.               DECODE(SUBSTR(c.name, 1, 5), 'SYS_C', '', NVL(c.name, '')),
  964.           c.con#, cd.rcon#, NVL(cd.refact,0), NVL(cd.enabled,0),
  965.           cd.robj#
  966.        FROM sys.user$ u, sys.user$ ru, sys.obj$ o, sys.obj$ ro, 
  967.             sys.con$ c, sys.cdef$ cd
  968.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND ro.obj# = cd.robj# AND
  969.              cd.con# = c.con# AND cd.type = 4 AND ru.user# = ro.owner#
  970. /
  971. CREATE OR REPLACE view exu7erc
  972.         (resource_name, unit_cost) as
  973.         SELECT m.name, c.cost 
  974.         FROM sys.resource_cost$ c, sys.resource_map m 
  975.         WHERE c.resource# = m.resource#
  976.             AND c.resource# in (2, 4, 7, 8)
  977. /
  978.  
  979. REM
  980. REM Job Queues
  981. REM
  982. CREATE OR REPLACE view exu7jbq
  983.             (job, ownerid, owner) as
  984.         SELECT j$.job, u$.user#, j$.powner
  985.         FROM sys.job$ j$, sys.user$ u$
  986.         WHERE j$.powner = u$.name
  987. /
  988.  
  989. CREATE OR REPLACE view exu7jbqu 
  990.         (job, ownerid, owner) as
  991.         SELECT * FROM sys.exu7jbq 
  992.         WHERE uid = ownerid
  993. /
  994. grant select on exu7jbqu to public
  995. /
  996. REM
  997. REM Refresh Groups
  998. REM
  999. CREATE OR REPLACE view exu7rgs 
  1000.         (refgroup, ownerid, owner) as
  1001.         SELECT r$.refgroup, u$.user#, r$.owner
  1002.         FROM sys.rgroup$ r$, sys.user$ u$
  1003.         WHERE r$.owner = u$.name
  1004. /
  1005.  
  1006. CREATE OR REPLACE view exu7rgsu
  1007.         (refgroup, ownerid, owner) as
  1008.         SELECT * from sys.exu7rgs
  1009.         WHERE uid = ownerid
  1010. /
  1011. grant select on exu7rgsu to public
  1012. /
  1013. REM
  1014. REM Refresh Group Children
  1015. REM
  1016. CREATE OR REPLACE view exu7rgc
  1017.         (owner, ownerid, child, type, refgroup) as
  1018.         SELECT rc$.owner, u$.user#, rc$.name, rc$.type, rc$.refgroup
  1019.         FROM sys.rgchild$ rc$, sys.user$ u$
  1020.         WHERE rc$.owner = u$.name
  1021. /
  1022.  
  1023. CREATE OR REPLACE view exu7rgcu
  1024.         (owner, ownerid,  child, type, refgroup) as
  1025.         SELECT * from sys.exu7rgc
  1026.         WHERE uid = ownerid
  1027. /
  1028. grant select on exu7rgcu to public
  1029. /
  1030. REM
  1031. REM PoSTtables actions 
  1032. REM
  1033. /
  1034. CREATE OR REPLACE view exu7pst
  1035.         (owner, ownerid, tname, tobjid, callorder) as
  1036.         SELECT a$.owner, u$.user#, a$.name, o$.obj#, a$.callorder
  1037.         FROM sys.expact$ a$, sys.user$ u$, sys.obj$ o$
  1038.         WHERE u$.name = a$.owner and o$.owner# = u$.user#
  1039.               and o$.name = a$.name 
  1040. /
  1041.  
  1042. CREATE OR REPLACE view exu7pstu
  1043.         (owner, ownerid, tname, tobjid, callorder) as
  1044.         SELECT * from sys.exu7pst
  1045.             where ownerid = uid
  1046. /
  1047. grant select on exu7pstu to public
  1048. /
  1049.  
  1050. REM PoSTtables actions incremental/cumulative with record = Y
  1051. CREATE OR REPLACE view exu7pstic
  1052.         (owner, ownerid, tname, tobjid, callorder) as
  1053.         SELECT * from sys.exu7pst
  1054.         WHERE (ownerid, tname) in
  1055.             (SELECT i.owner#, i.name
  1056.                  FROM sys.incexp i, sys.incvid v
  1057.                  WHERE i.expid > v.expid AND i.type = 2)
  1058. /
  1059. REM PoSTtables actions for incremental export : record = N
  1060. CREATE OR REPLACE view exu7psti as
  1061.         SELECT * from sys.exu7pst
  1062.         WHERE (ownerid, tname) in 
  1063.         (SELECT ownerid, name from sys.exu7tabi)
  1064. /
  1065. REM PoSTtables actions for cumulative  export : record = N
  1066. CREATE OR REPLACE view exu7pstc as
  1067.         SELECT * from sys.exu7pst
  1068.         WHERE (ownerid, tname) in 
  1069.         (SELECT ownerid, name from sys.exu7tabc)
  1070. /
  1071.  
  1072. REM Version Control
  1073. CREATE OR REPLACE view exu7ver (version) AS
  1074.             SELECT TO_NUMBER(value$) from sys.props$
  1075.         WHERE name = 'EXPORT_VIEWS_VERSION'
  1076. /
  1077. grant select on exu7ver to public
  1078. /
  1079. REM Check for Procedural Option
  1080. CREATE OR REPLACE view exu7cpo (value) AS
  1081.         SELECT DECODE(value, 'TRUE', 1, 'FALSE', 0, 2) 
  1082.         FROM v$option
  1083.         WHERE parameter = 'procedural'
  1084. /
  1085. grant select on exu7cpo to public
  1086. /
  1087. REM
  1088. REM Add versioning support for export
  1089. REM This will get bumped up as the views evolve. The insert is needed
  1090. REM for upgrades from 7.0 or new databases. The update is needed for 
  1091. REM databases that have older compatibility.
  1092. REM These are the releases when the compatibility was bumped:
  1093. REM    7.0.* - no compatibility - assume zero
  1094. REM    7.1.3 - set to one
  1095. REM    7.2.1 - set to two
  1096. REM
  1097. insert into props$ 
  1098. select 'EXPORT_VIEWS_VERSION', '2', 'Export views revision #' from dual
  1099. where not exists
  1100.   (select 'x' from props$ where name = 'EXPORT_VIEWS_VERSION')
  1101. /
  1102. update props$ set value$ = 2 where name = 'EXPORT_VIEWS_VERSION'
  1103. /
  1104. commit
  1105. /
  1106.  
  1107.