useful_oracle_commands

advertisement
Oracle Commands:
Index
Sql> select count(*) from PROJECT_SKILL;
Sql> create index ind_prj_skl on PROJECT_SKILL(p_id);
Sql> drop index ind_prj_skl;
Sql> Select index_name from user_indexes;
Sql> Select index_name from user_indexes where table_name = ‘employee’;
Check the account name.
Sql> select user from dual;
Set header off
Sql> set head off
-- select subset of tables:
Sql> select tname from tab where tname like 'E%';
--Replace contents in a table
Sql> update np set word = replace (word,'_',' ');
-- select part of a table
Sql> select * from np where word > 'C%' and word < 'D%';
-- change a column type
Sql> alter table np modify (word varchar2(70));
Look at Sequence names
SQL> select sequence_name from user_sequences;
SEQUENCE_NAME
-----------------------------INV_ID_SEQUENCE
INV_ID_SQUENCE
ORDER_ID_SEQUEMCE
ORDER_ID_SEQUENCE
PROJECT_ID_SEQUEMCE
PROJECT_ID_SEQUENCE
6 rows selected.
Add Column Example
The following statement adds a column named THRIFTPLAN of datatype NUMBER with a
maximum of seven digits and two decimal places and a column named LOANCODE of datatype
CHAR with a size of one and a NOT NULL integrity constraint:
Sql> ALTER TABLE emp
ADD (thriftplan NUMBER(7,2),
loancode CHAR(1) NOT NULL);
Modify Column Examples
The following statement increases the size of the THRIFTPLAN column to nine digits:
Sql> ALTER TABLE emp
MODIFY (thriftplan NUMBER(9,2));
Drop Constraint Examples
The following statement drops the primary key of the DEPT table:
Sql> ALTER TABLE dept
DROP PRIMARY KEY CASCADE;
If you know that the name of the PRIMARY KEY constraint is PK_DEPT, you could also drop it
with the following statement:
Sql> ALTER TABLE dept
DROP CONSTRAINT pk_dept CASCADE;
The CASCADE clause drops any foreign keys that reference the primary key.
The following statement drops the unique key on the DNAME column of the DEPT table:
Sql> ALTER TABLE dept
DROP UNIQUE (dname);
Rename a table:
Sql> ALTER TABLE emp RENAME TO employee;
Rename a column
Sql> ALTER TABLE table_name
Rename column old_name to new_name;
Look at sequence names
SQL> select sequence_name from user_sequences;
SEQUENCE_NAME
-----------------------------INV_ID_SEQUENCE
INV_ID_SQUENCE
ORDER_ID_SEQUEMCE
ORDER_ID_SEQUENCE
PROJECT_ID_SEQUEMCE
PROJECT_ID_SEQUENCE
6 rows selected.
Oracle8i Administrator's Guide
23 Managing Users and Resources (Oracle Documentation)
To see the current number of named users defined in the database
SELECT COUNT(*) FROM dba_users;
The following query lists users and their associated information as defined in the database:
SELECT username, profile, account_status from dba_users;
SELECT username
from dba_users
where username not like ‘M%’;
SELECT username, account_status from dba_users
Where account_status = ‘OPEN’
Order by username;
REUTERS21578
REUTERS_D1
REUTERS_D2
SCONLON
SCOTT
SUMALI
OPEN
OPEN
OPEN
OPEN
OPEN
OPEN
The following statement expires the password:
ALTER USER userscott PASSWORD EXPIRE;
Oracle8i Administrator's Guide
SQL*Loader
Database Administrator Utilities
Export and Import
4 SQL*Loader Case Studies *** put Orcle 8 cd in drive D’
The Case Studies
This chapter contains the following case studies:
Case 1: Loading Variable-Length Data
Loads stream format records in which the fields are delimited by commas and may be enclosed by
quotation marks. The data is found at the end of the control file.
Case 2: Loading Fixed-Format Fields:
Loads a datafile with fixed-length fields, stream-format records, all records the same length.
Case 3: Loading a Delimited, Free-Format File
Loads data from stream format records with delimited fields and sequence numbers. The data is
found at the end of the control file.
Case 4: Loading Combined Physical Records
Combines multiple physical records into one logical record corresponding to one database row
Case 5: Loading Data into Multiple Tables
Loads data into multiple tables in one run
Case 6: Loading Using the Direct Path Load Method
Loads data using the direct path load method
Case 7: Extracting Data from a Formatted Report
Extracts data from a formatted report
Case 8: Loading Partitioned Tables
Loads partitioned tables.
Case 9: Loading LOBFILEs (CLOBs)
Adds a CLOB column called RESUME to the table emp, uses a FILLER field (RES_FILE), and
loads multiple LOBFILEs into the emp table.
Download