【自学oracle】韩顺平oracle视频教程学习笔记
oracle的數(shù)據(jù)對象(表,視圖,序列,函數(shù),包,過程,觸發(fā)器)
不同的數(shù)據(jù)庫 數(shù)據(jù)對象未必是完全相同的
例如sqlserver2000里面就沒有包
多少人用(并發(fā)問題)
第二講
1.9i只有一個安裝文件
2.把這個10201_database_win32.zip文件拷貝到?jīng)]有中文的路徑下
3.到電腦的服務(wù)選項(xiàng)去確定本機(jī)沒有安裝oracle數(shù)據(jù)庫,如果有,則卸載
orclxuzhu 命令
4.解鎖步驟
? 先使用system登錄
? 然后輸入alter user scott account unlock
?5 system用戶名 orclxuzhu密碼
第三講
1.show user 當(dāng)前用戶名是什么
2.請使用scott用戶登錄oracle數(shù)據(jù)庫實(shí)例,然后,切換身份為system用戶登錄后,使用conn[ect] 用戶名/密碼@網(wǎng)絡(luò)[as sysdba/as sysoper]
? ?
3.簡單使用:conn[ect] 用戶名/密碼?
? ?該命令經(jīng)常用于切換當(dāng)前用戶,因此我們建議大家在登錄的時(shí)候使用普通用戶,scott,如果確實(shí)需要system用戶,則可以使用該命令切換為高級用戶
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 用戶控制每行顯示多少個字符,默認(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)限才能登陸,給一個用戶賦權(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.給小紅分配兩個常用角色
grant connect to xiaohong
grant resource to xiaohong?
4.讓xiaohong登錄
connect xiaohong/m123
5.小紅修改密碼 如果不加上名字表示對當(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)我們刪除一個用戶的時(shí)候,如果這個用戶自己已經(jīng)創(chuàng)建過數(shù)據(jù)對象,那么我們在刪除用戶的時(shí)候,需要加選項(xiàng)cascade,表示把這個用戶刪除同時(shí),把該用戶創(chuàng)建的數(shù)據(jù)對象一并刪除
12.顯示當(dāng)前連接用戶
show user?
13.oracle方案
當(dāng)一個用戶,創(chuàng)建好后,如果該用戶創(chuàng)建了任意一個數(shù)據(jù)對象,這時(shí),我們的dbms就會創(chuàng)建一個對應(yīng)的方案與該用戶對應(yīng),并且該方案的名字和用戶名一致
小技巧:如果希望看到某個用戶的方案究竟有什么數(shù)據(jù)對象,我們可以用pl/sql developer
14.連接用戶
conn scott/tiger;
15.如果希望看到某個用戶的方案究竟有什么數(shù)據(jù)對象,我們可以用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
select * from scott.emp
第六講
1.創(chuàng)建用戶tea ,stu 并給這兩個用戶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用戶把對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用戶把對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把自己擁有的對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會自動建立名稱為default的profile,當(dāng)建立用戶沒有指定profile選項(xiàng),那oracle就會將default分配給用戶
需求:只允許某個用戶,最多嘗試登錄三次,如果三次沒有成功,則鎖定兩天,兩天后才能重新登錄
基本語法:
create profile 文件名 limit failed_login_attempts 3 password_lock_time 2;
alter user 用戶名 profile 文件名;
給賬戶用戶解鎖
alter user 用戶名 account unlock;
終止命令:為了讓用戶定期修改密碼可以使用終止口令的指令來完成,同樣這個命令也需要dba身份來操作
需求:說一個賬號密碼,最多10,寬限期為2天,到時(shí)必須設(shè)置新的密碼
creat profile myprofile limit password_life_time 10 password_grace_time 2 繼續(xù)加限制條件;
alter user tea profile myprofile;
口令歷史
如果希望用戶在修改密碼時(shí),不能使用以前使用過的密碼,可使用口令歷史,這樣oracle就會將口令修改的信息存放到數(shù)據(jù)字典中,這樣當(dāng)用戶修改密碼時(shí),oracle就會對新舊密碼
進(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中啟動oracle的監(jiān)聽服務(wù)
lsnrctl start
啟動數(shù)據(jù)庫實(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ù)庫方式驗(yàn)證,比如:conn scott/xx
特權(quán)用戶(sys),默認(rèn)是以操作系統(tǒng)認(rèn)證(即:只要當(dāng)前這個用戶是在ora_dba組中,則可以通過),比如:conn system/orclxuzhu as sysdba?
dbms 一看到 as sysdba 則認(rèn)為要以特權(quán)用戶登錄,前面的用戶名和密碼不看,登錄后,自動切換成sys用戶<=>conn sys/orclxuzhu
如果當(dāng)前用戶不在ora_dba組,這時(shí)再使用數(shù)據(jù)庫驗(yàn)證方式
如果輸入用戶名和密碼是對的 還是可以連接上的
conn sys/orclxuzhu as sysdba;
我們可以通過修改sqlnet.ora文件,讓特權(quán)用戶登錄的時(shí)候,直接使用數(shù)據(jù)庫驗(yàn)證
搜索到sqlnet.ora文件,修改
SQLNET.AUTHENTICATION_SERVICES=(NTS)
如何找回管理員密碼
搜索名為PWD數(shù)據(jù)庫名.ora文件
數(shù)據(jù)庫實(shí)例名是根據(jù)實(shí)際情況定,比如orclxuzhu
拷貝一份密碼文件
生成新的密碼文件,在dos控制臺下輸入命令
orapwd file=E:\myoracle\oracle\database\PWDorclxuzh.ora password=xuzhu entries=10
entries 表示登錄sys最多用戶
如果希望新的密碼生效,則需要重新啟動數(shù)據(jù)庫實(shí)例
第八講
在運(yùn)行里面輸入
sqlplus 這個是dos窗口
sqlplusw 這個是應(yīng)用窗口
create table table_name{
? ?列名 列的數(shù)據(jù)類型
? ?......
}
create table users(
? ?id number,
? ?name varchar2(32),
? ?password varchar2(32),
? ?birthday date);
char(size) 定長 存放字符串最大2000個字符 ? ? ? ?1個a1個字符 1個漢字2個字符 原因:1個空間是1個字節(jié)來表示的
舉例說明
create table test1(name char(32));
這樣在name這列,最多只能放入32個字符,如果超過,就報(bào)錯,如果不夠'abc',則用空格補(bǔ)全
varchar2 變長 存放字符串最大4000個字符 ? ? ? ? ?1個a1個字符 1個漢字2個字符 原因:1個空間是1個字節(jié)來表示的
select name,dump(name) from test1;
如果我們的數(shù)據(jù)長度是固定,比如商品編號(8),則應(yīng)當(dāng)使用char來存放,因?yàn)檫@樣存取速度快,如果存放數(shù)據(jù)的長度是變化,則使用varchar2
nchar 定長 編碼方式是unicode ? 最大字符2000個 ? 1個a1個字符 1個漢字1個字符 原因:1個空間是2個字節(jié)來表示的
nvarchar2 變長 編碼方式是unicode ? 最大字符4000個 ? 1個a1個字符 1個漢字1個字符 原因:1個空間是2個字節(jié)來表示的
clob 字符型大對象 變長 最大8tb
blob 變長 最大8tb 說明,我們實(shí)際開發(fā)中很少把文件存放數(shù)據(jù)庫(效率問題),實(shí)際上我們一般記錄文件的有一個路徑(http://www.baidu.com/image/3.jpg d:/file/a.jpg)
然后通過io 網(wǎng)絡(luò)來操作
如果我們要求對文件安全性,可以考慮放入數(shù)據(jù)庫
第九講
number是變長的
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
舉例說明:
有效位:從左到右,第一個非0數(shù)就是第一個有效位
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)化成對應(yīng)的字段類型
字符和日期類型數(shù)據(jù)應(yīng)包含在單引號中
oracle 會把‘’=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語句不能刪除某一列的值,如果要刪除某列的值,則需要使用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ù)庫的內(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 不讓用單引號
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 || '是一個' || job from emp;
select ename || ' 是一個 ' || job from emp;
第十二講
我們希望刪除用戶,同時(shí)保留該用戶的數(shù)據(jù)對象,怎么處理
鎖定用戶
alter user scott account lock;
雖然鎖定了用戶 但是scott.emp在system 依然使用它的對象
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到多個字符,_表示任意單個字符
如何顯示首字母為S的員工姓名和工資
select ename,sal from emp where ename like 'S%';
如何顯示第三個字符為大寫O的所有的員工姓名和工資
select ename,sal from emp where ename like '__O%';
第十三講
如何顯示empno為123,345,800的雇員情況
select * from emp where empno in(123,345,800);
如何顯示沒有上級的雇員的情況
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 年薪;
下面這個也能排序
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;
只能返回一個值 不確定是哪個人的
select max(sal*13+nvl(comm,0)*13) 年工資 from emp
select max(sal),min(sal) from emp;
avg會忽略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;
顯示每個部門的每種崗位的平均工資和最低工資
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);
第十四講
多表查詢
這下面兩個查詢語句效果一樣
select distinct * from emp,dept;
select ?* from emp,dept;
跟上面的條數(shù)一樣但是數(shù)據(jù)呈現(xiàn)有點(diǎn)不一樣
select ?* from dept,emp;
顯示各個員工的姓名,工資,及其工資級別
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');
顯示各員工的姓名和他的上級領(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的工作相同的雇員的名字,崗位,工資,部門號
select ename,job,sal,deptno from emp where job in(select distinct job from emp where deptno=10);
如何顯示工資比部門30的所有員工的工資高的員工的姓名,工資和部門號
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的任意一個員工的工資高的員工的姓名,工資和部門號
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ù)查詢的小技巧,把一個子查詢當(dāng)作一個臨時(shí)表使用
各個部門的平均工資是多少?
select avg(sal),deptno from emp group by deptno;
把上面查詢的結(jié)果當(dāng)做一個臨時(shí)表對待
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;
如何顯示各個部門最高工資的員工信息
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;
顯示每個部門的信息(編號,名稱)和人員數(shù)量
先查詢出各個部門有多少人
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;
部門表中有個一個部門 但是沒有人 結(jié)果沒有顯示那個沒有人的部門信息
select t1.dname,t2.num from dept t1,(select deptno,count(*) num from emp group by deptno) t2 ?where t1.deptno=t2.deptno;
把沒有人的那個部門也顯示出來了
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ù)庫,必須掌握的一個要點(diǎn)
mysql:
select * from 表名 where 條件 limit 從第幾條取,取幾條
sqlserver:
select top 4 * from 表名 where id not in(select top 4 id from 表名 where 條件);
排除前4條,再取4條,這個案例實(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;
說明:上面的這個sql是oracle數(shù)據(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;
如果我們需要針對不同的情況,分頁,請?jiān)谧顑?nèi)層進(jìn)行處理,包括多表
第十七講
顯示每個部門每個崗位的平均工資,每個部門的平均工資,每個崗位的平均工資 ? ??
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á)式必須有一個出現(xiàn)在group by 子句中,否則就會出錯
下面這句錯誤 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ù)庫有兩種方式:
通過oracle提供的向?qū)Чぞ?推薦
我們可以用手工步驟直接創(chuàng)建
client: ? ? ? ? ? ? ? ?oracle ? ? ? ? ? ? orclxuzhu ? ?方案(schema) scott ? ? ? 數(shù)據(jù)對象(table 過程 觸發(fā)器 view 序列)
sqlplus ? ? ? ? ? ? ? ? dbms ? ? ? ? ? ? ? ? ? ? ? ? ? ?方案(schema) system ? ? ?也有自己的數(shù)據(jù)對象
sqlplusw
pl/sql developer
網(wǎng)頁 企業(yè)管理器
數(shù)據(jù)庫orclxuzhu2 ?口令 ?orclxuzhu2
當(dāng)我們創(chuàng)建完一個新的數(shù)據(jù)庫實(shí)例后,在服務(wù)中就會有兩個新的服務(wù)創(chuàng)建,這時(shí),你根據(jù)實(shí)際需要去啟動相應(yīng)的數(shù)據(jù)庫實(shí)例
在同一臺機(jī)器,可以同時(shí)啟動多個數(shù)據(jù)庫實(shí)例,我們在登錄或鏈接的時(shí)候,需要指定主機(jī)字符串
java連接oracle有兩種方式
1.jdbc直連 特別說明:如果使用jdbc連接,需要啟動監(jiān)聽服務(wù)
A;sun公司提供了一套對數(shù)據(jù)庫操作接口/類 放在java.sql包 ? ? B;oracle公司把接口實(shí)現(xiàn)就打了一個包 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)錯 因?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视频教程学习笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [css] 怎么给手持设备添加特殊样式
- 下一篇: [css] css中padding和m