home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 28.ddi / admin / expvew5.sql < prev    next >
Encoding:
Text File  |  1991-03-04  |  26.8 KB  |  763 lines

  1. rem 
  2. rem $Header: expvew5.sql,v 6002300.1 89/06/16 01:22:15 cyang Exp $ expvew5.sql Copyr (c) 1987 Oracle
  3. rem 
  4. rem RDBMS660023,DISK$DEV1:[V6SOURCE.OLB.60023]
  5. remark  Copyright (c) Oracle Corporation 1988
  6. remark
  7. remark  NAME
  8. remark    EXPVEW5.SQL
  9. remark  FUNCTION
  10. remark    Creates V5.1-style export views so that EXP V5.1 can be 
  11. remark    used over SQL*Net to export against V6.0 for import into V5.1.
  12. remark  NOTES
  13. remark       These views are installed in SYS account.
  14. remark       Many of the views created by this file have the same names as
  15. remark    views in the file CATALOG5.SQL, which contains V5-compatible
  16. remark    data dictionary views.  If those views were created, these views
  17. remark    will replace them.
  18. remark **    Because of a 'bug' in v6, exporting more than 1 users in
  19. remark    user mode doesn't work (bug 13386).
  20. remark **    Due to changes in the password encryption algorithm, all 
  21. remark    encrypted passwords are returned as the literal 
  22. remark    'REGRANT_AFTER_IMPORT' except for the user PUBLIC, which has a
  23. remark    NULL password.  A NULL password prevents EXPORT from generating 
  24. remark    GRANT statements for the user or exporting the user's objects. 
  25. remark    The user SYS is explicitly excluded.  SYSTEM will have an invalid
  26. remark    password changed to garbage, meaning that SYS will be the only 
  27. remark    valid logon in the database.  Someone will have to log on as
  28. remark    SYS and reGRANT CONNECT to all the other users in order to 
  29. remark    restore their logons.
  30. remark **   Since EXP uses connect-by to generate to enumerate the
  31. remark    table authorizations, we cannot create TABAUTH as a view
  32. remark    as it involves joins. Instead it is created as a table to
  33. remark    so the connect-by works. Therefore, one must RECREATE
  34. remark    SYS.TABAUTH before a full database export.
  35. remark **    Storage parameters for individual indexes will be lost, since 
  36. remark    this information is not maintained in V5.  The default index
  37. remark    parameters for the tablespace are used for the INDEXPAGES of the
  38. remark    for the table.
  39. remark       The following column datatype conversions were required:
  40. remark    VARCHAR -> CHAR
  41. remark    ROWID (V6, type# = 69) -> ROWID (V5, type# = 11).
  42. remark **    Column defaults are ignored.
  43. remark **    All indexes are considered compressed, as all indexes are 
  44. remark    compressed in V6.  The IND$.COMPRESS$ column in the data
  45. remark    dictionary does not seem to be maintained, so the proper value
  46. remark    is hardcoded here.
  47. remark       V6 does not impose the V5 restriction on clustered tables
  48. remark    whereby such tables had to have at least one column in the 
  49. remark    cluster key defined as NOT NULL.  No attempt is made here to
  50. remark    address this incompatibility, in part because an export file
  51. remark    created using the V6-to-V5 method may be imported back into V6,
  52. remark    where such tables are legal.  Attempts to import into V5 tables
  53. remark    that do not comply with this restriction will fail.  The
  54. remark    table, however, can be pre-created unclustered, or can be
  55. remark    exported in table mode, which will uncluster it.
  56. remark       Since in V5 the minimum extent size was 3 blocks, extent sizes
  57. remark    of 1 and 2 blocks are converted to three blocks where feasible.
  58. remark    The one remaining possible cause of failure is as follows:
  59. remark    if a table, cluster, or the sum of all an object's indexes have
  60. remark    very little storage allocated to them, i.e., 1 or 2 blocks, then
  61. remark    if the "compress extents" export option is used, EXP will 
  62. remark    generate an ALTER SPACE DEFINITION statement that asks for an
  63. remark    initial extent of less than 3 blocks.  V5 IMP will report an
  64. remark    error on the statement, but will still be able to import the
  65. remark    object (using the previous object's space definition).  It is
  66. remark    possible to write the affected views, EXTENTS and V4EXPEXTENTS,
  67. remark    in such a way as to avoid this circumstance, but this would
  68. remark    make them even slower (they already are 5-way UNIONs).  The
  69. remark    circumstance should be rare, so the current decision seems to
  70. remark    be the right one.
  71. remark       PCTFREE of zero is valid in V6; it is not in V5.  PCTFREE of
  72. remark    zero is converted to 1.
  73. remark       COLUMNS and V4EXPCOL return SEGCOL# (column number as stored
  74. remark    in the segment) rather than COL# (column number as created)
  75. remark    for the column id because that is the way it was stored in
  76. remark    V5.  This fact required a special fix to EXP to get it
  77. remark    to export clustered tables correctly. (isn't this fixed? chin)
  78. remark 
  79. remark       See comments before view definitions for other caveats.
  80. remark    Many views come in pairs, e.g., INDEXES and V4EXPINDEX.  Comments
  81. remark    for one view of a pair generally apply for the other.
  82. remark    
  83. remark  MODIFICATION
  84. remark   Bulchan        10/06/88 - Remove connect
  85. remark    Hong          05/23/88 - make it work for TPS v6.0.19,
  86. remark                             rename to expvew5.sql.
  87. remark    Grayson       05/19/88 - Updated comments, changed exported 
  88. remark                             encrypted passwords
  89. remark    Grayson       05/18/88 - Renamed file
  90. remark                             V6TOV5EXPVIEWS.SQL -> EXP5VIEW.SQL
  91. remark    Grayson       03/26/88 - Creation
  92. remark
  93. remark  Because V5 uses a user number for non-remote synonyms,
  94. remark  such synonyms which reference users that do not exist will not
  95. remark  be exported.
  96. remark    In V5, the pid/rba/tbl was used to identify tables, views, and
  97. remark    and clusters.  V6 replaced this compound key with a single obj#.
  98. remark    The following adaptations are used here:
  99. remark    Tables:    pid/rba/tbl -> ts#/obj#/0
  100. remark    Clusters:  pid/rba/tbl -> ts#/obj#/0
  101. remark    Views:     pid/rba/tbl -> 0/obj#/0
  102. remark    Synonyms:  pid/rba/tbl -> 0/obj#/0
  103. remark
  104. remark    The SIZE parameter to the CREATE CLUSTER statement has a somewhat
  105. remark    different meaning in V6.  They are sufficiently similar, however,
  106. remark    so that they may be used interchangably.  If the SIZE stored in
  107. remark    the CLU$ table is NULL, the blocksize for the tablespace is used.
  108. remark
  109. remark    The clusters belonging to SYS are excluded, because otherwise
  110. remark    EXP will export them.
  111. remark
  112. set echo on;
  113. drop view tables
  114. /
  115. create view tables
  116.     (tab$pid, tab$rba, tab$tbl,
  117.      tab$owner, tab$name, tab$type, tab$logblk,
  118.      tab$cluster, tab$reqblk, tab$indcompr,
  119.      tab$time,
  120.      tab$sowner, tab$sname,
  121.      tab$audit, tab$comment, tab$snode, tab$sownername)
  122. as
  123. select t.ts#, o.obj#, 0,
  124.        o.owner#, o.name, 'TABLE', to_number(null),
  125.        to_number(null), to_number(null), to_char(null),
  126.        o.ctime,
  127.        to_number(null), to_char(null),
  128.        substr(t.audit$,1,22), c.comment$, to_char(null), to_char(null)
  129. from sys.obj$ o, sys.tab$ t, sys.com$ c
  130. where o.obj# = t.obj# and o.obj# = c.obj#(+) and c.col#(+) is null
  131.   and o.type = 2
  132. union
  133. select 0, o.obj#, 0,
  134.        o.owner#, o.name, 'VIEW', to_number(null),
  135.        to_number(null), to_number(null), to_char(null),
  136.        o.ctime,
  137.        to_number(null), to_char(null),
  138.        substr(v.audit$, 1, 22), to_char(null), to_char(null), to_char(null)
  139. from sys.obj$ o, sys.view$ v
  140. where o.obj# = v.obj#
  141.   and o.type = 4
  142. union
  143. select c.ts#, c.obj#, 0,
  144.        o.owner#, o.name, 'CLUSTER', nvl(c.size$, ts.blocksize),
  145.        to_number(null), nvl(c.size$, ts.blocksize), 'COMPRESS',
  146. /*     decode(i.compress$, 0, 'NOCOMPRESS', 1, 'COMPRESS'), */
  147.        o.ctime,
  148.        to_number(null), to_char(null),
  149.        to_char(null), to_char(null), to_char(null), to_char(null)
  150. from sys.obj$ o, sys.clu$ c, sys.ts$ ts /*, sys.ind$ i */
  151. where o.obj# = c.obj#
  152.   and ts.ts# = c.ts#
  153. /*and c.obj# = i.bo# (+) */
  154.   and o.type = 3
  155.   and o.owner# != 0
  156. union
  157. select 0, o.obj#, 0,
  158.        o.owner#, o.name, 'SYNONYM', to_number(null),
  159.        to_number(null), to_number(null), to_char(null),
  160.        o.ctime,
  161.        u.user#, s.name,
  162.        to_char(null), to_char(null), s.owner, s.node
  163. from sys.obj$ o, sys.syn$ s, sys.user$ u
  164. where o.obj# = s.obj#
  165.   and o.type = 5
  166.   and s.owner = u.name(+)
  167. /
  168. remark
  169. remark Column view
  170. remark
  171. drop view columns
  172. /
  173. create view columns
  174.     (col$pid, col$rba, col$tbl,
  175.      col$name,
  176.      col$datatype,
  177.      col$length, col$scale,
  178.      col$null_type,
  179.      col$id, col$comment, col$default)
  180. as
  181. select t.ts#, c.obj#, 0,
  182.        c.name,
  183.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  184.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  185.                        69, 'ROWID'),
  186.        decode(c.type#, 2, nvl(c.precision, 0), c.length), c.scale,
  187.        decode(c.null$, 0, 'NULL', 'NOT NULL'),
  188.        c.segcol#, cc.comment$, to_char(null)
  189. from sys.col$ c, sys.com$ cc, sys.tab$ t
  190. where  c.obj# = cc.obj#(+)
  191.   and  c.col# = cc.col#(+)
  192.   and  t.obj# = c.obj#
  193. union
  194. select cl.ts#, c.obj#, 0,
  195.        c.name,
  196.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  197.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  198.                        69, 'ROWID'),
  199.        decode(c.type#, 2, nvl(c.precision, 0), c.length), c.scale,
  200.        decode(c.null$, 0, 'NULL', 'NOT NULL'),
  201.        c.segcol#, cc.comment$, to_char(null)
  202. from sys.col$ c, sys.com$ cc, sys.clu$ cl
  203. where  c.obj# = cc.obj#(+)
  204.   and  c.col# = cc.col#(+)
  205.   and  cl.obj# = c.obj#
  206. union
  207. select 0, c.obj#, 0,
  208.        c.name,
  209.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  210.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  211.                        69, 'ROWID'),
  212.        decode(c.type#, 2, nvl(c.precision, 0), c.length), c.scale,
  213.        decode(c.null$, 0, 'NULL', 'NOT NULL'),
  214.        c.segcol#, cc.comment$, to_char(null)
  215. from sys.col$ c, sys.com$ cc, sys.obj$ o
  216. where  c.obj# = cc.obj#(+)
  217.   and  c.col# = cc.col#(+)
  218.   and  o.obj# = c.obj# 
  219.   and  o.type = 4
  220. /
  221. remark
  222. remark  EXP expects the EXTENTS view to return all the extents associated with
  223. remark  a table for its data and indexes.  Finding the data extents is
  224. remark  easy enough, but since indexes are dissociated from their tables
  225. remark  or clusters in V6, the third queries below associate
  226. remark  a table or cluster, respectively, to the extents allocated for
  227. remark  that object's indexes.  In V5, every table or cluster had at
  228. remark  least one extent in its index segment.  In V6, however, any table
  229. remark  or cluster with no indexes on it will naturally have no index
  230. remark  extents assocated with it.  When EXP "compresses extents" it sums
  231. remark  the lengths of the extents for each type, and if there are no
  232. remark  index extents, the sum for the indexes would naturally be zero.
  233. remark  This zero result is unacceptable because it is illegal in V5
  234. remark  to use an initial extent of zero in a space definition.
  235. remark  Thus, the last queries below create a phony index
  236. remark  extent for each table and cluster with no indexes. 
  237. remark
  238. drop view extents
  239. /
  240. create view extents
  241.     (ext$pid, ext$rba, ext$type,
  242.      ext$startblock, ext$endblock)
  243. as
  244. select t.ts#, t.obj#, 'DATA',
  245.        e.block#, e.block# + e.length - 1
  246. from sys.uet$ e, sys.tab$ t
  247. where t.file# = e.segfile#
  248.   and t.block# = e.segblock#
  249. union
  250. select cl.ts#, cl.obj#, 'DATA',
  251.        e.block#, e.block# + e.length - 1
  252. from sys.uet$ e, sys.clu$ cl
  253. where cl.file# = e.segfile#
  254.   and cl.block# = e.segblock#
  255. union
  256. select i.ts#, i.bo#, 'INDEX',
  257.        e.block#, e.block# + e.length - 1
  258. from sys.uet$ e, sys.ind$ i
  259. where i.file# = e.segfile#
  260.   and i.block# = e.segblock#
  261. union
  262. select t.ts#, t.obj#, 'INDEX',
  263.        1, decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit)
  264. from sys.tab$ t, sys.ts$ ts
  265. where t.ts# = ts.ts#
  266.   and t.obj# not in
  267.         (select i.bo#
  268.          from sys.ind$ i)
  269. union
  270. select c.ts#, c.obj#, 'INDEX',
  271.        1, decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit)
  272. from sys.clu$ c, sys.ts$ ts
  273. where c.ts# = ts.ts#
  274.   and c.obj# not in
  275.         (select i.bo#
  276.          from sys.ind$ i)
  277. /
  278. remark
  279. remark Table Authorizations
  280. remark
  281. drop table tabauth
  282. /
  283. create table tabauth
  284.   (tau$grantor, tau$grantee, tau$creator,
  285.    tau$tname, tau$time, tau$alter, tau$delete,
  286.    tau$index, tau$insert, tau$select, tau$update)
  287. as
  288. select ur.name, ue.name, uo.name, o.name, ta.time,
  289.        decode(ta.alter$,  0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' '),
  290.        decode(ta.delete$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' '),
  291.        decode(ta.index$,  0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' '),
  292.        decode(ta.insert$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' '),
  293.        decode(ta.select$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' '),
  294.        decode(ta.update$, 0, ' ', 1, '*', 2, 'Y', 3, 'G', ' ')
  295. from sys.obj$ o, sys.user$ ur, sys.user$ ue, sys.user$ uo,sys.tabauth$ ta
  296. where o.obj# = ta.obj#
  297.   and ur.user# = ta.grantor#
  298.   and ue.user# = ta.grantee#
  299.   and uo.user# = o.owner#
  300.   and o.type in (2, 4)
  301. /
  302. remark
  303. remark Views table
  304. remark
  305. drop view views
  306. /
  307. create view views
  308.     (vew$pid, vew$rba, vew$tbl,
  309.      vew$textlen, vew$text)
  310. as
  311. select 0,o.obj#, 0,
  312.        v.textlength, v.text
  313. from sys.obj$ o, sys.view$ v
  314. where o.obj# = v.obj#
  315.   and o.type = 4
  316. /
  317. remark
  318. remark  Since there are no space definitions in V6, we create an empty
  319. remark  space definitions table.
  320. remark
  321. drop table spaces
  322. /
  323. create table spaces
  324.   (
  325.   spc$name         char(30)       not null,
  326.   spc$dini         number         not null,
  327.   spc$dinc         number         not null,
  328.   spc$dmextnt      number         not null,
  329.   spc$iini         number         not null,
  330.   spc$iinc         number         not null,
  331.   spc$imextnt      number         not null,
  332.   spc$pctfree      number         not null,
  333.   spc$pid          number
  334.   )
  335.   storage (initial 4k next 4k maxextents 1 pctincrease 0)
  336. /
  337. remark
  338. remark   This view suppresses cluster indexes as they are created
  339. remark  automatically in V5.
  340. remark
  341. remark  V6 does not support the syntax for defining ascending and descending 
  342. remark  indexes.  All indexes are returned as 'ASC', because all indexes
  343. remark  were ascending in V5 anyway ('DESC' was a no-op).
  344. remark
  345. remark  Since EXP uses the IDX$CONCATID field only to determine whether an
  346. remark  index is concatenated (= 1) or not (= 0), only those values are
  347. remark  returned here.
  348. remark
  349. drop view indexes
  350. /
  351. create view indexes
  352.     (idx$pid, idx$rba, idx$tbl,
  353.      idx$owner, idx$name, idx$colseq, idx$column,
  354.      idx$unique,
  355.      idx$order,
  356.      idx$compress,
  357.      idx$concatid)
  358. as
  359. select i.ts#, i.bo#, 0,
  360.        o.owner#, o.name, ic.pos#, c.name,
  361.        decode(i.unique$, 0, 'NON UNIQUE', 1, 'UNIQUE'),
  362.        'ASC',
  363.        'COMPRESS',
  364.     /* decode(i.compress$, 0, 'NOCOMPRESS', 1, 'COMPRESS'), */
  365.        decode(i.cols, 1, 0, 1)
  366. from sys.tab$ t, sys.obj$ o, sys.ind$ i, sys.icol$ ic, sys.col$ c
  367. where o.obj# = i.obj#
  368.   and ic.obj# = i.obj#
  369.   and t.obj# = i.bo#
  370.   and c.obj# = i.bo#
  371.   and c.col# = ic.col#
  372.   and o.type = 1
  373. /
  374. remark
  375. remark  This view excludes the placeholder "_NEXT_USER", because otherwise
  376. remark  EXP will try to export it.  "PUBLIC" has a null password to prevent
  377. remark  EXP from generating a GRANT CONNECT statement for it.
  378. remark
  379. drop view userauth
  380. /
  381. create view userauth
  382.     (usr$uid, usr$name,
  383.      usr$password,
  384.      usr$time,
  385.      usr$connect,
  386.      usr$dba,
  387.      usr$resource)
  388. as
  389. select u.user#, u.name,
  390.        decode(u.name, 'PUBLIC', to_char(null), 'REGRANT_ON_IMPORT'),
  391.        u.ctime,
  392.        decode(u.connect$, 0, ' ', 1, 'Y'),
  393.        decode(u.dba$, 0, ' ', 1, 'Y'),
  394.        decode(u.resource$, 0, ' ', 1, 'Y')
  395. from sys.user$ u
  396. where u.name != '_NEXT_USER'
  397. /
  398. remark
  399. remark  Map tablespaces into partitions
  400. remark
  401. drop view partitions
  402. /
  403. create view partitions
  404.   (par$id, par$name)
  405. as
  406. select ts.ts#, ts.name
  407. from sys.ts$ ts
  408. /
  409. remark
  410. remark  Since, in V6, index storage parameters are not associated with the
  411. remark  table, as in V5, but with the tablespace, the default storage
  412. remark  parameters for the tablespace are returned here for index quotas.
  413. remark
  414. drop view segquotas
  415. /
  416. create view segquotas
  417.     (sgq$pid, sgq$rba, sgq$tbl,
  418.      sgq$dini, sgq$dinc, sgq$dmextnt,
  419.      sgq$iini, sgq$iinc, sgq$imextnt,
  420.      sgq$pctfree, sgq$date)
  421. as
  422. select t.ts#, o.obj#, 0,
  423.        decode(s.iniexts, 1, 3, 2, 3, s.iniexts),
  424.        decode(s.extsize, 1, 3, 2, 3, s.extsize),
  425.        s.maxexts,
  426.        decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit),
  427.        decode(ts.dflincr, 1, 3, 2, 3, ts.dflincr),
  428.        ts.dflmaxext,
  429.        decode(t.pctfree$, 0, 1, t.pctfree$), o.ctime
  430. from sys.seg$ s, sys.tab$ t, sys.ts$ ts, sys.obj$ o
  431. where s.file# = t.file#
  432.   and s.block# = t.block#
  433.   and s.ts# = ts.ts#
  434.   and t.obj# = o.obj#
  435.   and s.type = 5
  436.   and o.type = 2
  437. union
  438. select c.ts#, c.obj#, 0,
  439.        decode(s.iniexts, 1, 3, 2, 3, s.iniexts),
  440.        decode(s.extsize, 1, 3, 2, 3, s.extsize),
  441.        s.maxexts,
  442.        decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit),
  443.        decode(ts.dflincr, 1, 3, 2, 3, ts.dflincr),
  444.        ts.dflmaxext,
  445.        decode(c.pctfree$, 0, 1, c.pctfree$), o.ctime
  446. from sys.seg$ s, sys.clu$ c, sys.ts$ ts, sys.obj$ o
  447. where s.file# = c.file#
  448.   and s.block# = c.block#
  449.   and s.ts# = ts.ts#
  450.   and c.obj# = o.obj#
  451.   and s.type = 5
  452. /
  453. remark
  454. remark Views to get at current user's objects
  455. remark
  456. drop view v4expuser
  457. /
  458. create view v4expuser (myid, mypsswd, myprivs, myname) as
  459.   select u.user#, decode(u.name, 'PUBLIC', to_char(null), 'REGRANT_ON_IMPORT'),
  460.   decode(u.connect$, 0, ' ', 1, 'Y', ' ') ||
  461.     decode(u.dba$, 0, ' ', 1, 'Y', ' ') ||
  462.     decode(u.resource$, 0, ' ', 1, 'Y', ' '),
  463.   user
  464. from sys.user$ u
  465. where u.user# = uid
  466. /
  467. grant select on v4expuser to public
  468. /
  469. remark
  470. remark  The default parameters for the tablespace are used for index 
  471. remark  storage, since index storage is not associated with the table as in V5.
  472. remark  The name of the table's tablespace is returned as the partition 
  473. remark  name, but the file# is returned instead
  474. remark  of the ts#, since the file#/block# concept replaces pid/rba.
  475. remark
  476. drop view v4expspace
  477. /
  478. create view v4expspace
  479.   (dini, dinc, dmax, iini, iinc, imax, pctf, pname, pid, rba, tbl) as
  480. select decode(s.iniexts, 1, 3, 2, 3, s.iniexts),
  481.        decode(s.extsize, 1, 3, 2, 3, s.extsize),
  482.        s.maxexts,
  483.        decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit),
  484.        decode(ts.dflincr, 1, 3, 2, 3, ts.dflincr),
  485.        ts.dflmaxext,
  486.        decode(t.pctfree$, 0, 1, t.pctfree$),
  487.        ts.name, t.ts#, t.obj#, 0
  488. from sys.seg$ s, sys.tab$ t, sys.ts$ ts, sys.obj$ o
  489. where s.file# = t.file#
  490.   and s.block# = t.block#
  491.   and s.ts# = ts.ts#
  492.   and t.obj# = o.obj#
  493.   and s.type = 5
  494.   and o.type = 2
  495.   and s.user# = uid
  496. union
  497. select decode(s.iniexts, 1, 3, 2, 3, s.iniexts),
  498.        decode(s.extsize, 1, 3, 2, 3, s.extsize),
  499.        s.maxexts,
  500.        decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit),
  501.        decode(ts.dflincr, 1, 3, 2, 3, ts.dflincr),
  502.        ts.dflmaxext,
  503.        decode(c.pctfree$, 0, 1, c.pctfree$),
  504.        ts.name, c.ts#, c.obj#, 0
  505. from sys.seg$ s, sys.clu$ c, sys.ts$ ts, sys.obj$ o
  506. where s.file# = c.file#
  507.   and s.block# = c.block#
  508.   and s.ts# = ts.ts#
  509.   and c.obj# = o.obj#
  510.   and s.type = 5
  511.   and o.type = 3
  512.   and s.user# = uid
  513. /
  514. grant select on v4expspace to public
  515. /
  516. drop view v4expindex
  517. /
  518. create view v4expindex
  519.   (tname, usrname, usrid, iname, colname, iunique, icompr, cid, cseq) as
  520. select ot.name, user, uid, oi.name, c.name,
  521.        i.unique$,
  522.        1,
  523.     /* i.compress$, */
  524.        decode(i.cols, 1, 0, 1), ic.pos#
  525. from sys.obj$ ot, sys.obj$ oi, sys.ind$ i, sys.icol$ ic, sys.col$ c
  526. where oi.obj# = i.obj#
  527.   and ic.obj# = i.obj#
  528.   and ot.obj# = i.bo#
  529.   and c.obj# = i.bo#
  530.   and c.col# = ic.col#
  531.   and oi.type = 1
  532.   and ot.type = 2
  533.   and oi.owner# = uid
  534.   and ot.owner# = uid
  535. /
  536. grant select on v4expindex to public
  537. /
  538. drop view v4exptab
  539. /
  540. create view v4exptab (name, pid, rba, tbl, aud, cmnt) as
  541. select o.name, t.ts#, t.obj#, 0, substr(t.audit$,1,22), c.comment$
  542. from sys.obj$ o, sys.tab$ t, sys.com$ c
  543. where o.obj# = t.obj#
  544.   and o.type = 2
  545.   and  o.obj# = c.obj#(+) 
  546.   and c.col#(+) is null
  547.   and o.owner# = uid
  548. /
  549. grant select on v4exptab to public
  550. /
  551. remark
  552. remark  Clusters don't have table numbers (tbl) in V6.  It always was zero
  553. remark  in V5.
  554. remark
  555. drop view v4expclus
  556. /
  557. create view v4expclus (name, pid, rba, tbl, compr, reqblk, owner) as
  558. select o.name, c.ts#, c.obj#,
  559.        0, 1, /* i.compress$, */ nvl(c.size$, ts.blocksize), uid
  560. from sys.obj$ o, sys.clu$ c, sys.ts$ ts /*, sys.ind$ i */
  561. where o.obj# = c.obj#
  562.   and ts.ts# = c.ts#
  563. /*and c.obj# = i.bo# (+) */
  564.   and o.type = 3
  565.   and o.owner# = uid
  566. /
  567. grant select on v4expclus to public
  568. /
  569. remark
  570. remark     In V5, every table and view had a row in the TABAUTH table 
  571. remark  indicating that the table's owner had every privilege WITH
  572. remark  GRANT OPTION.  These rows aren't created in V6, but could be
  573. remark  added via a UNION.  Code for such a UNION is commented out below,
  574. remark  because EXP queries this view with a WHERE clause that ensures
  575. remark  that GRANTOR != GRANTEE.  Eliminating the UNION should improve
  576. remark  performance.
  577. remark     In addition, V6 has additional privileges that will be lost here,
  578. remark  plus allows column-level grants on privileges other than UPDATE.
  579. remark  Column-restricted grants for privileges other than UPDATE are
  580. remark  changed to be grants for the entire table.
  581. remark
  582. drop view v4exptabauth
  583. /
  584. create view v4exptabauth (object, grantor, grantee, privs, owner) as
  585. select o.name, ur.name, ue.name,
  586.        decode(ta.alter$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' ') ||
  587.        decode(ta.delete$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' ') ||
  588.        decode(ta.index$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' ') ||
  589.        decode(ta.insert$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' ') ||
  590.        decode(ta.select$, 0, ' ', 1, 'Y', 2, 'Y', 3, 'G', ' ') ||
  591.        decode(ta.update$, 0, ' ', 1, '*', 2, 'Y', 3, 'G', ' '),
  592.        user
  593. from sys.obj$ o, sys.user$ ur, sys.user$ ue, sys.tabauth$ ta
  594. where o.obj# = ta.obj#
  595.   and ur.user# = ta.grantor#
  596.   and ue.user# = ta.grantee#
  597.   and o.owner# = uid
  598.   and o.type in (2, 4)
  599. /
  600. remark
  601. remark  union
  602. remark  select o.name, user, user,
  603. remark       'GGGGGG', user
  604. remark  from sys.obj$ o
  605. remark  where o.owner# = uid
  606. remark    and o.type in (2, 4)
  607. remark
  608. grant select on v4exptabauth to public
  609. /
  610. drop view v4expextents
  611. /
  612. create view v4expextents (pid, rba, type, sblock, eblock)
  613. as
  614. select t.ts#, t.obj#, 'DATA',
  615.        e.block#, e.block# + e.length - 1
  616. from sys.uet$ e, sys.tab$ t, sys.obj$ o
  617. where t.file# = e.segfile#
  618.   and t.block# = e.segblock#
  619.   and t.obj# = o.obj#
  620.   and o.owner# = uid
  621. union
  622. select cl.ts#, cl.obj#, 'DATA',
  623.        e.block#, e.block# + e.length - 1
  624. from sys.uet$ e, sys.clu$ cl, sys.obj$ o
  625. where cl.file# = e.segfile#
  626.   and cl.block# = e.segblock#
  627.   and cl.obj# = o.obj# 
  628.   and o.owner# = uid
  629. union
  630. select i.ts#, i.bo#, 'INDEX',
  631.        e.block#, e.block# + e.length - 1
  632. from sys.uet$ e, sys.ind$ i, sys.obj$ o
  633. where i.file# = e.segfile#
  634.   and i.block# = e.segblock#
  635.   and i.bo# =  o.obj#
  636.   and o.owner# = uid
  637. union
  638. select t.ts#, t.obj#, 'INDEX',
  639.        1, decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit)
  640. from sys.tab$ t, sys.ts$ ts, sys.obj$ o
  641. where t.ts# = ts.ts#
  642.   and t.obj# = o.obj# 
  643.   and o.owner# = uid
  644.   and t.obj# not in
  645.         (select i.bo#
  646.          from sys.ind$ i)
  647. union
  648. select c.ts#, c.obj#, 'INDEX',
  649.        1, decode(ts.dflinit, 1, 3, 2, 3, ts.dflinit)
  650. from sys.clu$ c, sys.ts$ ts, sys.obj$ o
  651. where c.ts# = ts.ts#
  652.   and c.obj# = o.obj#
  653.   and o.owner# = uid
  654.   and c.obj# not in
  655.         (select i.bo#
  656.          from sys.ind$ i)
  657. /
  658. grant select on v4expextents to public
  659. /
  660. remark
  661. remark     Views had pid's and rba's in V5, since they actually required
  662. remark  storage in the database.  In V6, views require no storage, and
  663. remark  thus have no file#, block#, or tab# associated with them.  
  664. remark     V6 has a new ROWID type (69) because it is incompatible with the
  665. remark  V5 ROWID.  This is cast to the V5 ROWID, but it may not work
  666. remark  correctly.  (If this doesn't work, considering it a CHAR may
  667. remark  permit a valid conversion.)  Similarly, the V6 VARCHAR datatype
  668. remark  is converted to CHAR.  Since the V5 COL$DATATYPE column was
  669. remark  defined to be one character too narrow to hold the words "LONG 
  670. remark  RAW", LONG RAWs were always considered LONG in the V5 data
  671. remark  dictionary.  Here, LONG RAW remains LONG RAW in the hopes that
  672. remark  EXP and IMP can treat them appropriately, but this may fail.
  673. remark  In V5, a column's default value was always NULL, and there was
  674. remark  no way to get it into the data dictionary.  The default can be
  675. remark  specified and stored in V6.0 (although it is ignored).  This view
  676. remark  always return NULL for the default, however, because in V6 it is
  677. remark  stored as a LONG and in V5 it is CHAR(240) and is useless anyway.
  678. remark
  679. drop view v4expcol
  680. /
  681. create view v4expcol
  682.     (rba, tbl, pid, name, length, scale, type, mand, id, cmnt, dflt ) as
  683. select t.obj#, 0, t.ts#, c.name,
  684.        decode(c.type#, 2, nvl(c.precision, 0), c.length),
  685.        nvl(c.scale, 0),
  686.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  687.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  688.                        69, 'ROWID'),
  689.        decode(c.null$, 0, 0, 1, 1, 1), c.segcol#, cc.comment$, to_char(null)
  690. from sys.obj$ o, sys.tab$ t, sys.col$ c, sys.com$ cc
  691. where o.obj# = t.obj#
  692.   and t.obj# = c.obj#
  693.   and c.obj# = cc.obj#(+)
  694.   and c.col# = cc.col#(+)
  695.   and o.owner# = uid
  696.   and o.type = 2
  697. union
  698. select cl.obj#, 0, cl.ts#, c.name,
  699.        decode(c.type#, 2, nvl(c.precision, 0), c.length),
  700.        nvl(c.scale, 0),
  701.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  702.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  703.                        69, 'ROWID'),
  704.        decode(c.null$, 0, 0, 1), c.segcol#, cc.comment$, to_char(null)
  705. from sys.obj$ o, sys.clu$ cl, sys.col$ c, sys.com$ cc
  706. where o.obj# = cl.obj#
  707.   and cl.obj# = c.obj#
  708.   and c.obj# = cc.obj#(+)
  709.   and c.col# = cc.col#(+)
  710.   and o.owner# = uid
  711.   and o.type = 3
  712. union
  713. select o.obj#, 0, 0, c.name,
  714.        decode(c.type#, 2, nvl(c.precision, 0), c.length),
  715.        nvl(c.scale, 0),
  716.        decode(c.type#, 1, 'CHAR', 2, 'NUMBER', 8, 'LONG', 9, 'CHAR',
  717.                        11, 'ROWID', 12, 'DATE', 23, 'RAW', 24, 'LONG RAW',
  718.                        69, 'ROWID'),
  719.        decode(c.null$, 0, 0, 1), c.segcol#, cc.comment$, to_char(null)
  720. from sys.obj$ o, sys.col$ c, sys.com$ cc
  721. where o.obj# = c.obj#
  722.   and c.obj# = cc.obj#(+)
  723.   and c.col# = cc.col#(+)
  724.   and o.owner# = uid
  725.   and o.type = 4
  726. /
  727. grant select on v4expcol to public
  728. /
  729. remark
  730. remark  Remote synonyms are excluded here because the inconsistent way
  731. remark  they were stored in the V5 data dictionary prevented them from
  732. remark  appearing in the V5 V4EXPSYN view.  They wouldn't have been 
  733. remark  exported correctly anyway because EXP doesn't look for the name
  734. remark  of the database link.
  735. remark
  736. drop view v4expsyn
  737. /
  738. create view v4expsyn (name, sname, sowner, stime) as
  739. select o.name, s.name, s.owner, o.ctime
  740. from sys.obj$ o, sys.syn$ s
  741. where o.obj# = s.obj#
  742.   and o.type = 5
  743.   and o.owner# = uid
  744.   and s.node is null
  745. /
  746. grant select on v4expsyn to public
  747. /
  748. drop view v4expview
  749. /
  750. create view v4expview
  751.     (name, pid, rba, tbl, aud, cmnt, vtime, vlen, vtext) as
  752. select o.name, 0, o.obj#, 0, substr(v.audit$,1,22), c.comment$,
  753.        o.ctime, v.textlength, v.text
  754. from sys.obj$ o, sys.view$ v, sys.com$ c
  755. where o.obj# = v.obj#
  756.   and o.type = 4
  757.   and o.obj# = c.obj#(+)
  758.   and c.col# is null
  759.   and o.owner# = uid
  760. /
  761. grant select on v4expview to public
  762. /
  763.