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

  1. rem 
  2. rem $Header: catexp6.sql 7020100.1 94/09/23 22:14:29 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      catexp6.sql - CATalog EXPort views for v6 SQL script
  7. Rem    DESCRIPTION
  8. Rem      Creates V6.0-style export views against the V7 RDBMS so that EXP V6.0
  9. Rem      can be used to read out the data in a V7 RDBMS
  10. Rem    NOTES
  11. Rem    MODIFIED   (MM/DD/YY)
  12. Rem     jloaiza    07/08/94 -  bitand modified column
  13. Rem     vraghuna   03/21/94 -  bug 190141 - change expvew6.sql header
  14. Rem     vraghuna   08/26/93 -  bug 178457 - increase performance of exucol
  15. Rem     mmoore     11/05/92 -  update tabauth$ 
  16. Rem     vraghuna   11/04/92 -  add tabauth$ from catalog5.sql 
  17. Rem     glumpkin   10/20/92 -  Renamed from EXPVEW6.SQL 
  18. Rem     cheigham   06/25/92 -  redo exu7col, add exu7colnn for dict. changes 
  19. Rem     cheigham   06/23/92 -  fix exucol to accommodate dictionary changes 
  20. Rem     cheigham   03/06/92 -  fix to_date clauses to be language-independent 
  21. Rem     cheigham   02/27/92 -  exclude objects which are in hash clusters 
  22. Rem     cheigham   02/26/92 -  fix exutab query 
  23. Rem     cheigham   02/24/92 -  exclude snapshot,snapshot log tables,views 
  24. Rem     rkooi      01/30/92 -  add newline to end 
  25. Rem     cheigham   01/03/92 -  add _system_audit_options_ table 
  26. Rem     cheigham   01/02/92 -  truncate audit$ columns to 24 chars 
  27. Rem     cheigham   11/20/91 -  fix db link name selection 
  28. Rem     cheigham   10/01/91 -  fix exugrn 
  29. Rem     cheigham   09/25/91 -  create index for privilege views 
  30. Rem     cheigham   09/18/91 -  use distinct(), not group by's, in exudba,exures
  31. Rem     agupta     09/04/91 -  initial revision of file 
  32. Rem     agupta     08/28/91 -  Creation 
  33.  
  34. set echo on;
  35.  
  36. rem this index makes exu(res/dba/cnt) much faster
  37. create index i_sysauth2 on sysauth$(privilege#,grantee#);
  38.  
  39. rem
  40. rem  adding tabauth$ for exugrn
  41. rem Create the security views which emulate the v5 and v6 security tables.
  42. rem 
  43. drop view tabauth$
  44. /                                              
  45. create view tabauth$ (obj#, grantor#, grantee#, time, sequence#, alter$, 
  46.                       delete$,index$, insert$, select$, update$, references$) as
  47.   select obj#, grantor#, grantee#, max(null), min(sequence#),
  48.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  49.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 25, 2), 
  50.       '00', 0, '01', 2, '11', 3, 0),
  51.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  52.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 19, 2), 
  53.       '00', 0, '01', 2, '11', 3, 0),
  54.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  55.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 15, 2), 
  56.       '00', 0, '01', 2, '11', 3, 0),
  57.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  58.        decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  59.               13, 2), '01', 2, '11', 3, 
  60.          decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  61.                 12, '0'), 6, 1), '0', 0, 1)),
  62.     decode(substr(lpad(sum(power(10, privilege#*2) + 
  63.       decode(option$, null, 0, power(10, privilege#*2 + 1))), 26, '0'), 7, 2), 
  64.       '00', 0, '01', 2, '11', 3, 0),
  65.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  66.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  67.              5, 2),'01', 2, '11', 3, 
  68.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  69.                  12, '0'), 2, 1), '0', 0, 1)),
  70.     decode(substr(lpad(sum(decode(col#, null, power(10, privilege#*2) + 
  71.       decode(option$, null, 0, power(10, privilege#*2 + 1)), 0)), 26, '0'), 
  72.              3, 2), '01', 2, '11', 3, 
  73.           decode(substr(lpad(sum(decode(col#, null, 0, power(10, privilege#))),
  74.                  12, '0'), 1, 1), '0', 0, 1))
  75.   from sys.objauth$
  76.   group by obj#, grantor#, grantee#
  77. /
  78. rem all tables 
  79. rem   NOTE: we exclude tables created by snapshots,snapshot logs
  80. rem   and tables in hash clusters since these aren't supported in v6.
  81. drop view exutab;
  82. CREATE VIEW exutab (objid,name, owner, ownerid, tablespace, fileno, blockno,
  83.             audit$, comment$, clusterflag, mtime, modified,
  84.                     pctfree$, pctused$, initrans, maxtrans) AS
  85.        SELECT o$.obj#,o$.name, u$.name, o$.owner#, ts$.name, t$.file#, 
  86.           t$.block#, substr(t$.audit$,1, 24), 
  87.           c$.comment$, NVL(t$.clu#, 0), o$.mtime,
  88.           bitand(t$.modified,1), t$.pctfree$, t$.pctused$, t$.initrans, 
  89.           t$.maxtrans
  90.        FROM sys.tab$ t$, sys.obj$ o$, sys.ts$ ts$, sys.user$ u$, sys.com$ c$,
  91.         sys.clu$ cl$
  92.        WHERE  t$.obj# = o$.obj# and t$.ts# = ts$.ts# and 
  93.               u$.user# = o$.owner# and o$.obj# = c$.obj#(+) 
  94.           and c$.col#(+) is null
  95.           and o$.name NOT LIKE 'SNAP$_%'
  96.           and o$.name NOT LIKE 'MLOG$_%'
  97.           and t$.clu# = cl$.obj#(+)
  98.           and (t$.clu#  is null or cl$.hashkeys = 0)
  99. /
  100. rem tables for incremental export: modified, altered or new
  101. drop view exutabi;
  102. CREATE VIEW exutabi AS 
  103.        SELECT t.* FROM exutab t,incexp i, incvid v
  104.        WHERE t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND
  105.              NVL(i.type,2) = 2 AND  
  106.              (bitand(t.modified,1) = 1 OR t.mtime > i.itime OR 
  107.               NVL(i.expid,9999) > v.expid)
  108. /         
  109. rem tables for cumulative export: modified, last export was inc, altered or new
  110. drop view exutabc;
  111. CREATE VIEW exutabc AS 
  112.        SELECT t.* FROM exutab t,incexp i, incvid v
  113.        WHERE  t.name  = i.name(+) AND t.ownerid = i.owner#(+) AND 
  114.              NVL(i.type,2) = 2 AND 
  115.               (bitand(t.modified,1) = 1 OR i.itime > NVL(i.ctime,
  116.                                              TO_DATE('01-01-00','DD-MM-YY'))
  117.                OR t.mtime > i.itime OR NVL(i.expid,9999) > v.expid)
  118. /
  119. rem current user's tables 
  120. drop view exutabu;
  121. CREATE VIEW exutabu AS
  122.        SELECT * FROM exutab WHERE ownerid = uid
  123. /
  124. grant select on exutabu to public;
  125.  
  126. rem not null constraints on columns
  127. drop view exucolnn;
  128. CREATE view exucolnn (tobjid, colid, conname, isnull) AS
  129.       SELECT o$.obj#, c$.col#, 
  130.               DECODE(SUBSTR(con$.name,1,5), 'SYS_C', '', NVL(con$.name, '')),
  131.           1
  132.       FROM  sys.obj$ o$, sys.col$ c$, sys.con$ con$, sys.cdef$ cd$,
  133.             sys.ccol$ cc$
  134.       WHERE c$.obj# = o$.obj# and c$.obj# = cc$.obj# and 
  135.             c$.col# = cc$.col# and cc$.con# = cd$.con# and
  136.             cd$.con# = con$.con#(+) and cd$.type =7
  137. /
  138.  
  139. rem all columns  - map v7 type 96 (varchar2) to type 1 (char)
  140. drop view exucol_temp;
  141. CREATE VIEW exucol_temp (tobjid, towner, townerid, tname, name, length, 
  142.             precision, scale, type, isnull, conname, colid, 
  143.             comment$, --default$, 
  144.             dfltlen) AS
  145.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  146.               c$.precision, c$.scale, 
  147.           DECODE(c$.type#, 96, 1, c$.type#), NVL(cn.isnull,0), cn.conname,
  148.               c$.col#, com$.comment$, -- c$.default$, 
  149.           NVL(c$.deflength, 0)
  150.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$,
  151.         sys.com$ com$, sys.exucolnn cn
  152.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  153.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+) and
  154.          c$.obj# = cn.tobjid and c$.col# = cn.colid
  155.     union all
  156.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, c$.length, 
  157.               c$.precision, c$.scale, 
  158.           DECODE(c$.type#, 96, 1, c$.type#), 0, null,
  159.               c$.col#, com$.comment$, -- c$.default$, 
  160.           NVL(c$.deflength, 0)
  161.        FROM sys.col$ c$, sys.obj$ o$, sys.user$ u$,
  162.         sys.com$ 
  163.        WHERE c$.obj# = o$.obj# and o$.owner# = u$.user# and 
  164.          c$.obj# = com$.obj#(+) and c$.col# = com$.col#(+) 
  165.          and not exists
  166.          (select null from sys.exucolnn cn
  167.         where c$.obj# = cn.tobjid and c$.col# = cn.colid)
  168. /
  169. drop view exucol;
  170. CREATE VIEW exucol (tobjid, towner, townerid, tname, name, length, precision, 
  171.             scale, type, isnull, conname, colid, comment$, default$, 
  172.                 dfltlen) AS
  173.     SELECT tobjid, towner, townerid, v$.tname, v$.name, v$.length, 
  174.            v$.precision, v$.scale, type, isnull, conname, colid, comment$,
  175.            default$, dfltlen
  176.     FROM exucol_temp v$, sys.col$ c$
  177.     WHERE c$.obj# = v$.tobjid and c$.col# = v$.colid
  178. /
  179. drop view exucolu;
  180. CREATE VIEW exucolu AS                   /* current user's columns */
  181.        SELECT * from exucol WHERE townerid = uid
  182. /
  183. grant select on exucolu to public;
  184.  
  185. rem all columns for index
  186. drop view exuico;
  187. CREATE VIEW exuico (tobjid, towner, townerid, tname, name, length, precision,
  188.             scale, type, isnull, conname, colid, comment$, default$, 
  189.             dfltlen) AS
  190.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, c$.name, 0, 0, 0, 0, 0, '',
  191.               i$.pos#, NULL, NULL, 0
  192.        FROM sys.col$ c$, sys.icol$ i$, sys.obj$ o$, sys.user$ u$
  193.        WHERE c$.obj# = i$.bo# and c$.col# = i$.col# and 
  194.          i$.obj# = o$.obj# and o$.owner# = u$.user#
  195. /
  196. drop view exuicou;
  197. CREATE VIEW exuicou AS                   /* current user's columns */
  198.        SELECT * from exuico WHERE townerid = uid
  199. /
  200. grant select on exuicou to public;
  201.  
  202. rem all users with connect (create session priv)
  203. rem drop both table and view; either could be there
  204. drop table exucnt;
  205. drop view exucnt;
  206. create view exucnt as
  207. select distinct(grantee#) from sysauth$
  208. connect by privilege# = prior grantee#
  209. start with privilege#=-5
  210. /
  211. rem all users with resource (unlimited tablespace priv)
  212. drop table exures;
  213. drop view exures;
  214. create view exures as 
  215. select distinct(grantee#) from sysauth$
  216. connect by privilege# = prior grantee#
  217. start with privilege#=-15
  218. /
  219. rem all users with dba (alter system priv)
  220. drop table exudba;
  221. drop view exudba;
  222. create view exudba as
  223. select distinct(grantee#) from sysauth$
  224. connect by privilege# = prior grantee#
  225. start with privilege#=-3
  226. /
  227. drop view exuusr;
  228. CREATE VIEW exuusr (name, userid, passwd, privs, datats, tempts) AS
  229.         SELECT u.name, u.user#, DECODE(u.password, 'N', '', u.password),
  230.     DECODE(c.grantee#, NULL, 'N', 'Y')||
  231.     DECODE(d.grantee#, NULL, 'N', 'Y')||
  232.     DECODE(r.grantee#, NULL, 'N', 'Y'),
  233.         ts1.name, ts2.name       
  234.     FROM sys.user$ u, sys.ts$ ts1, sys.ts$ ts2, sys.exucnt c, 
  235.          sys.exures r, sys.exudba d
  236.         WHERE u.datats# = ts1.ts# 
  237.     and u.tempts# = ts2.ts# 
  238.     and u.user#=c.grantee#(+)
  239.     and u.user#=r.grantee#(+) 
  240.     and u.user#=d.grantee#(+)
  241. /
  242. drop view exuusru;
  243. CREATE VIEW exuusru AS                         /* current user */
  244.        SELECT * FROM exuusr WHERE userid = UID
  245. /
  246. grant select on exuusru to public;
  247.  
  248. rem all grants
  249. drop view exugrn;
  250. CREATE VIEW exugrn (objid, grantor, grantorid, grantee, privs,
  251.                     creatorid, sequence#) AS
  252.     SELECT t$.obj#, ur$.name, t$.grantor#, ue$.name,
  253.            DECODE(t$.alter$, 0, 'N', 2, 'Y', 'G') ||
  254.            DECODE(t$.delete$, 0, 'N', 2,  'Y', 'G') ||
  255.            DECODE(t$.index$, 0, 'N', 2, 'Y', 'G') ||
  256.            DECODE(t$.insert$, 0, 'N', 2, 'Y', 'G') ||
  257.            DECODE(t$.select$, 0, 'N', 2, 'Y', 'G') ||
  258.            DECODE(t$.update$, 0, 'N', 1, 'R', 2, 'Y', 'G') ||
  259.             DECODE(t$.references$, 0, 'N', 2, 'Y', 'G'), 
  260.            o$.owner#, t$.sequence#
  261.        FROM sys.tabauth$ t$, sys.obj$ o$, sys.user$ ur$,
  262.         sys.user$ ue$
  263.        WHERE o$.obj# = t$.obj# AND
  264.              t$.grantor# = ur$.user# AND t$.grantee# = ue$.user#
  265. /
  266. rem first level grants
  267. drop view exugrnu;
  268. CREATE VIEW exugrnu AS
  269.        SELECT * FROM exugrn WHERE grantorid = UID AND creatorid = UID
  270. /
  271. grant select on exugrnu to public;
  272.  
  273. rem all column grants
  274. drop view exucgr;
  275. CREATE VIEW exucgr (objid, grantor, grantorid, grantee, creatorid, cname, 
  276.                sequence#, wgo) AS
  277.        SELECT c$.obj#, ur$.name, c$.grantor#, ue$.name, o$.owner#, cl$.name,
  278.               c$.sequence#, NVL(c$.option$,0)
  279.        FROM sys.objauth$ c$, sys.obj$ o$, sys.user$ ur$, sys.user$ ue$,
  280.             sys.col$ cl$
  281.        WHERE c$.grantor# = ur$.user# AND c$.grantee# = ue$.user# AND
  282.              c$.obj# = o$.obj# AND c$.privilege# = 10 AND 
  283.              c$.obj# = cl$.obj# AND c$.col# = cl$.col#
  284. /
  285. rem first level grants
  286. drop view exucgru;
  287. CREATE VIEW exucgru AS
  288.        SELECT * FROM exucgr WHERE grantorid = UID AND creatorid = UID
  289. /
  290. grant select on exucgru to public;
  291.  
  292. rem all indexes
  293. drop view exuind;
  294. CREATE VIEW exuind (iobjid, iname, iowner, iownerid, ispace, ifileno, iblockno,
  295.             btname, btobjid, btowner, btownerid, unique$,
  296.             cluster$, pctfree$, initrans, maxtrans)  AS
  297.        SELECT i$.obj#, i$.name, ui$.name, i$.owner#, ts$.name, ind$.file#,
  298.           ind$.block#, t$.name, t$.obj#, ut$.name, t$.owner#,
  299.               ind$.unique$, DECODE(t$.type, 3, 1, 0), ind$.pctfree$, 
  300.           ind$.initrans, ind$.maxtrans
  301.        FROM  sys.obj$ t$, sys.obj$ i$, sys.ind$ ind$,
  302.          sys.user$ ui$, sys.user$ ut$, sys.ts$ ts$
  303.        WHERE ind$.bo# = t$.obj# AND ind$.obj# = i$.obj# AND
  304.          ts$.ts# = ind$.ts# AND i$.owner# = ui$.user# AND
  305.              t$.owner# = ut$.user# AND (unique$=0 OR 
  306.          NOT EXISTS (SELECT * from sys.con$ c$
  307.              WHERE c$.owner# = i$.owner#
  308.                          AND   c$.name = i$.name))
  309. /
  310. rem current user indexes
  311. drop view exuindu;
  312. CREATE VIEW exuindu AS
  313.        SELECT * FROM exuind WHERE iownerid = UID and btownerid = UID
  314. /
  315. grant select on exuindu to public;
  316.  
  317. rem all views 
  318. rem  we exclude views created by snapshot logs since they aren't supported
  319. rem  in v6
  320. drop view exuvew;
  321. CREATE VIEW exuvew (vobjid,vname, vlen, vtext, vowner, vownerid,
  322.             vtime, vaudit, vcomment, vcname) AS
  323.        SELECT o$.obj#, o$.name, v$.textlength, v$.text, u$.name, o$.owner#, 
  324.             TO_CHAR(o$.ctime, 'YYMMDDHH24MISS'), 
  325.           substr(v$.audit$, 1, 24), com$.comment$,
  326.               DECODE(SUBSTR(c$.name,1,5), 'SYS_C', '', NVL(c$.name, ''))
  327.        FROM sys.obj$ o$, sys.view$ v$, sys.user$ u$, sys.cdef$ cd$,
  328.             sys.con$ c$, sys.com$ com$
  329.        WHERE o$.obj# = v$.obj# AND o$.owner# = u$.user# AND
  330.          o$.obj# = cd$.obj#(+) AND cd$.con# = c$.con#(+) AND 
  331.              o$.obj# = com$.obj#(+) AND com$.col#(+) is null AND
  332.          o$.name not like 'MVIEW$_%'
  333. /
  334. rem views for incremental export: new or last export not valid
  335. rem cannot use union as in exutabi because of long field
  336. drop view exuvewi;
  337. CREATE VIEW exuvewi AS 
  338.        SELECT vw.* FROM exuvew vw, incexp i, incvid v
  339.        WHERE i.name(+) = vw.vname AND i.owner#(+) = vw.vownerid
  340.              AND v.expid < NVL(i.expid, 9999) AND NVL(i.type, 4) = 4
  341. /         
  342. rem views for cumulative export: new, last export was inc or not valid
  343. drop view exuvewc;
  344. CREATE VIEW exuvewc AS 
  345.        SELECT vw.* FROM exuvew vw, incexp i, incvid v
  346.        WHERE vw.vname = i.name(+) AND vw.vownerid = i.owner#(+) AND 
  347.              NVL(i.type,4) = 4 AND
  348.              (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  349.               v.expid < NVL(i.expid, 9999))
  350. /
  351. rem current user's view
  352. drop view exuvewu;
  353. CREATE VIEW exuvewu AS
  354.        SELECT *    FROM exuvew WHERE vownerid = UID
  355. /
  356. grant select on exuvewu to public;
  357.  
  358. rem all synonyms
  359. drop view exusyn;
  360. CREATE VIEW exusyn (synnam, syntab, tabown, tabnode,
  361.                 public$, synown, synownid, syntime) AS
  362.        SELECT o$.name, s$.name, s$.owner, s$.node,
  363.             DECODE(o$.owner#, 1, 1, 0),
  364.              uo$.name, o$.owner#, TO_CHAR(o$.ctime, 'YYMMDDHH24MISS')
  365.        FROM sys.obj$ o$, sys.syn$ s$, sys.user$ us$, sys.user$ uo$
  366.        WHERE s$.obj# = o$.obj# AND o$.owner# = uo$.user# AND
  367.          s$.owner = us$.name(+)
  368. /
  369. rem synonyms for incremental export: new or last export not valid
  370. drop view exusyni;
  371. CREATE VIEW exusyni AS 
  372.        SELECT s.* FROM exusyn s, incexp i, incvid v
  373.        WHERE s.synnam = i.name(+) AND s.synownid = i.owner#(+) AND 
  374.              NVL(i.type,5) = 5 AND NVL(i.expid,9999) > v.expid
  375. /         
  376. rem synonyms for cumulative export: new, last export was inc or not valid
  377. drop view exusync;
  378. CREATE VIEW exusync AS 
  379.        SELECT s.* FROM exusyn s, incexp i, incvid v
  380.        WHERE  s.synnam  = i.name(+) AND s.synownid = i.owner#(+) AND 
  381.               NVL(i.type,5) = 5 AND
  382.           (NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY')) < i.itime OR 
  383.                NVL(i.expid,9999) > v.expid)
  384. /
  385. rem user's synnonyms
  386. drop view exusynu;
  387. CREATE VIEW exusynu AS
  388.        SELECT * FROM exusyn WHERE synownid = UID
  389. /
  390. grant select on exusynu to public;
  391.  
  392. rem clustered tables' columns
  393. drop view exucco;
  394. CREATE VIEW exucco(tname, towner, townerid, cluster$, tcolnam, seq) AS
  395.        SELECT t$.name, u$.name, t$.owner#, c$.name, tc$.name, cc$.col#
  396.        FROM sys.obj$ t$, sys.tab$ tab$, sys.obj$ c$,
  397.         sys.col$ tc$, sys.col$ cc$, sys.user$ u$
  398.        WHERE t$.type = 2 AND t$.obj# = tab$.obj# AND
  399.            tab$.clu# = cc$.obj# AND tab$.obj# = tc$.obj# AND 
  400.              tab$.clu# = c$.obj# AND 
  401.              cc$.segcol# = tc$.segcol# AND t$.owner# = u$.user#
  402. /
  403. rem current user's clustered tables' columns
  404. drop view exuccou;
  405. CREATE VIEW exuccou AS
  406.        SELECT * FROM exucco WHERE townerid = UID
  407. /
  408. grant select on exuccou to public;
  409.  
  410. rem all clusters except HASH clusters (not supported in v6)
  411. drop view exuclu;
  412. CREATE VIEW exuclu (objid, owner, ownerid, name, tblspace, size$, fileno,
  413.                 blockno, mtime, pctfree$, pctused$, initrans, maxtrans) AS
  414.        SELECT o$.obj#, u$.name, o$.owner#, o$.name, ts$.name, 
  415.           NVL(c$.size$, -1), c$.file#, c$.block#, o$.mtime, c$.pctfree$, 
  416.               c$.pctused$, c$.initrans, c$.maxtrans
  417.        FROM sys.obj$ o$, sys.clu$ c$, sys.ts$ ts$, sys.user$ u$
  418.        WHERE o$.obj# = c$.obj# AND c$.ts# = ts$.ts# AND o$.owner# = u$.user#
  419.     AND c$.hashkeys = 0
  420. /
  421. rem clusters for incremental export: new or last export invalid
  422. rem altered cluster is not exported because this would require exporting all
  423. rem tables in it.
  424. drop view exuclui;
  425. CREATE VIEW exuclui AS 
  426.        SELECT c.* FROM exuclu c,incexp i, incvid v
  427.        WHERE c.name  = i.name(+) AND c.ownerid = i.owner#(+) AND
  428.          NVL(i.expid,9999) > v.expid
  429. /         
  430. rem clusters for cumulative export: last export was inc or new
  431. rem altered cluster is not exported because this would require exporting all
  432. rem tables in it.
  433. drop view exucluc;
  434. CREATE VIEW exucluc AS 
  435.        SELECT c.* FROM exuclu c,incexp i, incvid v
  436.        WHERE c.name = i.name(+) AND c.ownerid = i.owner#(+) AND 
  437.              NVL(i.type,3) = 3 AND
  438.           (i.itime > NVL(i.ctime,TO_DATE('01-01-00','DD-MM-YY'))
  439.              OR NVL(i.expid,9999) > v.expid)
  440. /
  441. rem current user's clusters
  442. drop view exucluu;
  443. CREATE VIEW exucluu AS
  444.        SELECT * FROM exuclu WHERE ownerid = UID
  445. /
  446. grant select on exucluu to public;
  447.  
  448. rem all storage parameters
  449. drop view exusto;
  450. CREATE VIEW exusto (ownerid, fileno, blockno, iniext, sext, minext,
  451.                     maxext, pctinc, blocks) AS
  452.        SELECT user#, file#, block#, iniexts, extsize, minexts, maxexts, 
  453.               extpct, blocks
  454.        FROM sys.seg$
  455.  
  456. rem storage parameters for current user's segments
  457. drop view exustou;
  458. CREATE VIEW exustou AS
  459.        SELECT * FROM exusto WHERE ownerid = UID
  460. /
  461. grant select on exustou to public;
  462.  
  463. rem all tablespaces
  464. drop view exutbs;
  465. CREATE VIEW exutbs (id, owner, name, isonline, iniext, sext, pctinc,
  466.             minext, maxext) AS
  467.        SELECT ts$.ts#, 'SYSTEM', ts$.name, 
  468.           DECODE(ts$.online$, 1, 'ONLINE', 'OFFLINE'), ts$.dflinit,
  469.              ts$.dflincr, ts$.dflextpct, ts$.dflminext, ts$.dflmaxext
  470.        FROM sys.ts$ ts$ 
  471.        WHERE ts$.online$ in (1, 2) and ts$.ts# != 0
  472. /
  473.  
  474. rem tablespace quotas
  475. drop view exutsq;
  476. CREATE VIEW exutsq(tsname, tsid, uname, maxblocks) AS
  477.        SELECT t$.name, q$.ts#, u$.name, q$.maxblocks
  478.        FROM  sys.ts$ t$, sys.tsq$ q$, sys.user$ u$
  479.        WHERE  q$.user# = u$.user# AND q$.ts# = t$.ts# AND q$.maxblocks != 0
  480. /
  481.  
  482. rem block size
  483. drop view exubsz;
  484. CREATE VIEW exubsz(blocksize) AS
  485.        SELECT ts$.blocksize
  486.        FROM   sys.ts$ ts$
  487. /
  488. grant select on exubsz to public;
  489.  
  490. rem all files
  491. drop view exufil;
  492. CREATE VIEW exufil(fname, fsize, tsid) AS
  493.        SELECT v$.name, f$.blocks, f$.ts#
  494.        FROM   sys.file$ f$, sys.v$dbfile v$
  495.        WHERE  f$.file# = v$.file#
  496. /
  497.  
  498. rem all database links
  499. rem in v7, db link names can be longer than in v6.  We compress the form
  500. rem  'x.y[.a.b]' to 'x'.  If the name is of form 'x', it is unchanged.
  501. drop view exulnk;
  502. CREATE VIEW exulnk (owner, ownerid, name, user$, passwd, host, public$) AS
  503.        SELECT DECODE(l$.owner#, 1, 'SYSTEM', u$.name), l$.owner#,
  504.     decode(instr(l$.name,'.'), 0, l$.name,
  505.            substr(l$.name, 1, instr(l$.name,'.')-1)),
  506.               l$.userid, l$.password, l$.host, DECODE(l$.owner#, 1, 1, 0)
  507.        FROM sys.user$ u$, sys.link$ l$
  508.        WHERE u$.user# = l$.owner#
  509. /
  510. drop view exulnku;
  511. CREATE VIEW exulnku AS                /* current user's database links */
  512.        SELECT * FROM exulnk WHERE ownerid = UID
  513. /
  514. grant select on exulnku to public;
  515.  
  516. rem all rollback segments
  517. drop view exursg;
  518. CREATE VIEW exursg (name, space$, fileno , blockno, minext, public$) AS 
  519.        SELECT r$.name, ts$.name, r$.file#, r$.block#, s$.minexts,
  520.              DECODE(r$.user#, 1, 1, 0)
  521.        FROM sys.ts$ ts$, sys.undo$ r$, sys.seg$ s$
  522.        WHERE r$.status$ != 1 AND r$.file# = s$.file# AND r$.block# = s$.block#
  523.              AND s$.ts# = ts$.ts# and r$.us# != 0
  524. /
  525.  
  526. rem info on deleted object
  527. drop view exudel;
  528. CREATE VIEW exudel (owner, name, type, type#) AS
  529.        SELECT u$.name, i$.name, DECODE(i$.type, 2, 'TABLE', 3, 
  530.               'CLUSTER', 4, 'VIEW', 5, 'SYNONYM'), i$.type
  531.        FROM sys.incexp i$, sys.user$ u$
  532.        WHERE i$.owner# = u$.user# AND
  533.              (i$.owner#, i$.name, i$.type) 
  534.              NOT IN (SELECT o$.owner#, o$.name, o$.type 
  535.              FROM   sys.obj$ o$
  536.                      WHERE  o$.linkname is null
  537.             )
  538. /
  539.  
  540. rem info on sequence number
  541. drop view exuseq;
  542. CREATE VIEW exuseq (owner, ownerid, name, objid, curval, minval, maxval, 
  543.             incr, cache, cycle, order$, audt) AS
  544.        SELECT u.name, u.user#, o.name, o.obj#, s.highwater, s.minvalue, 
  545.           s.maxvalue, s.increment$, s.cache, s.cycle, s.order$, 
  546.           substr(s.audit$, 1, 24)
  547.        FROM sys.obj$ o, sys.user$ u, sys.seq$ s
  548.        WHERE o.obj# = s.obj# AND o.owner# = u.user#
  549. /
  550. drop view exusequ;
  551. CREATE VIEW exusequ AS 
  552.        SELECT * FROM sys.exuseq WHERE UID = ownerid
  553. /
  554. grant select on sys.exusequ to public;
  555.  
  556. rem contraints on table
  557. drop view exucon;
  558. CREATE VIEW exucon (objid, owner, ownerid, tname, type, cname, cno, condition,
  559.                     condlength) AS
  560.        SELECT o.obj#, u.name, c.owner#, o.name, cd.type, 
  561.           DECODE(SUBSTR(c.name,1,5), 'SYS_C', '', NVL(c.name, '')),
  562.               c.con#, cd.condition, cd.condlength
  563.        FROM sys.obj$ o, sys.user$ u, sys.con$ c, sys.cdef$ cd
  564.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND cd.con# = c.con#
  565. /
  566. drop view exuconu;
  567. CREATE VIEW exuconu AS 
  568.        SELECT * FROM sys.exucon WHERE UID = ownerid
  569. /
  570. grant select on sys.exuconu to public;
  571.  
  572. rem referential constraints
  573. drop view exuref;
  574. CREATE VIEW exuref (objid, owner, ownerid, tname, rowner, rtname, cname, cno,
  575.                 rcno) AS
  576.        SELECT o.obj#, u.name, c.owner#, o.name, ru.name, ro.name, 
  577.               DECODE(SUBSTR(c.name, 1, 5), 'SYS_C', '', NVL(c.name, '')),
  578.           c.con#, cd.rcon#
  579.        FROM sys.user$ u, sys.user$ ru, sys.obj$ o, sys.obj$ ro, 
  580.             sys.con$ c, sys.cdef$ cd
  581.        WHERE u.user# = c.owner# AND o.obj# = cd.obj# AND ro.obj# = cd.robj# AND
  582.              cd.con# = c.con# AND cd.type = 4 AND ru.user# = ro.owner#
  583. /
  584. drop view exurefu;
  585. CREATE VIEW exurefu AS SELECT * FROM sys.exuref WHERE UID = ownerid
  586. /
  587. grant select on sys.exurefu to public;
  588. rem referential constraints for incremental and cumulative export
  589. rem for tables just exported, i.expid will be greater than v.expid
  590. rem as v.expid is incremented only at the end of the incremental export
  591. rem but i.expid is incremented when the table is exported.
  592. rem USED ONLY WHEN REOCRD = YES
  593. drop view exurefic;
  594. CREATE VIEW exurefic AS
  595.        SELECT * FROM sys.exuref 
  596.        WHERE (ownerid, tname) in 
  597.              (SELECT i.owner#, i.name 
  598.               FROM sys.incexp i, sys.incvid v
  599.               WHERE i.expid > v.expid AND i.type = 2)
  600. /
  601. rem referentail constraints for incremental export
  602. rem exutabi will return the correct table name because RECORD = NO
  603. drop view exurefi;
  604. CREATE VIEW exurefi AS
  605.        SELECT * FROM sys.exuref
  606.        WHERE (ownerid, tname) in (SELECT ownerid, name FROM sys.exutabi)
  607. /
  608. rem referentail constraints for cumulative export, assuming
  609. rem exutabc will return the correct table name because RECORD = NO
  610. drop view exurefc;
  611. CREATE VIEW exurefc AS
  612.        SELECT * FROM sys.exuref
  613.        WHERE (ownerid, tname) in (SELECT ownerid, name FROM sys.exutabc)
  614. /
  615.  
  616. rem contraint column list
  617. drop view exuccl;
  618. CREATE VIEW exuccl (ownerid, cno, colname, colno) AS
  619.        SELECT o.owner#, cc.con#, c.name, cc.pos#
  620.        FROM sys.obj$ o, sys.col$ c, sys.ccol$ cc
  621.        WHERE o.obj# = cc.obj# AND c.obj# = cc.obj# AND cc.col# = c.col#
  622. /
  623. drop view exucclu;
  624. CREATE VIEW exucclu AS
  625.        SELECT * FROM sys.exuccl WHERE UID = ownerid
  626. /
  627. grant select on sys.exucclu to public;
  628. drop view exucclo;
  629. CREATE VIEW exucclo (ownerid, cno, colname, colno) AS
  630.     SELECT a.ownerid, a.cno, a.colname, a.colno
  631.     FROM sys.exuccl a, sys.con$ b , sys.cdef$ c
  632.     WHERE b.owner#=UID
  633.     AND   b.con# = c.con#
  634.     AND   c.rcon# = a.cno
  635. /
  636. grant select on sys.exucclo to public;
  637.  
  638. rem replication constraints
  639. drop view exurep;
  640. CREATE VIEW exurep (objid, owner, ownerid, tname, rowner, rtname, cname, 
  641.             sowner, sname, scname, cno, rcno) AS
  642.     SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
  643.     FROM dual where 1=2
  644. /
  645. drop view exurepu;
  646. CREATE VIEW exurepu AS SELECT * FROM sys.exurep WHERE UID = ownerid
  647. /
  648. grant select on sys.exurepu to public;
  649.  
  650. rem replication constraints for incremental and cumulative export
  651. rem for tables just exported, i.expid will be greater than v.expid
  652. rem as v.expid is incremented only at the end of the incremental export
  653. rem but i.expid is incremented when the table is exported.
  654. rem USED ONLY WHEN REOCRD = YES
  655. drop view exurepic;
  656. CREATE VIEW exurepic AS
  657.     SELECT * from exurep
  658. /
  659. rem replication constraints for incremental export
  660. rem exutabi will return the correct table name because RECORD = NO
  661. drop view exurepi;
  662. CREATE VIEW exurepi AS
  663.     SELECT * FROM exurep
  664. /
  665. rem replication constraints for cumulative export, assuming
  666. rem exutabc will return the correct table name because RECORD = NO
  667. drop view exurepc;
  668. CREATE VIEW exurepc AS
  669.     SELECT * FROM exurep
  670. /
  671.  
  672. rem v6 export wants this table around; it was discontinued in v7
  673. create table "_system_auditing_options_" (a char(1))
  674. /
  675.