(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
This lesson covers heap tables
See Appendix C for Other Table Types
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table t
2 (c1 number )
3 organization heap
4 tablespace ts1
5 nologging
6 nocompress
7 nomonitoring
8 storage (buffer_pool default)
9 initrans 5
10 maxtrans 5
11 /
Table created.
Table Name – 1 to 30 characters
Heap is default organization
All parameters used here are discussed in this lesson
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table test
2 (c1 date DEFAULT sysdate);
Table created.
SQL> insert into test
2 values(DEFAULT);
1 row created.
CREATE TABLE table-name
(col-name datatype [DEFAULT expr] [constraint]
[
,col-name datatype [DEFAULT expr] [constraint] . . .
] )
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table t2
2 (c1 number(10,2),
3 c2 varchar2(50),
4 c3 clob);
Table created.
SQL> insert into t2
2 values(12345678.99, 'x', 'x')
3 /
1 row created.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
Date
2002-11-01 12:00:00
Timestamp
03-NOV-02 03.00.00.000000 AM
Timestamp with Local Time Zone
03-NOV-02 03.00.00.000000 AM -07:00
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table daves_pictures
2 (id number primary key,
3 description varchar(200),
4 picture blob not null);
Table created.
SQL> create directory boat as 'c:\boat';
Directory created.
SQL> declare
2 l_bfile bfile;
3 l_blob blob;
4 begin
5 insert into daves_pictures (id, picture)
6 values(s1.nextval, empty_blob)
7 returning picture into l_blob;
8 l_bfile := bfilename('BOAT', 'boat001.jpg');
9 dbms_lob.fileopen( l_bfile );
10 dbms_lob.loadfromfile( l_blob, l_bfile,
11 dbms_lob.getlength(l_bfile) );
12 dbms_lob.fileclose( l_bfile );
13 commit;
14 end;
15 /
PL/SQL procedure successfully completed.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> select rowid from t;
ROWID
------------------
AAAHfxAAHAAAAGOAAA
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table t1 (c1 , c2) as
2 select owner, table_name
3 from dba_tables
4 where owner='SCOTT';
SQL> desc t1
Name Null? Type
------------- -------- -------------
C1 NOT NULL VARCHAR2(30)
C2 NOT NULL VARCHAR2(30)
Only not null constraints are created
Uses datatype of source columns
SQL> create table t2
2 tablespace users as
3 select * from dba_users;
Table created.
SQL> select count(*) from t2;
COUNT(*)
----------
19
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> create table emp as
2 select * from scott.emp
3 where 1=0;
Table created.
1 create table emp2 (name_job) as
2 select ename || ' ' || job
3* from scott.emp
SQL> /
Table created.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
GATHER_TABLE_STATS, GATHER_SCHEMA_STATS etc.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> exec dbms_stats.gather_schema_stats(user, -
> cascade=>true, -
> method_opt=>'for columns skewonly')
PL/SQL procedure successfully completed.
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
(If applicable)
Other Text:
(Examples or comments displayed on slide, if any).
SQL> begin
2 for x in ( select username
3 from dba_users
4 where username not in ( 'SYS', 'SYSTEM' ) )
5 loop
6 dbms_output.put_line('gathering stats for '||x.username);
7 dbms_stats.gather_SCHEMA_stats(x.username,
8 cascade=>true,
9 method_opt=>'for columns skewonly',
10 granularity=>'all',