Work oracle common actions

Common database operations

Start the database listener lsnrctl start
stop the database listener
lsnrctl stop
sign in the Oracle
sqlplus / AS sysdba
start oralce
the Startup;
shut down the Oracle
the shutdown load immediate;

Database data file is damaged due to mountains
Startup Mount
ALTER Database 21 is Offline datafile drop;
ALTER Database Recover datafile '/u01/app/oracle/oradata/test.dbf';
ALTER Database datafile '/ u01 / App / Oracle / oradata / Test.dbf 'Online;
ALTER Open Database;

Create a table space
the CREATE TABLESPACE the Test
DATAFILE '/u01/app/oracle/oradata/test.dbf'
SIZE 32M
AUTOEXTEND ON
the NEXT 32M MAXSIZE UNLIMITED
the EXTENT MANAGEMENT the LOCAL;
lookup table space data file
the SELECT tablespace_name, file_id, file_name, bytes
the FROM dba_data_files the ORDER BY tablespace_name;
add data files to table space for
the ALTER tABLESPACE the Test the ADD DATAFILE
'/u01/app/oracle/oradata/test02.dbf' SIZE 1G
AUTOEXTEND the NEXT ON MAXSIZE 1G 30G;
create user
create user username identified by password default tablespace table space;
Connect assigned to user roles, Resource roles and DBA role
grant connect, resource, dba to username;
assigned to the remote user permissions (access another user's table need this permission)
Grant All privileges to the user name

Database Export:
expdp username / password @ database server IP: 1521 / examples of the database schemas = User name directory = DATA_PUMP_DIR DUMPFILE = .DMP need to export the backup files generated by the export log LOGFILE = .log
export certain table parameter
tables = schema1.table1, schema1.table2
the DATA_PUMP_DIR data pump export directory is the default storage directory import mode, in particular path oracle / oracle installation path in the ADMIN / ORCL (example) / dpdump
into the database:
IMPDP username / password database server @ IP: 1521 / examples of the database directory = DATA_PUMP_DIR DUMPFILE = log .log REMAP_SCHEMA backup files to be imported and introducing the produced .DMP LOGFILE = source username =: = target user name REMAP_TABLESPACE the source tablespace: target space TRANSFORM = OID: N , SEGMENT_ATTRIBUTES: N SKIP_UNUSABLE_INDEXES = Y TABLE_EXISTS_ACTION = truncate
table parameters present
TABLE_EXISTS_ACTION = Skip
TABLE_EXISTS_ACTION = Replace

Common sql statement

清除表重复数据
delete from test where rowid in(
select max(rowid) From test group by year,admdivid,expfuncid,expecoid,projectid having count(*)>1)

MERGE command, if there is data in the database to update, if there is no insert.
The INTO the TEST Tl the MERGE
the USING (the SELECT '2' AS ID, 'newtest2' Dual the FROM NAME AS) T2 ON (= t1.id t2.ID)
the WHEN MATCHED THEN
the UPDATE = T2.NAME the SET t1.name
the WHEN the NOT MATCHED THEN
the INSERT ( t1.ID, t1.NAME) VALUES (t2.ID, T2.NAME);

intersect is the intersection, the intersection is the result set has two elements in
the SELECT uid from tb1
intersect
the SELECT uid from tb2
so there was not only tb1 and there tb2 same UID will check out
minus a difference set
the SELECT uid from tb1
minus
the SELECT uid from tb2
present in tb1 but not in tb2 the uid is found

- See Table locked
SELECT b.owner, b.object_name, a.session_id, a.locked_mode locked_object from V $ A, B WHERE b.object_id dba_objects = a.object_id;
- Check that the user that the process according to death lock
the SELECT b.username, b.sid, b.serial #, LOGON_TIME from v $ locked_object a, v $ a.session_id the session the WHERE b = b.sid the Order by b.logon_time;
- see attached process
SELECT sid, serial #, username, the FROM v $ OSUSER the session;
- found locked tables sid, serial #, os_user_name, machine_name , terminal, lock of the type, the MODE
the SELECT s.sid, s.serial #, s.username, s.schemaname , s.osuser, s.process, s.machine,
s.terminal, s.logon_time, the session l.type the FROM $ V S, V $ L Lock
the WHERE s.sid the IS = l.sid the AND s.username the ORDER the NOT NULL sid BY;
/ * this statement will look to lock the database of all the DML statements generated, can also be found,
any DML statements actually had two locks, one lock table, a row lock. * /
- kill the process sid, Serial #
the ALTER System session'210,11562 the kill ';

Guess you like

Origin www.cnblogs.com/kdy11/p/11419766.html