IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Oracle Discussion :

[SQL] DDL d'un tablespace


Sujet :

Oracle

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2002
    Messages : 82
    Points : 49
    Points
    49
    Par défaut [SQL] DDL d'un tablespace
    db=oracle9i
    os=win2k

    Bonjour,

    J'aimerais retrouver le code sql de la création d'un tablespace en me connectant en sys via sqlplus...
    Ce code source n'est pas repris dans les vues dba_source et db_objects.

    Merci pour vos informations,

    Magnum_head,
    L'expérience est une lanterne qui n'éclaire que le chemin déjà parcouru.

  2. #2
    Expert éminent sénior
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Points : 19 073
    Points
    19 073
    Par défaut
    Oracle propose de nombreux scripts : http://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=131704.1

    Dont :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    REM
    REM                    SCRIPT FOR CREATING TABLESPACES
    REM
    REM This script must be run by a user with the DBA role.
    REM
    REM Running this script will in turn create a script to build all the
    REM tablespaces in the database.  This created script, create_tablespaces.sql,
    REM can be run by any user with the DBA role or with the 'CREATE TABLESPACE'
    REM system privilege.
    REM
     
    set verify off;
    set termout off;
    set feedback off;
    set echo off;
    set pagesize 0;
     
    set termout on;
    select 'Creating tablespace build script...' from dual;
    set termout off;
     
    create table ts_temp (lineno number, ts_name varchar2(30),
                        text varchar2(800));
     
    DECLARE
       CURSOR ts_cursor IS select   tablespace_name,
                                    initial_extent,
                                    next_extent,
                                    min_extents,
                                    max_extents,
                                    pct_increase,
                                    status
                            from    sys.dba_tablespaces
                            where tablespace_name != 'SYSTEM'
                            and status != 'INVALID'
                            order by tablespace_name;
       CURSOR df_cursor (c_ts VARCHAR2) IS select   file_name,
                                                    bytes
                                           from     sys.dba_data_files
                                           where    tablespace_name = c_ts
                                             and    tablespace_name != 'SYSTEM'
                                           order by file_name;
       lv_tablespace_name   sys.dba_tablespaces.tablespace_name%TYPE;
       lv_initial_extent    sys.dba_tablespaces.initial_extent%TYPE;
       lv_next_extent       sys.dba_tablespaces.next_extent%TYPE;
       lv_min_extents       sys.dba_tablespaces.min_extents%TYPE;
       lv_max_extents       sys.dba_tablespaces.max_extents%TYPE;
       lv_pct_increase      sys.dba_tablespaces.pct_increase%TYPE;
       lv_status            sys.dba_tablespaces.status%TYPE;
       lv_file_name         sys.dba_data_files.file_name%TYPE;
       lv_bytes             sys.dba_data_files.bytes%TYPE;
       lv_first_rec         BOOLEAN;
       lv_string            VARCHAR2(800);
       lv_lineno            number := 0;
     
       procedure write_out(p_line INTEGER, p_name VARCHAR2,
                 p_string VARCHAR2) is
       begin
         insert into ts_temp (lineno, ts_name, text) values
                (p_line, p_name, p_string);
       end;
     
    BEGIN
       OPEN ts_cursor;
       LOOP
          FETCH ts_cursor INTO lv_tablespace_name,
                               lv_initial_extent,
                               lv_next_extent,
                               lv_min_extents,
                               lv_max_extents,
                               lv_pct_increase,
                               lv_status;
          EXIT WHEN ts_cursor%NOTFOUND;
          lv_lineno := 1;
          lv_string := ('CREATE TABLESPACE '||lower(lv_tablespace_name));
          lv_first_rec := TRUE;
          write_out(lv_lineno, lv_tablespace_name, lv_string);
          OPEN df_cursor(lv_tablespace_name);
          LOOP
             FETCH df_cursor INTO lv_file_name,
                                  lv_bytes;
             EXIT WHEN df_cursor%NOTFOUND;
             if (lv_first_rec) then
                lv_first_rec := FALSE;
                lv_string := 'DATAFILE ';
             else
                lv_string := lv_string || ',';
             end if;
             lv_string:=lv_string||''''||lv_file_name||''''||
                        ' SIZE '||to_char(lv_bytes) || ' REUSE';
          END LOOP;
          CLOSE df_cursor;
             lv_lineno := lv_lineno + 1;
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_lineno := lv_lineno + 1;
             lv_string := (' DEFAULT STORAGE (INITIAL ' ||
                          to_char(lv_initial_extent) ||
                          ' NEXT ' || lv_next_extent);
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_lineno := lv_lineno + 1;
             lv_string := (' MINEXTENTS ' ||
                          lv_min_extents ||
                          ' MAXEXTENTS ' || lv_max_extents);
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_lineno := lv_lineno + 1;
             lv_string := (' PCTINCREASE ' ||
                          lv_pct_increase || ')');
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_string := ('   '||lv_status);
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_lineno := lv_lineno + 1;
             lv_string:='/';
             write_out(lv_lineno, lv_tablespace_name, lv_string);
             lv_lineno := lv_lineno + 1;
             lv_string:='                                                  ';
             write_out(lv_lineno, lv_tablespace_name, lv_string);
       END LOOP;
       CLOSE ts_cursor;
    END;
    /
     
    spool create_tablespaces.sql
    set heading off
    set recsep off
    col text format a80 word_wrap
     
     
    select   text
    from     ts_temp
    order by ts_name, lineno;
     
    spool off;
     
    drop table ts_temp;
     
    exit
     
     
     
    ==============
    Sample Output: 
    ==============
     
    CREATE TABLESPACE company03                                                     
    DATAFILE '/oracle/8.1.6/dbs/company_t1' SIZE 5242880 REUSE                      
    DEFAULT STORAGE (INITIAL 51200 NEXT 51200                                       
    MINEXTENTS 2 MAXEXTENTS 50                                                      
    PCTINCREASE 50)                                                                 
    ONLINE                                                                          
    /                                                                               
     
    CREATE TABLESPACE data                                                          
    DATAFILE '/database/816/V816/data.dbf' SIZE 157286400                           
    REUSE,'/database/816/V816/data02.dbf' SIZE 209715200 REUSE                      
    DEFAULT STORAGE (INITIAL 10240 NEXT 10240                                       
    MINEXTENTS 1 MAXEXTENTS 121                                                     
    PCTINCREASE 50)                                                                 
    ONLINE                                                                          
    /           
     
    CREATE TABLESPACE invoice_dat                                                   
    DATAFILE '/database/816/V816/tangr.dbf' SIZE 20971520 REUSE                     
    DEFAULT STORAGE (INITIAL 10240 NEXT 10240                                       
    MINEXTENTS 1 MAXEXTENTS 121                                                     
    PCTINCREASE 50)                                                                 
    ONLINE                                                                          
    /    
    ...

  3. #3
    Rédacteur

    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 320
    Points : 3 798
    Points
    3 798
    Par défaut
    Bonjour
    et alors à quoi sert la fonction rechercher

    package dbms_METADATA


    Jaouad

  4. #4
    Expert éminent sénior
    Avatar de orafrance
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    15 967
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 15 967
    Points : 19 073
    Points
    19 073
    Par défaut
    ha oui, c'est plus malin ça

  5. #5
    Rédacteur

    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 320
    Points : 3 798
    Points
    3 798
    Par défaut
    Citation Envoyé par Fred_D
    ha oui, c'est plus malin ça
    Par contre ton script est bien pour une 8i

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2002
    Messages : 82
    Points : 49
    Points
    49
    Par défaut
    Merci beaucoup

    J'ai donc éxcécuté
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    select dbms_metadata.get_ddl('TABLESPACE','MONTABLESPACE') from dual;
     
    CREATE TABLESPACE "MONTABLESPACE" DATAFILE
    'N:\ORADATA\MONTABLESPACE.DBF
    Ce qui m'étonne c'est que je ne retrouve pas mais option sur size, reuse blocksize, extent management,...

    Est-ce normal ? Ou problème d'affichage...
    L'expérience est une lanterne qui n'éclaire que le chemin déjà parcouru.

  7. #7
    Rédacteur

    Profil pro
    Inscrit en
    Janvier 2005
    Messages
    2 320
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 320
    Points : 3 798
    Points
    3 798
    Par défaut
    Que ne ferais t'on pas pour nos chéres VIP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    SQL> select dbms_metadata.get_ddl('TABLESPACE','OLTS_CT_DN') from dual ; 
     
    DBMS_METADATA.GET_DDL('TABLESPACE','OLTS_CT_DN')
    --------------------------------------------------------------------------------
     
      CREATE TABLESPACE "OLTS_CT_DN" DATAFILE
      'E:\ORACLE\ORADATA\OIDPRD\DNCAT1_O
     
     
    SQL> set long 4000
    SQL> r
      1* select dbms_metadata.get_ddl('TABLESPACE','OLTS_CT_DN') from dual
     
    DBMS_METADATA.GET_DDL('TABLESPACE','OLTS_CT_DN')
    --------------------------------------------------------------------------------
     
      CREATE TABLESPACE "OLTS_CT_DN" DATAFILE
      'E:\ORACLE\ORADATA\OIDPRD\DNCAT1_OIDPRD.DBF' SIZE 2097152 REUSE
      AUTOEXTEND ON NEXT 1048576 MAXSIZE UNLIMITED
      LOGGING ONLINE PERMANENT BLOCKSIZE 4096
      EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1048576 SEGMENT SPACE MANAGEMENT MANUAL

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2002
    Messages : 82
    Points : 49
    Points
    49
    Par défaut
    Géniale

    Merci pour votre gentillesse et A+
    L'expérience est une lanterne qui n'éclaire que le chemin déjà parcouru.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 14/04/2008, 10h18
  2. [SQL Server 2005]Trigger DDL -> Nom Table Modifiée
    Par Yotho dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 26/06/2007, 11h11
  3. Utilisation du tablespace TEMP lors d'une requête SQL
    Par dyvim dans le forum Administration
    Réponses: 2
    Dernier message: 31/05/2007, 19h15
  4. [Oracle ordre DDL en PL/SQL]
    Par tesla dans le forum SQL
    Réponses: 7
    Dernier message: 05/10/2006, 16h13
  5. [SQL] DDL d'une fonction
    Par noirot dans le forum Oracle
    Réponses: 2
    Dernier message: 14/02/2006, 17h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo