------------------------2013-5-4------------------------
create user "tempuser2" profile "DEFAULT"
identified by "tempuser2" default tablespace "USERS"
account unlock;
--profile "DEFAULT" 是區(qū)分大小寫的。
? default tablespace "USERS" 是區(qū)分大小寫的。
?
create user "TEMPUSER" profile "DEFAULT"
identified by "TEMPUSER" default tablespace "USERS"
account unlock;?
--全部大寫,否則創(chuàng)建的用戶名是:"tempuser2" !!!
?
grant create any table to "tempuser2" with admin option;
grant "CONNECT" to "tempuser2" with admin option;??????????? "CONNECT"大寫
grant create any table to "TEMPUSER" with admin option;
grant "CONNECT" to "TEMPUSER" with admin option;?
?
begin
dbms_resource_manager_privs.grant_switch_consumer_group(
? grantee_name =>'TEMPUSER',
? consumer_group =>'DEFAULT_CONSUMER_GROUP',
? grant_option=>true
);
end;
begin
dbms_resource_manager.set_initial_consumer_group(
? user=>'TEMPUSER',
? consumer_group=>'DEFAULT_CONSUMER_GROUP'
);
end;
alter user "TEMPUSER" account lock
alter user "TEMPUSER" identified by "TEMP"
drop user tempuser cascade;
CREATE ROLE "TEMPROLE"?
??? IDENTIFIED BY "temprole"
--角色--
GRANT "CONNECT" TO "TEMPROLE" WITH ADMIN OPTION;
GRANT "DBA" TO "TEMPROLE" WITH ADMIN OPTION;
--系統(tǒng)權(quán)限--
GRANT ALTER ANY
??? INDEX TO "TEMPROLE" WITH ADMIN OPTION
GRANT SELECT ANY TABLE TO "TEMPROLE" WITH ADMIN OPTION
--grant--
BEGIN
?dbms_resource_manager_privs.revoke_switch_consumer_group(
??revokee_name => 'TEMPROLE',
??consumer_group => 'DEFAULT_CONSUMER_GROUP'
?);
END;
------------------------2013-5-5------------------------
##角色##
create role "TEMPROLE2" identified by "TEMPROLE2";
grant alter any index to "TEMPROLE2" with admin option;
grant select any table to "TEMPROLE2" with admin option;
grant "CONNECT" to "TEMPROLE2" with admin option;
grant "DBA" to "TEMPROLE2" with admin option;
begin
dbms_resource_manager_privs.grant_switch_consumer_group(
? grantee_name => 'TEMPROLE2',
? consumer_group => 'DEFAULT_CONSUMER_GROUP',
? grant_option => false
);
end;
alter role "TEMPROLE2" identified externally;
revoke "DBA" from "TEMPROLE2";????????????????? #revoke關(guān)鍵字#
drop role TEMPROLE2;
##profile概要文件##
CREATE PROFILE "TEMPPROFILE"
??? LIMIT CPU_PER_SESSION 1000 CPU_PER_CALL 1000 CONNECT_TIME 30
??? IDLE_TIME DEFAULT SESSIONS_PER_USER 10
??? LOGICAL_READS_PER_SESSION 1000 LOGICAL_READS_PER_CALL 1000
??? PRIVATE_SGA 16K COMPOSITE_LIMIT 10000000
??? FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 5
??? PASSWORD_GRACE_TIME 60 PASSWORD_LIFE_TIME 30
??? PASSWORD_REUSE_MAX UNLIMITED PASSWORD_REUSE_TIME 30
??? PASSWORD_VERIFY_FUNCTION DEFAULT
為用戶分配概要文件
alter user tempuser profile tempprofile;
概要文件的刪除
drop profile tempprofile;
##表空間##
CREATE TABLESPACE "TEMPTABLESPACE"
??? LOGGING
??? DATAFILE 'D:\ORACLE\ORADATA\ORA1128\TEMPTABLESPACE.ora' SIZE
??? 5M EXTENT MANAGEMENT LOCAL
創(chuàng)建表空間的語法是:
create tablespace tablespacename
datafile 'filename' [size integer [K|M]]
[autoextend [off|on]];
##數(shù)據(jù)文件##
ALTER TABLESPACE "CWMLITE"
??? ADD
??? DATAFILE 'D:\ORACLE\ORADATA\ORA1128\TEMPDATAFILE.ora'? SIZE?
??? 5M AUTOEXTEND
??? ON NEXT? 100K MAXSIZE UNLIMITED
##回退段##
回退段是一種特殊類型的數(shù)據(jù)段,記錄著數(shù)據(jù)庫被某個(gè)事務(wù)操作后的資料的原值,因此回退段里的資料可以用來對(duì)數(shù)據(jù)庫進(jìn)行恢復(fù)。
CREATE ROLLBACK SEGMENT "TEMPROLLBACKSEGMENT"
??? TABLESPACE "TEMPTABLESPACE"
??? STORAGE ( INITIAL 10K NEXT 10K)
ALTER ROLLBACK SEGMENT "TEMPROLLBACKSEGMENT" ONLINE
D:\oracle\admin\ora1128\pfile\init.ora
###########################################
# 系統(tǒng)管理的撤銷和回退段
###########################################
undo_management=AUTO?? -->manual
undo_retention=10800
undo_tablespace=UNDOTBS
報(bào)錯(cuò):ORA-30019:自動(dòng)撤消模式中的回退段操作非法。
##重做日志組##
ALTER DATABASE
??? ADD LOGFILE GROUP 4 ('D:\ORACLE\ORADATA\ORA1128\log4.ora')
??? SIZE 1024K
SQL
數(shù)據(jù)查詢語言DQL: 查詢數(shù)據(jù)
數(shù)據(jù)定義語言DDL: 建立,刪除和修改數(shù)據(jù)對(duì)象,create? alter? drop? truncate
數(shù)據(jù)操縱語言DML: 完成數(shù)據(jù)操縱的命令,包括查詢。 insert? select? delete? update
數(shù)據(jù)控制語言DCL: 控制對(duì)數(shù)據(jù)庫的訪問,服務(wù)器的關(guān)閉,啟動(dòng)等。grant? revoke
事務(wù)處理語言TCL? commit? savepoint? rollback
select * from emp;
select * from dept;
desc dept? 查看表結(jié)構(gòu)。
select empno,ename,job from scott.emp;
select distinct job from scott.emp;??? <===> select all job from scott.emp;
select empno,ename,job from scott.emp where job='MANAGER';
select empno,ename,sal from scott.emp where sal <=2500;
不等于運(yùn)算符
select empno,ename,job from scott.emp where job ^= 'MANAGER';
select empno,ename,job from scott.emp where job != 'MANAGER';
select empno,ename,job from scott.emp where job <> 'MANAGER';
in(列表以逗號(hào)隔開)
not in(列表以逗號(hào)隔開)
between and 介于之間
字符型字段也可以比較大小
select empno,ename,job from scott.emp where job > 'MANAGER';
select empno,ename,job from scott.emp where job not in ('MANAGER','CLERK');
select empno,ename,job from scott.emp where job between 'CLERK' and 'MANAGER'
like模式匹配
select empno,ename,job from scott.emp where job like 'M%'
select empno,ename,job from scott.emp where job like 'M__'?? x
select empno,ename,job from scott.emp where job like 'M______'? 代表M開頭的長(zhǎng)度為7的字符串,并且區(qū)分大小寫。
is null是否為空
select empno,ename,job from scott.emp where job is null
以上為單條件查詢,以下為組合條件的查詢。
select empno,ename,job from scott.emp where job > 'CLERK' and sal <= 2000
not job='CLERK' 等價(jià)于 job<>'CLERK'
排序
select empno,ename,job,sal from scott.emp where job <= 'CLERK' order by job asc,sal desc
???? EMPNO ENAME????? JOB????????????? SAL
---------- ---------- --------- ----------
????? 7788 SCOTT????? ANALYST???????? 3000
????? 7902 FORD?????? ANALYST???????? 3000
????? 7934 MILLER???? CLERK?????????? 1300
????? 7876 ADAMS????? CLERK?????????? 1100
????? 7900 JAMES????? CLERK??????????? 950
????? 7369 SMITH????? CLERK??????????? 800
分組查詢
select empno,ename,job,sal from scott.emp group by job,empno,ename,sal having? sal <= 2000
select job,sum(sal) from scott.emp group by job,sal having sal < 2000;
select job,sum(sal) as sal2 from scott.emp group by job having sal > 5000
?????????????????????????????????????????????????????????????? *
ERROR 位于第 1 行:
ORA-00979: 不是 GROUP BY 表達(dá)式
應(yīng)該寫成分組函數(shù)的方式。
select job,sum(sal) from scott.emp group by job;? 按job分組,分組統(tǒng)計(jì)sal求和。
select job,sum(sal) as sal2 from scott.emp group by job having sum(sal) > 5000; 在以上條件基礎(chǔ)上篩選總和大于5000的記錄。
對(duì)空表記錄的查詢,同樣適合于oracle。
select count(*) from newlifeyhj.t;?? 為0
select sum(A) from newlifeyhj.t;???? 為空
順序求子句的值:
1.where子句,建立候選行。
2.group by子句中指定的組。
3.having子句進(jìn)一步約束不滿足having子句中分組標(biāo)準(zhǔn)結(jié)果分組。
avg 平均值
count 計(jì)數(shù)
max 最大值
min 最小值
stddev 標(biāo)準(zhǔn)差
sum 合計(jì)
variance 方差
所有的oracle忽略空值。
min和max用于任何數(shù)據(jù)類型,avg,sum,variance,stddev函數(shù)只能被用于數(shù)字。
NVL函數(shù)強(qiáng)制組函數(shù)包含空值。
分組數(shù)據(jù):? GROUP BY 子句語法
可以使用GROUP BY 子句將表中的數(shù)據(jù)分成若干組
在SELECT 列表中所有未包含在組函數(shù)中的列都應(yīng)該包含在 GROUP BY 子句中。
SQL> select employee_id,avg(salary) from employees group by employee_id;
包含在 GROUP BY 子句中的列不必包含在SELECT 列表中
所用包含于SELECT 列表中,而未包含于組函數(shù)中的列都必須包含于 GROUP BY 子句中,
否則會(huì)報(bào)錯(cuò):第 1 行出現(xiàn)錯(cuò)誤:? ORA-00979: 不是 GROUP BY 表達(dá)式 注意:
不能在 WHERE 子句中使用組函數(shù)(注意)。
可以在 HAVING 子句中使用組函數(shù)。
過濾分組:
使用 HAVING 過濾分組:
1.行已經(jīng)被分組。
2.使用了組函數(shù)。
3.滿足HAVING 子句中條件的分組將被顯示
select department_id,max(salary) from employees group by department_id having max(salary)>2000
##帶where條件##
--查詢?nèi)康膕al條件 8行
select job,sal as sal2 from scott.emp where sal <= 2000;
--查詢滿足job,sal記錄分組,7行, SALESMAN 1250 兩條重復(fù)的記錄。
select job,sal as sal2 from scott.emp where sal <= 2000 group by job,sal;
--查詢滿足job,sal記錄分組,7行, sum(SALESMAN 1250) 兩條重復(fù)的記錄。 ==>求和,SALESMAN 2500
select job,sum(sal) as sal2 from scott.emp where sal <= 2000 group by job,sal;
--注釋,根據(jù)單一job分組求和sal
select job,sum(sal) as sal2 from scott.emp where sal <= 2000 group by job;
字段運(yùn)算查詢+ - * /
select empno,ename,sal,mgr,sal+mgr,sal+100 from scott.emp;
select empno 編號(hào),ename 姓名,job 工作,sal 薪水,mgr,sal+mgr,sal+100 from scott.emp;
##多表查詢##
#無條件多表查詢#
select emp.empno,emp.ename,emp.deptno from scott.emp;? 14行
select dept.dname,dept.loc from scott.dept;??????????? 5行
select emp.empno,emp.ename,emp.deptno,dept.dname,dept.loc from scott.emp,scott.dept;? 14*5=70行
無條件多表查詢是將各表的記錄以"笛卡爾"積的方式組合起來。
#等值多表查詢#
select emp.empno,emp.ename,emp.deptno,dept.deptno,dept.dname,dept.loc from scott.emp,scott.dept
where scott.emp.deptno=scott.dept.deptno
#非等值多表查詢#
select emp.empno,emp.ename,emp.deptno,dept.deptno,dept.dname,dept.loc from scott.emp,scott.dept
where scott.emp.deptno!=scott.dept.deptno and scott.emp.deptno=10
##SQL嵌套查詢##
內(nèi)嵌的select語句稱為子查詢,子查詢形成的結(jié)果又成為父查詢的條件。
select sal from scott.emp where ename='WARD';? ==> sal=1250
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal >= (select sal from scott.emp where ename='WARD')
#關(guān)鍵字in not in#
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal in (select sal from scott.emp where ename='WARD')
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal not in (select sal from scott.emp where ename='WARD')
select sal from scott.emp where job = 'MANAGER';
#any關(guān)鍵字# 等價(jià)于where sal > 2975 or sal > 2850 or sal > 2450
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > any(select sal from scott.emp where job = 'MANAGER')
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > 2975
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > 2850
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > 2450
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > 2975 or sal > 2850 or sal > 2450
#some關(guān)鍵字# 等價(jià)于where sal = 2975 or sal = 2850 or sal = 2450
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal = some(select sal from scott.emp where job = 'MANAGER');
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal = 2975 or sal = 2850 or sal = 2450;
#all關(guān)鍵字#
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > all(select sal from scott.emp where job = 'MANAGER');
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal > 2975 and sal > 2850 and sal > 2450;
#exists關(guān)鍵字#
select emp.empno,emp.ename,emp.job,emp.sal from scott.emp,scott.dept
where exists
(select * from scott.emp where scott.emp.deptno = scott.dept.deptno);
#union關(guān)鍵字#并操作
select deptno from scott.emp
union
select deptno from scott.dept;
#intersect關(guān)鍵字#交操作
select deptno from scott.emp
intersect
select deptno from scott.dept;
#minus關(guān)鍵字#差操作,屬于集合A且不屬于集合B的元素總合就是差集。
select deptno from scott.emp
minus
select deptno from scott.dept;
要求屬性具有相同的定義,包括類型和取值范圍。
##SQL函數(shù)查詢##
#ceil函數(shù)#取大于等于數(shù)值n的最小整數(shù)
select mgr,mgr/100,ceil(mgr/100) from scott.emp;
#floor函數(shù)#取小于等于數(shù)值n的最大整數(shù)
select mgr,mgr/100,floor(mgr/100) from scott.emp;
#mod函數(shù)# mod(m,n), 取m整除n后的余數(shù)。
select mgr,mod(mgr,1000),mod(mgr,100),mod(mgr,10) from scott.emp;
==>p21
------------------------2013-5-6------------------------
#power函數(shù)#[數(shù)]冪,power(m,n),取m的n次方。
select mgr,power(mgr,2),power(mgr,3) from scott.emp;
#round函數(shù)# round(m,n),四舍五入,保留n位。
select mgr,round(mgr/100,2),round(mgr/1000,2) from scott.emp;
#sign函數(shù)# sign(n),n>0,取1; n=0,取0; n<0,取-1
select mgr,mgr-7800,sign(mgr-7800) from scott.emp;
#avg函數(shù)# 求平均值,要求字段為數(shù)值型。
select avg(mgr) 平均薪水 from scott.emp;
#count函數(shù)# count(字段名)或count(*),統(tǒng)計(jì)總數(shù)。
select count(*) 記錄總數(shù) from scott.emp;
select job,count(distinct job) 工作類別總數(shù) from scott.emp group by job;
select count(distinct job) 工作類別總數(shù) from scott.emp;
#min函數(shù)# min(字段名),計(jì)算數(shù)值型字段最小值。
select min(sal) 最少薪水 from scott.emp;
#max函數(shù)# max(字段名),計(jì)算數(shù)值型字段最大值。
select max(sal) 最高薪水 from scott.emp;
#sum函數(shù)# 計(jì)算數(shù)值型字段總和。
select sum(sal) 薪水求和 from scott.emp;
##SQL錄入數(shù)據(jù)##
#單行記錄錄入#
7900 JAMES????? 03-12月-81
insert into scott.emp(empno,ename,hiredate)values(7999,'JONE','25-11月-2002');
select empno,ename,hiredate from scott.emp;
#多行記錄的錄入#
select empno+100,ename,hiredate from scott.emp where empno >= 6999
insert into scott.emp(empno,ename,hiredate)
(select empno+100,ename,hiredate from scott.emp where empno >= 6999)
#表間數(shù)據(jù)復(fù)制#
select distinct empno,ename,hiredate
? from scott.emp
? where empno >= 7000
?
create table scott.test? --利用現(xiàn)有的表創(chuàng)建表。
as(
? select distinct empno,ename,hiredate
? from scott.emp
? where empno >= 7000
);? //分三步執(zhí)行的,首先查詢符合要求的數(shù)據(jù),其次是建立3個(gè)字段的名為test數(shù)據(jù)庫空表,最后將查詢的數(shù)據(jù)插入到test數(shù)據(jù)表中。
select * from scott.test;
desc scott.test;
create table test2
as
select * from scott.test where 1 <> 2;?? --條件不成立,僅僅復(fù)制的是表結(jié)構(gòu),而不是表數(shù)據(jù)。
create table scott.test2?? --注意表名前面的前綴。
as
select * from scott.test where 1 <> 2;
日期數(shù)據(jù)類型默認(rèn)格式為 DD-MON-RR
使用日期的默認(rèn)格式
使用TO_DATE函數(shù)轉(zhuǎn)換? TO_DATE('2005-10-18','YYYY-MM-DD')
select * from scott.test;
##SQL刪除數(shù)據(jù)##
delete from scott.test where empno >= 7500 and empno <= 8000;
delete from scott.test
truncate table scott.test;?? --表已截掉。
truncate table命令將快速刪除數(shù)據(jù)表中的所有記錄,但保留數(shù)據(jù)表結(jié)構(gòu)。這種快速刪除與delete from數(shù)據(jù)表的刪除全部數(shù)據(jù)表記錄不一樣,
delete命令刪除的數(shù)據(jù)將存儲(chǔ)在系統(tǒng)回滾段中,需要的時(shí)候,數(shù)據(jù)可以回滾恢復(fù)。
而truncate命令刪除的數(shù)據(jù)是不可以恢復(fù)的。
--insert into scott.test(empno,ename,hiredate)values(7999,'JONE','25-11月-2002');
--delete from scott.test;
--rollback;
select * from scott.test;
事務(wù)例子sql
select * from scott.test2 where 1 = 1;
--insert into scott.test2(empno,ename,hiredate)values(8881,'STEVE',TO_DATE('2013-5-6','YYYY-MM-DD'));
update scott.test2 set ename='STEVE2' where empno = 8881;
savepoint mark1;
delete from scott.test2 where empno = 8881;
?--delete from scott.test2 where empno = 8881;
?--truncate table scott.test2;??? --測(cè)試truncate是否支持回滾。
savepoint mark2;
rollback to savepoint mark1;
commit;
select * from scott.test2 where 1 = 1;
?
##SQL更新數(shù)據(jù)##
#直接賦值更新#
select empno,ename,hiredate from scott.emp where empno=7999;
update scott.emp set empno=8888,ename='TOM',hiredate='03-9月-2002' where empno=7999;
select empno,ename,hiredate from scott.emp where empno=8888;
#嵌套更新#
update scott.emp set sal = 600 where empno=8888;
select empno,sal from scott.emp where empno=8888;
select sal+300 from scott.emp where empno=8888;
update scott.emp
set sal = (select sal+300 from scott.emp where empno=8888)
where empno = 8888;
安裝9i
ping 10.0.6.57 -t? 網(wǎng)絡(luò)
數(shù)據(jù)庫服務(wù)器的體系結(jié)構(gòu)
進(jìn)程結(jié)構(gòu)
1.用戶進(jìn)程,客戶機(jī)內(nèi)存上運(yùn)行的程序,如SQL Plus,企業(yè)管理器。
2.服務(wù)器進(jìn)程,Oracle 9i的主要后臺(tái)支持進(jìn)程。
?系統(tǒng)監(jiān)控進(jìn)程(smon)?? x
?進(jìn)程監(jiān)控進(jìn)程(pmon)?? x
?數(shù)據(jù)庫寫入進(jìn)程(dbwr) x
?日志寫入進(jìn)程(lgwr)?? x
?歸檔進(jìn)程(arch)?????? x
?檢查點(diǎn)進(jìn)程(ckpt)???? x
?恢復(fù)進(jìn)程(reco)
?鎖進(jìn)程(LCKn)
?快照進(jìn)程(SNPn)
?調(diào)度進(jìn)程(Dnnn)??? --服務(wù)進(jìn)程和用戶進(jìn)程--
內(nèi)存結(jié)構(gòu)
1.系統(tǒng)全局區(qū)SGA
2.程序全局區(qū)PGA
PGA是數(shù)據(jù)庫服務(wù)器內(nèi)存中為單個(gè)用戶進(jìn)程分配的專用的內(nèi)存區(qū)域,是用戶進(jìn)程私有的,不能共享。
數(shù)據(jù)庫的邏輯結(jié)構(gòu)
1.數(shù)據(jù)塊 Data Block
2.數(shù)據(jù)區(qū)間 Data Extent
3.數(shù)據(jù)段 Data Segment?? 數(shù)據(jù)段 索引段 臨時(shí)段 回滾段
4.邏輯對(duì)象 Logic Object 表 索引 視圖
5.表空間 Tablespace????
6.數(shù)據(jù)庫 Database
模式
模式是對(duì)用戶所創(chuàng)建的數(shù)據(jù)庫對(duì)象的總稱。
模式對(duì)象包括表、視圖、索引、同義詞、序列、過程和程序包等。
oracle 9i安裝完畢后自動(dòng)建立9個(gè)默認(rèn)的表空間。
cwmlite?? 用于聯(lián)機(jī)分析處理olap
drsys???? 用于存放與工作空間設(shè)置有關(guān)的信息
example?? 實(shí)例表空間,存放實(shí)例信息。
index???? 索引表空間,存放數(shù)據(jù)庫索引信息。
system??? 系統(tǒng)表空間,存放表空間名稱、所含數(shù)據(jù)文件等管理信息。
temp????? 臨時(shí)表空間,存儲(chǔ)臨時(shí)表。
tools???? 工具表空間,存放數(shù)據(jù)庫工具軟件所需的數(shù)據(jù)庫對(duì)象。
undotbs?? 回滾表空間,存放數(shù)據(jù)庫恢復(fù)信息。
users???? 用戶表空間,存放用戶私有信息。
1.物理塊
2.物理文件
?數(shù)據(jù)文件:用于存放所有的數(shù)據(jù),以DBF為擴(kuò)展名。???? 存儲(chǔ)數(shù)據(jù)庫數(shù)據(jù),如表,索引數(shù)據(jù)等。? (數(shù)據(jù)庫文件或數(shù)據(jù)文件)
?日志文件:記錄了對(duì)數(shù)據(jù)庫進(jìn)行的所有操作,以LOG為擴(kuò)展名。?? 對(duì)數(shù)據(jù)庫所有修改信息,用于故障恢復(fù)。(恢復(fù)日志文件)
?控制文件:記錄了數(shù)據(jù)庫所有文件的控制信息,以CTL為擴(kuò)展名。 記錄數(shù)據(jù)庫物理結(jié)構(gòu)的二進(jìn)制文件。??? (控制文件)
D:\oracle\oradata\ora1128
數(shù)據(jù)庫以下面兩種模式運(yùn)行
NOARCHIVELOG MODE
ARCHIVELOG MODE?
to_date('17-12-1980','dd-mm-yyyy')
show sga;
show parameter sga;
show parameter db;
show parameter pga;
show parameter log_buffer;
select * from v$bgprocess where paddr <> '00';
select * from v$controlfile;
select * from v$datafile;
select * from v$logfile;
interval函數(shù)用法:
--日期加上1天
select trunc(sysdate) + interval '1' day from dual;
--月份加上1月
select trunc(sysdate) + interval '1' month from dual;
--年份加上1年
select trunc(sysdate) + interval '1' year from dual;
--查詢系統(tǒng)時(shí)間
select sysdate from dual;
--trunc函數(shù)
select trunc(sysdate) from dual;
select trunc(sysdate) + interval '99' day from dual;
select trunc(sysdate) + interval '101' day from dual;
--ERROR 位于第 1 行:
ORA-01873: 間隔的前導(dǎo)精度太小
select TO_CHAR(SYSDATE + INTERVAL '100' DAY(3), 'YYYYMMDD') from dual;
select
TO_CHAR(SYSDATE - INTERVAL '3' YEAR, 'YYYYMMDDHH24') ToYEAR,
--=>從系統(tǒng)日期算起往前 3 年
TO_CHAR(SYSDATE - INTERVAL '3' month, 'YYYYMMDDHH24') ToMONTH,
--=>從系統(tǒng)日期算起往前 3 個(gè)月
TO_CHAR(SYSDATE - INTERVAL '30' DAY, 'YYYYMMDDHH24') ToDay,
--=>從系統(tǒng)日期算起往前 30 天
TO_CHAR(SYSDATE - INTERVAL '30' HOUR, 'YYYYMMDDHH24') ToHOUR,
--=>從系統(tǒng)日期算起往前 30 小時(shí)
TO_CHAR(SYSDATE - INTERVAL '30' minute, 'YYYYMMDD HH24:MI:SS') ToMinute,
--=>從系統(tǒng)日期算起往前 30 分鍾
TO_CHAR(SYSDATE - INTERVAL '50' second,'YYYYMMDD HH24:MI:SS') ToSecond,
--=>從系統(tǒng)日期算起往前 50 秒
SYSDATE
--系統(tǒng)日期
from dual;
--http://pramaire.pixnet.net/blog/post/7619355-oracle-%E6%97%A5%E6%9C%9F%E9%81%8B%E7%AE%97-%5B%2B--interval%5D
Oracle數(shù)據(jù)庫的主要特點(diǎn):
1. 支持多用戶,大事務(wù)量的事務(wù)處理.
2. 數(shù)據(jù)安全性和完整性控制.
3. 支持分布式數(shù)據(jù)處理.
4. 可移植性.
授予用戶MARTIN操作TEST表對(duì)象的權(quán)限
grant select on test to martin; --允許用戶查詢test表的記錄
grant update on test to martin; --允許用戶更新test表的記錄
grant all on test to martin; --允許用戶插入,刪除,更新和查詢test表中的記錄
grant select,update on test to martin with grant option;? --表的多個(gè)權(quán)限的賦予,管理權(quán)限。
grant update(qty_hand,re_level) on test to martin;? --控制力度在修改表中的字段。
revoke select,update on test from martin;? --移除權(quán)限。
RAW
(raw image format)原始圖象數(shù)據(jù)存儲(chǔ)格式。
##Oracle數(shù)據(jù)類型##
字符數(shù)據(jù)類型,char(1-2000)? varchar2(1-4000)? long(可變長(zhǎng)度字符數(shù)據(jù),最多能存儲(chǔ)2GB)
數(shù)值數(shù)據(jù)類型的聲明語法:可以存儲(chǔ)整數(shù),浮點(diǎn)數(shù)和實(shí)數(shù)。最高精度為38位。
number(p[,s]),p表示精度,s表示小數(shù)點(diǎn)的位數(shù)。
日期類型:date,timestamp
raw: 存儲(chǔ)二進(jìn)制數(shù)據(jù),最多能存儲(chǔ)2000字節(jié),
long raw: 存儲(chǔ)可變長(zhǎng)度的二進(jìn)制數(shù)據(jù),最多能存儲(chǔ)2GB
lob:大對(duì)象數(shù)據(jù)類型,存儲(chǔ)達(dá)4GB的非結(jié)構(gòu)化信息,如聲音剪輯和視頻文件。允許高效,隨機(jī),分段的訪問。
clob: character lob 字符lob 能夠存儲(chǔ)大量字符數(shù)據(jù)。
blob: binary lob 二進(jìn)制lob,可以存儲(chǔ)較大的二進(jìn)制對(duì)象,如圖形,視頻剪輯和聲音文件。
bfile: binary file 二進(jìn)制文件,用于將二進(jìn)制數(shù)據(jù)存儲(chǔ)在數(shù)據(jù)庫外部的操作系統(tǒng)文件中。
oracle偽列:rowid(表中行的存儲(chǔ)地址),rownum(查詢返回的結(jié)果集中行的序號(hào),可以用它來限制查詢返回的行數(shù)。)
Oracle服務(wù)器由Oracle數(shù)據(jù)庫(邏輯單元)和Oracle實(shí)例(管理數(shù)據(jù)庫的后臺(tái)進(jìn)程和內(nèi)存結(jié)構(gòu))組成。
SGA內(nèi)存結(jié)構(gòu)(共享池,數(shù)據(jù)緩沖區(qū),日志緩沖區(qū))
使用表空間:為什么使用?
在大型商場(chǎng)中收款機(jī)眾多,同時(shí)訪問進(jìn)程很多,經(jīng)常達(dá)到50-100個(gè)進(jìn)程同時(shí)訪問,這樣,通過建立多個(gè)用戶表空間、索引表空間,把各個(gè)用戶分別建在不同的表空間里。
(多個(gè)用戶表空間放在不同的物理磁盤上),減少了用戶之間的I/O競(jìng)爭(zhēng)、讀寫數(shù)據(jù)與寫讀索引的競(jìng)爭(zhēng)(用戶表空間、索引表空間也分別放在不同的物理磁盤上)
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
