日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【自学oracle】韩顺平oracle视频教程学习笔记

發(fā)布時(shí)間:2023/12/9 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【自学oracle】韩顺平oracle视频教程学习笔记 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
第一講
oracle的數(shù)據(jù)對(duì)象(表,視圖,序列,函數(shù),包,過程,觸發(fā)器)
不同的數(shù)據(jù)庫(kù) 數(shù)據(jù)對(duì)象未必是完全相同的
例如sqlserver2000里面就沒有包
多少人用(并發(fā)問題)


第二講
1.9i只有一個(gè)安裝文件
2.把這個(gè)10201_database_win32.zip文件拷貝到?jīng)]有中文的路徑下
3.到電腦的服務(wù)選項(xiàng)去確定本機(jī)沒有安裝oracle數(shù)據(jù)庫(kù),如果有,則卸載
orclxuzhu 命令
4.解鎖步驟
? 先使用system登錄
? 然后輸入alter user scott account unlock
?5 system用戶名 orclxuzhu密碼


第三講
1.show user 當(dāng)前用戶名是什么
2.請(qǐng)使用scott用戶登錄oracle數(shù)據(jù)庫(kù)實(shí)例,然后,切換身份為system用戶登錄后,使用conn[ect] 用戶名/密碼@網(wǎng)絡(luò)[as sysdba/as sysoper]
? ?
3.簡(jiǎn)單使用:conn[ect] 用戶名/密碼?
? ?該命令經(jīng)常用于切換當(dāng)前用戶,因此我們建議大家在登錄的時(shí)候使用普通用戶,scott,如果確實(shí)需要system用戶,則可以使用該命令切換為高級(jí)用戶
4.disc[onnect] 該命令用戶斷開和oracle連接,但是不退出sqlplus窗口
5.exit命令 該命令用戶斷開和oracle連接,同時(shí)退出sqlplus窗口
6.passw[ord] 該命令用于修改用戶的密碼
? 基本用法
? 如果給自己修改密碼,則可以不帶用戶名,如果給別人修改密碼(前提是system或者sys用戶來修改),則需要帶用戶名
7.& 交互命令
? select * from emp where job='&job';
? 輸入job的值:CLERK
8.edit命令
? 用于編輯腳本
? edit d:/aa.sql
9.spool命令 該命令把屏幕上顯示的記錄,保存到文件中,以后分析
? spool d:/bak.sql
? select * from emp
? spool off
?
第四講
1.linesize 用戶控制每行顯示多少個(gè)字符,默認(rèn)80字符 set linesize 120;
2.pagesize 用于每頁顯示多少行 set pagesize 100;
3.創(chuàng)建用戶(具有dba權(quán)限的用戶才能操作,system,sys)
? create user 用戶名 identified by 密碼
? create user xiaoming identified by m123 [oracle要求用戶密碼不能用數(shù)字開始]
??
? 這里剛剛創(chuàng)建的用戶是沒有任何權(quán)限的,甚至連登陸都不行
? 需要管理員給用戶分配相應(yīng)的權(quán)限才能登陸,給一個(gè)用戶賦權(quán)限使用命令grant,回收權(quán)限使用命令revoke
??
? 如何給用戶分配具體的權(quán)限
? grant create session to xiaoming?
? 執(zhí)行成功就可以登陸了
??
4.如果給別人修改密碼則需要具有dba的權(quán)限,或是擁有alter user的系統(tǒng)權(quán)限,也可以使用password用戶名
? alter user 用戶名 identified by 新密碼
??
第五講
1.預(yù)定義角色把常用的權(quán)限集中起來,形成角色dba connect resource


2.使用system創(chuàng)建xiaohong
create user xiaohong identified by m123


3.給小紅分配兩個(gè)常用角色
grant connect to xiaohong
grant resource to xiaohong?


4.讓xiaohong登錄
connect xiaohong/m123


5.小紅修改密碼 如果不加上名字表示對(duì)當(dāng)前用戶
password xiaohong
舊口令:
新口令:


6.斷開連接
disconnect


7.創(chuàng)建一張表
create table users(id number);


8.插入數(shù)據(jù)
insert into users values(1);


9.查詢數(shù)據(jù)
select * from users;


10.使用system登錄,然后回收角色
revoke connect from xiaohong
revoke resource from xiaohong


11.刪除用戶
drop user 用戶[cascade]
drop user xiaohong cascade;
當(dāng)我們刪除一個(gè)用戶的時(shí)候,如果這個(gè)用戶自己已經(jīng)創(chuàng)建過數(shù)據(jù)對(duì)象,那么我們?cè)趧h除用戶的時(shí)候,需要加選項(xiàng)cascade,表示把這個(gè)用戶刪除同時(shí),把該用戶創(chuàng)建的數(shù)據(jù)對(duì)象一并刪除


12.顯示當(dāng)前連接用戶
show user?


13.oracle方案
當(dāng)一個(gè)用戶,創(chuàng)建好后,如果該用戶創(chuàng)建了任意一個(gè)數(shù)據(jù)對(duì)象,這時(shí),我們的dbms就會(huì)創(chuàng)建一個(gè)對(duì)應(yīng)的方案與該用戶對(duì)應(yīng),并且該方案的名字和用戶名一致
小技巧:如果希望看到某個(gè)用戶的方案究竟有什么數(shù)據(jù)對(duì)象,我們可以用pl/sql developer


14.連接用戶
conn scott/tiger;


15.如果希望看到某個(gè)用戶的方案究竟有什么數(shù)據(jù)對(duì)象,我們可以用pl/sql developer


16.要求讓xiaohong用戶可以去查詢scott的emp表
步驟1:先用scott登錄
conn scott/tiger
步驟2:賦權(quán)限

grant select[update|delete|insert|all] on emp to xiaohong


conn xiaohong/m123
select * from scott.emp


第六講
1.創(chuàng)建用戶tea ,stu 并給這兩個(gè)用戶resource,connect角色
conn system/yzj;
create user tea identified by tea;
grant resource ?to tea;
grant connect to tea;
create user stu identified by stu;
grant resource ?to stu;
grant connect to stu;
2.使用scott用戶把對(duì)emp表的select權(quán)限給tea
conn scott/tiger;
grant select on emp to tea;
使用tea查詢scott的emp表
conn scott/tiger;
select * from scott.emp;
使用scott用戶把對(duì)emp表的所有權(quán)限賦給tea
conn scott/tiger;
grant all on emp to tea;
使用tea更新/刪除/插入 scott的emp表
conn tea/tea;
update scott.emp set job='Teacher' where job='&job';
delete from scott.emp where job='&job';
insert into scott.emp values(8888,'FORD','Teache','7698','08-9月 -81',1500,300,20);
使用scott收回權(quán)限
conn scott/tiger;
revoke select on scott.emp from tea;
revoke all on scott.emp from tea;
想辦法將讓tea把自己擁有的對(duì)scott.emp的權(quán)限轉(zhuǎn)給stu


scott->tea->stu [權(quán)限轉(zhuǎn)移.]


conn scott/tiger;
grant all on scott.emp to tea with grant option;


//with grant option 表示得到權(quán)限的用戶,可以把權(quán)限繼續(xù)分配
//with admin option 如果是系統(tǒng)權(quán)限,則帶with admin option?


conn tea/tea;
grant select on scott.emp to stu;
使用stu查詢scott用戶的emp表
conn stu/stu;
select * from scott.emp;
使用tea收回給stu的權(quán)限
conn tea/tea;
revoke select on scott.emp from stu;


profile是口令限制,資源限制的命令集合,當(dāng)建立數(shù)據(jù)時(shí),oracle會(huì)自動(dòng)建立名稱為default的profile,當(dāng)建立用戶沒有指定profile選項(xiàng),那oracle就會(huì)將default分配給用戶


需求:只允許某個(gè)用戶,最多嘗試登錄三次,如果三次沒有成功,則鎖定兩天,兩天后才能重新登錄
基本語法:
create profile 文件名 limit failed_login_attempts 3 password_lock_time 2;
alter user 用戶名 profile 文件名;


給賬戶用戶解鎖
alter user 用戶名 account unlock;


終止命令:為了讓用戶定期修改密碼可以使用終止口令的指令來完成,同樣這個(gè)命令也需要dba身份來操作
需求:說一個(gè)賬號(hào)密碼,最多10,寬限期為2天,到時(shí)必須設(shè)置新的密碼


creat profile myprofile limit password_life_time 10 password_grace_time 2 繼續(xù)加限制條件;
alter user tea profile myprofile;


口令歷史
如果希望用戶在修改密碼時(shí),不能使用以前使用過的密碼,可使用口令歷史,這樣oracle就會(huì)將口令修改的信息存放到數(shù)據(jù)字典中,這樣當(dāng)用戶修改密碼時(shí),oracle就會(huì)對(duì)新舊密碼
進(jìn)行比較,當(dāng)發(fā)現(xiàn)新舊密碼一樣時(shí),就提示用戶重新輸入密碼


create profile password_history limit password_life_time 10 password_grace_time 2 password_reuse_time 1;
alter user tea profile password_history;


刪除profile
drop profile profile文件名


cmd中啟動(dòng)oracle的監(jiān)聽服務(wù)
lsnrctl start


啟動(dòng)數(shù)據(jù)庫(kù)實(shí)例
oradim -startup -sid orclxuzhu?


查看電腦什么時(shí)候安裝的操作系統(tǒng),網(wǎng)卡信息
systeminfo


第七講
oracle認(rèn)證方式


conn system/xxx;
conn system/xxx as sysdba;
show user;
user為"sys"
conn xxx/xxx as sysdba;
show user;
user為"sys"


不用認(rèn)證用戶名和密碼 用戶就是sys


oracle用戶驗(yàn)證機(jī)制
普通用戶,默認(rèn)是以數(shù)據(jù)庫(kù)方式驗(yàn)證,比如:conn scott/xx


特權(quán)用戶(sys),默認(rèn)是以操作系統(tǒng)認(rèn)證(即:只要當(dāng)前這個(gè)用戶是在ora_dba組中,則可以通過),比如:conn system/orclxuzhu as sysdba?
dbms 一看到 as sysdba 則認(rèn)為要以特權(quán)用戶登錄,前面的用戶名和密碼不看,登錄后,自動(dòng)切換成sys用戶<=>conn sys/orclxuzhu
如果當(dāng)前用戶不在ora_dba組,這時(shí)再使用數(shù)據(jù)庫(kù)驗(yàn)證方式


如果輸入用戶名和密碼是對(duì)的 還是可以連接上的
conn sys/orclxuzhu as sysdba;


我們可以通過修改sqlnet.ora文件,讓特權(quán)用戶登錄的時(shí)候,直接使用數(shù)據(jù)庫(kù)驗(yàn)證
搜索到sqlnet.ora文件,修改
SQLNET.AUTHENTICATION_SERVICES=(NTS)


如何找回管理員密碼
搜索名為PWD數(shù)據(jù)庫(kù)名.ora文件
數(shù)據(jù)庫(kù)實(shí)例名是根據(jù)實(shí)際情況定,比如orclxuzhu
拷貝一份密碼文件
生成新的密碼文件,在dos控制臺(tái)下輸入命令
orapwd file=E:\myoracle\oracle\database\PWDorclxuzh.ora password=xuzhu entries=10
entries 表示登錄sys最多用戶


如果希望新的密碼生效,則需要重新啟動(dòng)數(shù)據(jù)庫(kù)實(shí)例




第八講
在運(yùn)行里面輸入
sqlplus 這個(gè)是dos窗口
sqlplusw 這個(gè)是應(yīng)用窗口


create table table_name{
? ?列名 列的數(shù)據(jù)類型
? ?......
}


create table users(
? ?id number,
? ?name varchar2(32),
? ?password varchar2(32),
? ?birthday date);


char(size) 定長(zhǎng) 存放字符串最大2000個(gè)字符 ? ? ? ?1個(gè)a1個(gè)字符 1個(gè)漢字2個(gè)字符 原因:1個(gè)空間是1個(gè)字節(jié)來表示的
舉例說明
create table test1(name char(32));
這樣在name這列,最多只能放入32個(gè)字符,如果超過,就報(bào)錯(cuò),如果不夠'abc',則用空格補(bǔ)全


varchar2 變長(zhǎng) 存放字符串最大4000個(gè)字符 ? ? ? ? ?1個(gè)a1個(gè)字符 1個(gè)漢字2個(gè)字符 原因:1個(gè)空間是1個(gè)字節(jié)來表示的


select name,dump(name) from test1;


如果我們的數(shù)據(jù)長(zhǎng)度是固定,比如商品編號(hào)(8),則應(yīng)當(dāng)使用char來存放,因?yàn)檫@樣存取速度快,如果存放數(shù)據(jù)的長(zhǎng)度是變化,則使用varchar2


nchar 定長(zhǎng) 編碼方式是unicode ? 最大字符2000個(gè) ? 1個(gè)a1個(gè)字符 1個(gè)漢字1個(gè)字符 原因:1個(gè)空間是2個(gè)字節(jié)來表示的


nvarchar2 變長(zhǎng) 編碼方式是unicode ? 最大字符4000個(gè) ? 1個(gè)a1個(gè)字符 1個(gè)漢字1個(gè)字符 原因:1個(gè)空間是2個(gè)字節(jié)來表示的


clob 字符型大對(duì)象 變長(zhǎng) 最大8tb


blob 變長(zhǎng) 最大8tb 說明,我們實(shí)際開發(fā)中很少把文件存放數(shù)據(jù)庫(kù)(效率問題),實(shí)際上我們一般記錄文件的有一個(gè)路徑(http://www.baidu.com/image/3.jpg d:/file/a.jpg)
然后通過io 網(wǎng)絡(luò)來操作
如果我們要求對(duì)文件安全性,可以考慮放入數(shù)據(jù)庫(kù)


第九講
number是變長(zhǎng)的
number可以存放整數(shù),也可以存放小數(shù)
number(p,s)
p為整數(shù)位,s為小數(shù)位 范圍:1<=p<=38,-84<=s<=127
保存數(shù)據(jù)范圍:-1.0e-130<=number value <1.0e+126
-1.0e-130(科學(xué)計(jì)數(shù)法) :就是-1.0乘以10的-130次方
保存在機(jī)器內(nèi)部的范圍:1~22bytes


舉例說明:
有效位:從左到右,第一個(gè)非0數(shù)就是第一個(gè)有效位


date日期類型
用于表示時(shí)間(年/月/日/時(shí)/分/秒)
insert into test8 values('11-11月-11');
oracle日期的默認(rèn)格式是'dd-mm-yyyy';如果我們希望使用自己習(xí)慣的日期添加,也可以,但是需要借助oracle函數(shù)


第十講
使用alter table 語句添加 修改 或刪除列的語法
alter table tablename
add (columnname datatype);


alter table tablename
modify (columnname datatype);


alter table tablename
drop column columnname;


alter table tablename
drop column (columnname1,columnname2);


修改表的名稱:rename 表名 to 新表名


刪除表
drop table tablename;


增刪改查
create table test10(id number);


insert into test10 (id) values('123'); 這是可以的 dbms視圖把數(shù)據(jù)轉(zhuǎn)化成對(duì)應(yīng)的字段類型


字符和日期類型數(shù)據(jù)應(yīng)包含在單引號(hào)中


oracle 會(huì)把‘’=Null


create table test14(name varchar2(64),age number);
insert into test14 (name,age) values("shunping",null);正確
insert into test14 (name) values("abc");正確 age就是null


如果給表的每列都添加值,則可以不帶列名


update 如果沒有where語句 就是更新所有的行


第十一講
update students set fellowship=10 where fellowship is null;


delete 如果不使用where子句,將刪除表中所有數(shù)據(jù)
delete from 表名 刪除表中所有數(shù)據(jù),表結(jié)構(gòu)還在,寫日志,可以恢復(fù)的,速度慢


delete語句不能刪除某一列的值,如果要?jiǎng)h除某列的值,則需要使用update語句


truncate table 表名:
刪除表中所有數(shù)據(jù),表結(jié)構(gòu)還在,不寫日志,無法找回刪除的記錄,速度快


savepoint aa;
delete from students;
rollback to aa;
select * from students;


查看表結(jié)構(gòu)
desc 表名


去重復(fù)行
返回的數(shù)據(jù)完全一樣才是重復(fù)行
select distinct deptno,job from emp order by deptno;


數(shù)據(jù)庫(kù)的內(nèi)容,字段 表名都不區(qū)分大小寫
sqlserver2000 不區(qū)分大小寫?
oracle 區(qū)分大小寫


虛表
select abs(-100) from dual;


select abs(sal) from emp;


select sal*sal from emp;


select sal*abs(sal) from emp;


select ename,sal*13+comm*13 from emp;


select ename,sal*13+NVL(comm,0)*13 from emp;


oracle 不讓用單引號(hào)
select ename,sal*13+NVL(comm,0)*13 "年薪" from emp;


select ename,sal*13+NVL(comm,0)*13 as 年薪 from emp;
說明:NVL函數(shù)是oracle提供的,用于處理數(shù)據(jù)null的問題
nvl(comm,0):如果comm為空null,則返回0,如果不為空,則返回本身的值


||:在查詢時(shí)如果希望把多列拼接起來作為一列返回可以使用||
select ename || '是一個(gè)' || job from emp;


select ename || ' 是一個(gè) ' || job from emp;


第十二講
我們希望刪除用戶,同時(shí)保留該用戶的數(shù)據(jù)對(duì)象,怎么處理
鎖定用戶
alter user scott account lock;
雖然鎖定了用戶 但是scott.emp在system 依然使用它的對(duì)象
select * from scott.emp;


用戶解鎖
alter user scott account unlock;


select * from emp where to_char(hiredate,'yyyy-mm-dd')>'1982-1-1';


select * from emp where to_char(hiredate,'yyyy')='1980';


select * from emp where to_char(hiredate,'mm')='4';


select * from emp where sal>=2000 and sal<=2500;


select * from emp where sal between 2000 and 2500;


%表示任意0到多個(gè)字符,_表示任意單個(gè)字符


如何顯示首字母為S的員工姓名和工資
select ename,sal from emp where ename like 'S%';


如何顯示第三個(gè)字符為大寫O的所有的員工姓名和工資
select ename,sal from emp where ename like '__O%';


第十三講
如何顯示empno為123,345,800的雇員情況
select * from emp where empno in(123,345,800);


如何顯示沒有上級(jí)的雇員的情況
select * from emp where mgr is null;


不寫asc也行 默認(rèn)是升序
select * from emp order by sal asc;


降序
select * from emp order by sal desc;


select * from emp order by deptno,hiredate desc;


select ename,sal*13+nvl(comm,0)*13 年薪 from emp order by 年薪;


下面這個(gè)也能排序
select ename,sal*13+nvl(comm,0)*13 年薪 from emp order by sal*13+nvl(comm,0)*13;


select max(sal) from emp;


select min(sal) from emp;


只能返回一個(gè)值 不確定是哪個(gè)人的
select max(sal*13+nvl(comm,0)*13) 年工資 from emp


select max(sal),min(sal) from emp;


avg會(huì)忽略sal為空的人
select avg(sal),sum(sal) from emp;


select sum(comm)/count(*) from emp;


總的員工數(shù)
select count(*) from emp;


comm不為空的字段
select count(comm) from emp;


select ename,job from emp where sal=(select max(sal) from emp);


select * from emp where sal>(select avg(sal) from emp);


select avg(sal),max(sal),deptno from emp group by deptno;


顯示每個(gè)部門的每種崗位的平均工資和最低工資
select avg(sal),max(sal),deptno,job from emp group by deptno,job order by deptno;


select avg(sal),deptno from emp group by deptno;


select avg(sal),deptno from emp group by deptno having avg(sal)<2000;


select avg(sal),deptno from emp group by deptno having avg(sal)>100 order by avg(sal);


第十四講
多表查詢
這下面兩個(gè)查詢語句效果一樣
select distinct * from emp,dept;
select ?* from emp,dept;


跟上面的條數(shù)一樣但是數(shù)據(jù)呈現(xiàn)有點(diǎn)不一樣
select ?* from dept,emp;


顯示各個(gè)員工的姓名,工資,及其工資級(jí)別
select emp.ename,emp.sal,salgrade.grade from emp,salgrade where emp.sal between salgrade.losal and salgrade.hisal;


select * from emp where empno=(select mgr from emp where ename='FORD');


顯示各員工的姓名和他的上級(jí)領(lǐng)導(dǎo)姓名
select worker.ename,boss.ename from emp worker,emp boss where worker.mgr=boss.empno;


select worker.ename,boss.ename from emp worker,emp boss where worker.mgr=boss.empno(+);左外連


select * from emp where deptno=(select deptno from emp where ename='SMITH') and ename !='SMITH';
select * from emp where deptno=(select deptno from emp where ename='SMITH') and ename <>'SMITH';


第十五講


如何查詢和部門10的工作相同的雇員的名字,崗位,工資,部門號(hào)
select ename,job,sal,deptno from emp where job in(select distinct job from emp where deptno=10);


如何顯示工資比部門30的所有員工的工資高的員工的姓名,工資和部門號(hào)
select ename,sal,deptno from emp where sal>all(select sal from emp where deptno =30);
select ename,sal,deptno from emp where sal>(select max(sal) from emp where deptno =30);


如何顯示工資比部門30的任意一個(gè)員工的工資高的員工的姓名,工資和部門號(hào)
select ename,sal,deptno from emp where sal>any(select sal from emp where deptno =30);
select ename,sal,deptno from emp where sal>(select min(sal) from emp where deptno =30);


如何查詢與smith的部門和崗位完全相同的所有雇員
select * from emp where (deptno,job)=(select deptno,job from where emp where ename='SMITH');


select * from emp where deptno=(select deptnofrom where emp where ename='SMITH') and job=(select job where emp where ename='SMITH');不好


第十六講
在from子句中使用子查詢
如何顯示高于自己部門平均工資的員工的信息


這里要用到數(shù)據(jù)查詢的小技巧,把一個(gè)子查詢當(dāng)作一個(gè)臨時(shí)表使用


各個(gè)部門的平均工資是多少?
select avg(sal),deptno from emp group by deptno;


把上面查詢的結(jié)果當(dāng)做一個(gè)臨時(shí)表對(duì)待
select t2.ename,t2.sal,t1.myavg ,t2.deptno
from emp t1,(select avg(sal) myavg,deptno from emp group by deptno) t1 where t2.deptno=t1.deptno and t2.sal>t1.myavg;


如何顯示各個(gè)部門最高工資的員工信息
select t2.ename,t2.sal,t1.mymax ,t2.deptno
from emp t1,(select max(sal) mymax,deptno from emp group by deptno) t1 where t2.deptno=t1.deptno and t2.sal=t1.mymax;


顯示每個(gè)部門的信息(編號(hào),名稱)和人員數(shù)量
先查詢出各個(gè)部門有多少人
select deptno,count(*) from emp group by deptno;
?
部門相同的只顯示一條數(shù)據(jù)
select deptno from emp group by deptno;


分組之后部門的數(shù)量
select count(*) from emp group by deptno;


部門表中有個(gè)一個(gè)部門 但是沒有人 結(jié)果沒有顯示那個(gè)沒有人的部門信息
select t1.dname,t2.num from dept t1,(select deptno,count(*) num from emp group by deptno) t2 ?where t1.deptno=t2.deptno;


把沒有人的那個(gè)部門也顯示出來了
select t1.dname,t2.num from dept t1,(select deptno,count(*) num from emp group by deptno) t2 ?where t1.deptno=t2.deptno(+);


分頁查詢
分頁查詢是我們學(xué)習(xí)任何數(shù)據(jù)庫(kù),必須掌握的一個(gè)要點(diǎn)
mysql:
select * from 表名 where 條件 limit 從第幾條取,取幾條


sqlserver:
select top 4 * from 表名 where id not in(select top 4 id from 表名 where 條件);
排除前4條,再取4條,這個(gè)案例實(shí)際上是取出5-8


select emp.*,rownum from emp;


oracle:
select t2.* from (select t1.*,rownum rn from (select * from emp) t1 where rownum<=6) t2 ?where rn>=4;


說明:上面的這個(gè)sql是oracle數(shù)據(jù)庫(kù)效率比較高的查詢方法,在百萬級(jí)都可以及時(shí)響應(yīng)


create table mytest as select empno,ename,sal,comm,deptno from emp;


自我復(fù)制


insert into mytest (empno,ename,sal,comm,deptno) select empno,ename,sal,comm,deptno from emp;


如果我們需要針對(duì)不同的情況,分頁,請(qǐng)?jiān)谧顑?nèi)層進(jìn)行處理,包括多表


第十七講
顯示每個(gè)部門每個(gè)崗位的平均工資,每個(gè)部門的平均工資,每個(gè)崗位的平均工資 ? ??
select avg(sal),deptno,job from emp group by cube(deptno,job)


inner join
select 列名.. from 表1 inner join 表二 on 條件..


left join的另外一種寫法
select stu.name,stu.id,exam.grade from stu,exam where stu.id = exam.id(+);


right join的另外一種寫法
select stu.name,stu.id,exam.grade from stu,exam where stu.id(+)= exam.id;


full out join?
select stu.name,stu.id,exam.grade from stu full outer join exam on stu.id = exam.id;


第十八講
select ename,job,hiredate from emp where hiredate between '01-2月-81' and '01-5月-81' order by hiredate;


select ename,job,hiredate from emp where to_char(hiredate,'yyyy-mm-dd') between '1981-02-01' and '1981-05-01' order by hiredate;


小結(jié):
1.分組函數(shù)(avg...)只能出現(xiàn)在選擇列表,having、order by 子句中
2.如果在select 語句中同事包含有g(shù)roup by,having,order by 那么他們的順序是group by,having,order by
3.在選擇列中如果有列,表達(dá)式,分組函數(shù),那么這些列和表達(dá)式必須有一個(gè)出現(xiàn)在group by 子句中,否則就會(huì)出錯(cuò)


下面這句錯(cuò)誤 order by 沒有意義

select ename,job,sal from emp where job ?in(select job from emp where depto = 30 order by job)


第十九講
創(chuàng)建數(shù)據(jù)庫(kù)有兩種方式:
通過oracle提供的向?qū)Чぞ?推薦
我們可以用手工步驟直接創(chuàng)建


client: ? ? ? ? ? ? ? ?oracle ? ? ? ? ? ? orclxuzhu ? ?方案(schema) scott ? ? ? 數(shù)據(jù)對(duì)象(table 過程 觸發(fā)器 view 序列)
sqlplus ? ? ? ? ? ? ? ? dbms ? ? ? ? ? ? ? ? ? ? ? ? ? ?方案(schema) system ? ? ?也有自己的數(shù)據(jù)對(duì)象
sqlplusw
pl/sql developer
網(wǎng)頁 企業(yè)管理器


數(shù)據(jù)庫(kù)orclxuzhu2 ?口令 ?orclxuzhu2


當(dāng)我們創(chuàng)建完一個(gè)新的數(shù)據(jù)庫(kù)實(shí)例后,在服務(wù)中就會(huì)有兩個(gè)新的服務(wù)創(chuàng)建,這時(shí),你根據(jù)實(shí)際需要去啟動(dòng)相應(yīng)的數(shù)據(jù)庫(kù)實(shí)例


在同一臺(tái)機(jī)器,可以同時(shí)啟動(dòng)多個(gè)數(shù)據(jù)庫(kù)實(shí)例,我們?cè)诘卿浕蜴溄拥臅r(shí)候,需要指定主機(jī)字符串


java連接oracle有兩種方式
1.jdbc直連 特別說明:如果使用jdbc連接,需要啟動(dòng)監(jiān)聽服務(wù)
A;sun公司提供了一套對(duì)數(shù)據(jù)庫(kù)操作接口/類 放在java.sql包 ? ? B;oracle公司把接口實(shí)現(xiàn)就打了一個(gè)包 ojdbc14.jar 提供給程序員使用
2.jdbc-odbc橋連接


第二十講
dml 語句(數(shù)據(jù)操作語言)[insert,update,delete]
ddl 語句(數(shù)據(jù)定義語音) create table drop table
dql 語句(數(shù)據(jù)查詢語言) select?
dcl 語句(數(shù)據(jù)控制語言) commit rollback


//完成查詢
ps.executeQuery();


//插入 刪除 更新
ps.executeUpdate();


第二十一講
jdbc-odbc橋連接
步驟如下:
(1)配置數(shù)據(jù)源
(2)1521的監(jiān)聽實(shí)際上是可以不起的


Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");//實(shí)際上是sun公司提供的
url="jdbc:odbc:hsporc"; hsporc是數(shù)據(jù)源名稱


橋連和直連 實(shí)際上改下driver url 就可以互相使用


insert into emp(empno,hiredate) values(2222,'1988-11-11')報(bào)錯(cuò) 因?yàn)槟J(rèn)格式是(日-月-年)而且年是兩位的,怎么解決 我們可以使用函數(shù)
TO_DATE(string,'format') 把字符串轉(zhuǎn)成指定格式的日期
insert into emp(empno,hiredate) values(2222,to_date('1988-11-11','yyyy-mm-dd'));

總結(jié)

以上是生活随笔為你收集整理的【自学oracle】韩顺平oracle视频教程学习笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 午夜淫片 | 美女露出粉嫩尿囗让男人桶 | 国产婷婷一区二区三区 | 色综合图区| 亚洲天堂系列 | 人妻 丝袜美腿 中文字幕 | 色导航 | 秘密基地免费观看完整版中文 | 国产剧情av在线 | 少妇捆绑紧缚av | 国产美女作爱视频 | 少妇h视频 | 亚洲综合色在线 | 一级黄色片在线播放 | 宅男午夜在线 | 黄片毛片在线免费观看 | 亚洲视频国产 | 成人性生交大片免费看96 | 日本女优在线看 | 亚洲综合在线观看视频 | 香蕉视频91 | 日韩精品视频在线免费观看 | 麻豆黄色网 | 精品人妻无码一区二区三区 | 久久久国产成人 | 亚洲精品视频在线观看视频 | 成人av网站在线观看 | 最近中文字幕 | 国产天堂| 亚洲天堂国产 | 2021毛片 | 操啊操 | 天天操天天碰 | 黄色理论视频 | 国产精品欧美性爱 | 草草影院发布页 | 玉女心经在线看 | 久久综合色88 | 国产在成人精品线拍偷自揄拍 | 91口爆一区二区三区在线 | 人妻av无码一区二区三区 | 99re在线视频观看 | 蜜桃精品成人影片 | 婷婷综合久久 | 久久久久久福利 | 国产理论av| 少妇精品 | 在线观看国产小视频 | 99热伊人| 九九热这里有精品 | 国产第一亚洲 | 综合xx网| 日韩视频免费播放 | 香蕉视频免费在线观看 | 林雅儿欧洲留学恋爱日记在线 | 欧美aaaa视频 | 好吊色视频一区二区 | av在线中文 | 国产做a | 日韩中文字幕一区二区三区四区 | 日韩欧美不卡在线 | brazzers欧美一区二区 | 久久阁| 奇米影视久久 | 亚洲精选中文字幕 | 亚洲欧美另类在线观看 | 天堂网视频在线观看 | 99av视频| 亚洲国产精品久久 | 人人爽夜夜爽 | 久久久久久久久久av | 九一亚色 | 国产一级久久久 | 91精品国产手机 | 18成人免费观看网站 | www.av视频在线观看 | 波多野结衣加勒比 | 亚洲天堂五月 | 河北彩花中文字幕 | 天天干天天色天天 | 国产不卡一区 | 久久久久亚洲av无码专区喷水 | 日韩啪啪网 | 亚洲逼院 | 禁漫天堂免费网站 | 红桃视频成人在线 | 中文字幕在线资源 | 成年人网站黄 | 久久免费精品 | 瑟瑟视频在线 | 精品不卡一区二区三区 | 欧美一区二区三区激情啪啪 | 欧美日韩系列 | 精品视频一区二区三区四区五区 | 亚洲精品入口 | 成人一区二区在线观看 | 色呦呦麻豆 | 亚洲国产97在线精品一区 | 森泽佳奈中文字幕 |