日常技術積累

sembh發表於2010-07-08

提個問題:區域性索引和全域性索引區別這類問題有什麼區別?全域性分割槽索引,全域性非分割槽索引,本地分割槽索引,本地非分割槽索引...

pctfree: 一般把該引數設定為10,參數列示塊中預留的空餘空間比例。比如 pctfree 20 pctused 80.這樣空間的空閒比不能超過20%,超過將無法作update,insert操作。也就是說當這個塊大於20%的時候,這個塊就不可用。只有小於這個值,這個塊才可用。注意單位為:資料塊。

initrans: 一般把該引數設定為1或者2。表示初始化了一個block的同時能併發進行的事務數,隨著事務數量增加可以達到maxtrans上界(trans = transaction)
如果資料庫中平均每天有800個會話,至少會有100個以上的會話會同時訪問表A,請問表A的INITRANS引數該如何設定比較好呢?思考下吧.

看段建表空間的指令碼:

tablespace safa
pctfree 10
initrans 1
maxtrans 255
storage
{
initial 16k
minextents 1
maxextents unlimited
}

initial 一般設定為16k,或者64k.
具體大小取決於該表的儲存策略
如果你的這個表預期會超過100M,你初始設定可以設為50M,next可以設為1M,pctincrease一般設為0。如果這個表預期不會超過20M,你可以設定初始128k,next128k。如果建立這個表之後,你馬上要匯入500M的資料,這種情況下如果你把表的initial設定為1M,next1M, 匯入過程就需要很長時間,因為在匯入過程中oracle要不斷的分配空間,如果initial設定為1000M,那麼相比之下匯入過程會快很多,因為在建立表的時候oracle就已經給它分配了1000M,匯入過程中不需要擴充套件空間。也可以
選擇預設分配。minextents 1 maxextents unlimited。

事務就是一個單元的工作,包括一系列的操作這些操作要麼全部成功,要麼全部失敗。事務使用鎖,防止其他使用者修改另外一個還沒有完成的事務中的資料。鎖就是保護指定的資源,不被其他事務操作。

undo是撤消(rollback)。redo是重做。

jobs:定時任務,任務可以是儲存過程,ddbms_job.submit()用法。比如下面的例子:PROCEDURE Submit ( job OUT binary_ineger,
What IN varchar2,
next_date IN date,
interval IN varchar2,
no_parse IN booean:=FALSE)

what 引數是將被執行的pl/sql程式碼塊。next_date引數指何時將執行這個工作。
interval引數何時這個工作將被重執行。
又比如在pl/sql下的job目錄下建立一個job

begin
sys.dbms_job.submit(job=>:job,
what => '儲存過程之間以分號隔離',
next_date => to_date('22-02-2010 11:00:00','dd-mm-yyyy hh24:mi:ss'),
interval => 'trunc(sysdate,'HH') + 1/24');
commit;
end;
/

select decode(nvl(t1,to_date('4000-1-1','yyyy-mm-dd')),to_date('4000-1-1','yyyy-mm-dd')),pkg_f_work_day(t9,t2),pkg_f_work_day(t1,t2))

上面的t1要trunc()掉,否則在decode內,會報錯,應該為number型,卻為date型.

--檢查表空間的SQL指令碼
SELECT tablespace_name, max_m, count_blocks free_blk_cnt, sum_free_m,to_char(100*sum_free_m/sum_m, '99.99') || '%' AS pct_free
FROM ( SELECT tablespace_name,sum(bytes)/1024/1024 AS sum_m FROM dba_data_files GROUP BY tablespace_name),
( SELECT tablespace_name AS fs_ts_name, max(bytes)/1024/1024 AS max_m, count(blocks) AS count_blocks, sum(bytes/1024/1024) AS sum_free_m FROM dba_free_space GROUP BY tablespace_name )
WHERE tablespace_name = fs_ts_name

檢查剩餘表空間
SELECT tablespace_name, sum ( blocks ) as free_blk ,
trunc ( sum ( bytes ) /(1024*1024) ) as free_m,
max ( bytes ) / (1024) as big_chunk_k, count (*) as num_chunks
FROM dba_free_space GROUP BY tablespace_name;

檢查無效的資料庫物件
SELECT owner, object_name, object_type FROM dba_objects
WHERE status=’INVALID’。

檢查不起作用的約束
SELECT owner, constraint_name, table_name,
constraint_type, status
FROM dba_constraints
WHERE status = 'DISABLED’ AND constraint_type = 'P';

所有的索引都要放到索引表空間中。

表空間是邏輯概念,資料檔案是物理概念.每個表空間是由一個多多個資料檔案組成的,資料檔案就是你說的存在硬碟上的東東,表空間的儲存能力由組成表空間的資料檔案大小、數量、可擴充套件性,以及作業系統的限制有關係。只有資料檔案是實實在在的東西,其它的都是邏輯概念,日誌檔案,控制檔案也是物理檔案。看得見的東西都是物理檔案,看不見的都是概念。

oracle BPEL 工作流程建模型,中介軟體+服務,200萬?


rman:備份
有一套命令sql語句。
學習rman:http://www.itpub.net/thread-810100-1-2.html


select add_months(sysdate, 12 * rownum) d from dual connect by rownum < 100 ??????

nomount:裝載


ALTER TABLE 表名 DROP COLUMN 新列名
詳細出處參考:


select * from Planteam t where instr(t.rylb,'"+renyuan+"') >0 ; --顯示rylb這列裡面的內容有renyuan這個值的記錄:函式instr的用法。

select to_char(add_months(to_date('2010-03-09 00:00','yyyy-mm-dd hh24:mi'),1),'yyyy-mm-dd hh24:mi') as nextmonth from dual;--加一個月


select to_char(to_date('2019-10-01' 12:00),'yyyy-mm-dd hh24:mi')+7,'yyyy-mm-dd hh24:mi') as nextweek from dual;


alter table skilldet modify user_team varchar2(50); --修改表欄位長度


-----------------CONNECT BY 用法
SELECT TO_CHAR(TO_DATE('20080401', 'YYYYMMDD') + ROWNUM - 1, 'yyyymmdd') AS "日期"
FROM DUAL
CONNECT BY ROWNUM <= (TO_DATE('20080408', 'YYYYMMDD') -
TO_DATE('20080401', 'YYYYMMDD'));

日期:
20080401
20080402
20080403
20080404
20080405
20080406
20080407
-----------------------------------------------------------------------------------------
一個儲存過程:
declare
n1_01 number;
n1_11 number;
begin
n_01 :=0;
n_11 :=0;

for cur in (select org_no from o_org) loop

select count(*)
into n_01
from a,b
where a.id = b.id
and a.org_no = b.org_no
and a.org_no = cur.org_no
and exists(select 1 from .....)
n11:= n_11 + n_01;

end loop;
dbms_output.put_line('數量,'||n_11);
end;
----------------------------------------------------------------------------------------------------

登陸模式:兩種,不太瞭解。

登陸oracle資料庫的方式
登陸使用者:除sys,system,dbsnmp,sysman使用者外,其他都被鎖定

登入密碼:在資料庫安裝時設定

登陸許可權(身份):sysdba(資料庫管理員DBA),許可權最高

sysoper(資料庫操作員)normal(普通使用者)


一、oracle資料庫自帶的SQL plus

開始——程式——ORACLE10G--APPLICATION DEVELOPMENT——SQL PLUS

二、第三方軟體PL/SQL Developer

開啟PL/SQL Developer軟體

三、以瀏覽器的方式EM(Enterprise Manager)

在oracle資料庫安裝過程中,有資訊提示。

在位址列中輸入:http://本機實體地址:埠號/em(如果oracle資料庫安裝在本機中)

http://安裝資料庫的機器的IP地址:埠號/em(如果oracle資料庫安裝在其他機器上)

以em方式進入時,使用者名稱和許可權有一些限制:

【sys】使用者具有“SYSDBA”或者“SYSOPER”許可權,登陸em也只能用這兩個身份,不能用

normal。sysoper主要用來啟動、關閉資料庫,sysoper 登陸後使用者是 public,sysdba登

陸後是sys

--------------------------------------------------------------------------------------------
select * from v$pq_sysstat;
--------------------------------------------------------
$('.lineSelect').each(function(){
$(this).click(function(){
$('td').removeClass('selected_y');
$(this).parent().children().addClass("select_y");
var pid = $(this).parent().attr("pid");
G_fz_id = pid;
})
})

">

分組型別
---------------------資料遷移
SELECT 'CREATE TABLE'||table_name||
'_test' || 'AS SELECTA * FROM'
|| table_name || 'WHERE 1=2;'
AS "Create Talbe Script"
FORM user_talbe;
-----------------------------------------
SELECT 'DROP TABLE' || object_name ||';'
FROM user_objects
WHERE object_type= 'TABLE'
/
-----------------------------把表匯出到檔案
SELECT
'INSERT INOT de_test VALUES'
('|| d_id' ||,''' ||d_name ||''','''
|| l_id || ''');'
AS "Insert Statements Script"
FROM de
/
---------------------------------------
/********************************
中文名:建立工單的編號.
作者:
時間:
修改記錄:
說明:
***************************************/

create or replace package body pkg_seq_m is


function f_cr_defid return varchar2 is
v_r varchar2(16);
begin
select 'CR'||to_char(sysdate,'yyyymmdd') || lpad(seg_bh.nextval,4,'0') into v_r from dual;
return v_r;
end;

end pkg_seq_m;
-----------------------------------------------------------
create or replace package pkg_seq_m is
function f_cr_defid return varchar2
end pkg_seq_m;


1 中小型資料庫:100G以下資料庫,或200以下併發使用者。
2 大型 : 1T以下資料量,或1000以下併發使用者。

3 海量 : 1T以上資料量,或1000以上併發使用者。

--------------------------------------------
oracle document library.
-------------------------------------------------------------
Automatic Shared Memory Management simplifies the configuration of the SGA and is the recommended memory configuration. To use Automatic Shared Memory Management, set the SGA_TARGET initialization parameter to a nonzero value and set the STATISTICS_LEVEL initialization parameter to TYPICAL or ALL。

概念資料模型(CDM)
資訊系統的概念設計工具,即實體-聯絡圖(E-R圖),CDM就是以其自身方式來描述E-R圖。此時不考慮物理實現的細節,只表示資料庫的整體邏輯結構,獨立於任何軟體和資料儲存結構。

物理資料模型(PDM)
PDM考慮了資料庫的物理實現,包括軟體和資料儲存結構。
PDM的物件:表(Table)、表中的列(Table column)、主碼和外碼(Primary & Foreign key)、參照(Reference)、索引(Index)、檢視(View)等。


---------------------------------------5月11日
If a commonly executed query needs to access a small percentage of data in the table, then it can be executed more efficiently by using an index. By creating such an index,

file I/O (V$FILESTAT

system statistics (V$SYSSTAT),

SQL statistics (V$SQLAREA, V$SQL or V$SQLSTATS, V$SQLTEXT, V$SQL_PLAN, and V$SQL_PLAN_STATISTICS).

使用索引時,unique的比non-unique的快。

Optimizer plan for the SQL statement (either from EXPLAIN PLAN, V$SQL_PLAN, or the TKPROF output)

--為什麼要看執行計劃:
It is important to generate and review execution plans for all of the key SQL statements in your application. Doing so lets you compare the optimizer execution plans of a SQL statement when the statement performed well to the plan when that the statement is not performing well. Having the comparison, along with information such as changes in data volumes, can assist in identifying the cause of performance degradation.


--全表掃描對於查詢某個小表的大部分記錄的效率比用索引掃描效率好。

--A full table scan does not mean inefficiency. It might be more efficient to perform a full table scan on a small table, or to perform a full table scan to leverage a better join method (for example, hash_join) for the number of rows returned.

--什麼時候用in,什麼時候用exists.??
In certain circumstances, it is better to use IN rather than EXISTS. In general, if the selective predicate is in the subquery, then use IN. If the selective predicate is in the parent query, then use EXISTS.


用in代替exists例子:
SELECT
e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE EXISTS (SELECT 1 FROM orders o /* Note 1 */
WHERE e.employee_id = o.sales_rep_id /* Note 2 */
AND o.customer_id = 144); /* Note 3 */
employee有全掃描。

SELECT e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE e.employee_id(是unique index) IN (SELECT o.sales_rep_id /* Note 4 */
FROM orders o
WHERE o.customer_id = 144); /* Note 3 */

用exists代替in:
SELECT /* IN example */
e.employee_id, e.first_name, e.last_name, e.department_id, e.salary
FROM employees e
WHERE e.department_id = 80 /* Note 5 */
AND e.job_id = 'SA_REP' /* Note 6 */
AND e.employee_id IN (SELECT o.sales_rep_id FROM orders o); /* Note 4 */

orders 有全掃描。

SELECT /* EXISTS example */
e.employee_id, e.first_name, e.last_name, e.salary
FROM employees e
WHERE e.department_id = 80 /* Note 5 */
AND e.job_id = 'SA_REP' /* Note

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24214296/viewspace-1035094/,如需轉載,請註明出處,否則將追究法律責任。

相關文章