標籤:blog creat tns admin 比較 最佳化器 字典 開啟 響應
1、 AIX環境下查看oracle配置資訊(service_name、SID、tnsname)。
SID:
echo $ORACLE_SID
service_name:
sqlplus / as sysdba;
show parameter instance_name;
show parameter service_names;
show parameter service;
select instance_namefrom v$instance;
tnsname:
netca 查看;
tnsnames.ora查看:開啟network/admin下的tnsnames.ora檔案:
find . –name “tnsnames.ora” ;
cat tnsnames.ora
2、 在無TNS配置時,登入到資料庫。
sqlplus user/[email protected]:port/servicename
sqlplususer/[email protected]
sqlplususer/pwd---aix
sqlplus/nolog>connect user/pwd
sqlplus/ as sysdba
格式一:jdbc:oracle:thin:@//<host>:<port>/<service_name>
格式二:jdbc:oracle:thin:@<host>:<port>:<SID>
格式三:jdbc:oracle:thin:@< tnsname >
3、 快速複製一張表,並在此建立索引。
複製表結構及其資料
create table table_name_new as select * from table_name_old
只複製表結構
create table table_name_new as select * from table_name_oldwhere 1=2
只複製表資料
insert into table_name_new select * from table_name_old
表結構不一樣
insert into table_name_new(column1,column2...) selectcolumn1,column2... from table_name_old
複製表結構及其資料不寫日誌
create table table_name_new nologging as select * fromtable_name_old
設定並行度
create table testa2 (t1 int) parallel;
commit;
插入資料不寫日誌
alter table table_name NOLOGGING;
再修改寫日誌
alter table table_name LOGGING;
並行度:
查看dba_tables資料字典時,可以發現有“DEGREE”欄位,這個欄位表示的就是資料表的並行度。這個參數的設定,關係著資料庫的I/O,以及sql的執行效率。當設定表的並行度非常高的時候,sql最佳化器將可能對錶進行全表掃描,引起 Direct Path Read 等待。
在使用並行查詢前需要謹慎考慮,因為並行查詢儘管能提高程式的回應時間,但是會
消耗比較多的資源。
alter table t parallel(degree 1);------直接指定表的並行度
alter table t parallel; ----------設定表的並行度為default
建立索引:
create [unique]index index_name on table_name(column_name[,column_name…])
4、 Oracle11g 資料庫的匯入匯出。
匯出:
全部:
exp imagesys/[email protected] file=/icms/20170116.dmp full=y
使用者:
exp imagesys/imagesys @orcl file=/icms/20170116.dmp owner=imagesys
exp system file=/icms/lims2017116.dmp log=/icms/icms.logowner=imagesys
表:
exp imagesys/[email protected] file=/icms/lims2017116.dmptables=(table1,table2)
匯出空表sql語句
select ‘alter table ‘||table_name||‘ allocate extent;‘ fromuser_tables where segment_created=‘NO‘
匯入:
全部:
imp imagesys/[email protected] buffer=64000 file=/icms/lims2017116.dmpFULL=Y
使用者:
imp imagesys/[email protected] file=/icms/lims2017116.dmp fromuser=imagesys touser=imagesys
5、 命令列將表查詢結果輸出到txt裡
spool E:\log.txt;
select id,name from users;
spool off;
6、 AIX 、WIN寫指令碼形式串連資料庫並將查詢結果輸出到文字檔。
Bat:
sqlplus arch/[email protected] @E:\runsql\log.sql>log1.txt
sh:
sqlplus imagesys/imagesys @log.sql>log1.txt
oracle 基礎知識