日常技术积累

提个问题:局部索引和全局索引区别这类问题有什么区别?全局分区索引,全局非分区索引,本地分区索引,本地非分区索引...

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 新列名
详细出处参考:http://www.itqun.net/content-detail/103147.html


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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/24214296/viewspace-1035094/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值