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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

oracle的学习笔记(转)

發(fā)布時(shí)間:2023/12/20 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle的学习笔记(转) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Oracle的介紹

1. Oracle的創(chuàng)始人----拉里?埃里森2. oracle的安裝



[連接Oracle步驟](](https://img2018.cnblogs.com/blog/1224549/201810/1224549-20181017214101430-1777213931.png)

3. oracle的體系結(jié)構(gòu):數(shù)據(jù)庫: 在oracle中,數(shù)據(jù)庫只有一個(gè),就是全局?jǐn)?shù)據(jù)庫(orcl)---不同模塊的表結(jié)構(gòu),通過用戶區(qū)分實(shí)例表空間(datafile 'C:/db1.dbf'): 一個(gè)邏輯概念,就是用來存儲(chǔ)數(shù)據(jù)庫表的 用戶 數(shù)據(jù)文件: 用來具體存儲(chǔ)數(shù)據(jù)信息的,磁盤上的具體文件

準(zhǔn)備工作:

1. 創(chuàng)建表空間:create tablespace 名稱datafile 'c:\itheima.dbf'size 100m -- 大小 autoextend on -- on 表示自動(dòng)擴(kuò)充 next 10m -- 每次擴(kuò)充的大小 2. 刪除表空間 drop tablespace 名稱; 3. 創(chuàng)建用戶: create user 用戶名 identified by 用戶名 -- 設(shè)置密碼 default tablespace 用戶名; -- 指定用戶所屬的表空間 4. 用戶授權(quán): connect -- 連接角色 resource --開發(fā)者角色 dba --超級(jí)管理員角色 grant dba to 用戶名 -- 賦予權(quán)限

表的基本操作:

常用數(shù)據(jù)類型: varchar, varchar2,date,number(10,2)==>10是總長(zhǎng)度,2表示小數(shù)點(diǎn)后的位數(shù) 1. 創(chuàng)建表 create table person( pid number(20), pname varchar2(10) ); 2. 修改表 1. 添加一列 alter table person add gender number(1); 2. 添加多列 alter table person add (gender number(1),(age number(3))); 3. 修改列類型: alter table person modify gender char(1); 4. 修改列名稱: alter table person rename column gender to sex; 5. 刪除一列: alter table person drop column sex;

增刪改基本操作:

1. 增加insert into person (pid,pname) values (1,'小明'); commit; 2. 修改 update person set pname = '小馬' where pid = 1; commit; 3. 刪除 delete from person; ---刪除表中全部記錄 drop table person; ---刪除表結(jié)構(gòu) truncate table person; ---先刪除表,再次創(chuàng)建表,效果等同于刪除表中的全部記錄

修改字符集:

select userenv('language') from dual; 配置環(huán)境變量: NLS_LANG 值為查詢出的結(jié)果

序列:默認(rèn)從1開始,依次遞增,為主鍵賦值使用(Mysql的自增)

1. 創(chuàng)建create sequence s_person; 2. 查看(序列不屬于任何一張表,但是可以邏輯和表做綁定)select s_person.nextval from dual; --- dual表示的是虛表,補(bǔ)全語法,沒有任何意義 select s_person.currval from dual; 3. 基本使用: insert into person (pid,pname) values (s_person.nextval,'王智');

解鎖用戶

1. alter user scott account unlock; ------------> 解鎖scott用戶,如果在安裝的時(shí)候已經(jīng)解鎖,可以不需要設(shè)置 2. alter user scott identified by tiger; --解鎖scott用戶的密碼【此句也可以用來重置密碼】

單行函數(shù):作用于一行,返回一個(gè)值

1. 字符函數(shù)select upper('yes') from dual; ==== 小寫變大寫select lower('yes') from dual; ==== 大寫變小寫 CONCAT : 拼接兩個(gè)字符串,與 || 相同 select concat('Hello',' Oracle') from dual; INITCAP : 將字符串的第一個(gè)字母變?yōu)榇髮?select INITCAP('hello') from dual; 2. 數(shù)值函數(shù) select round(26.18, 1) from dual; ==== 四舍五入,后面的參數(shù)表示保留的小數(shù)點(diǎn)后的位置,如果是-1呢?自行測(cè)試 select trunc(26.18, 1) from dual;直接截取 select mod(10, 3) from dual; ==== 求余數(shù) 3. 日期函數(shù): select sysdate - e.hiredate from emp e; === 查詢emp表所有員工入職到現(xiàn)在多少天了,sysdate表示當(dāng)前時(shí)間 select sysdate + 1 from dual; === 算出明天此刻(運(yùn)算操作都是針對(duì)天) select months_between(sysdate,e.hiredate) from emp e; 查詢emp表所有員工入職到現(xiàn)在多少月了 如果算年呢? 禮拜呢? 考慮使用上面兩個(gè)例子的基礎(chǔ)上修改 select months_between(sysdate,e.hiredate) / 12 from emp e; select (sysdate - e.hiredate) / 7 from emp e; 4. 轉(zhuǎn)換函數(shù): select to_char(sysdate,'fm yyyy-mm-dd hh24:mi:ss') from dual; === 日期轉(zhuǎn)字符串,去掉fm試試?去掉24試試? select to_date('2018-6-7 16:39:50','fm yyyy-mm-dd hh24:mi:ss') from dual; === 字符串轉(zhuǎn)日期 5. 通用函數(shù): select e.sal * 12 + nvl(e.comm,0) from emp e; === 算出emp表中所有員工的年薪(由于comm獎(jiǎng)金有null值,所以需要排除掉null值,nvl表示判斷第一個(gè)數(shù)是否為null,是則返回第二個(gè)參數(shù),不是返回第一個(gè)參數(shù)) select e.sal * 12 + nvl2(e.comm,e.comm,0) from emp e;=== 第一個(gè)參數(shù)是判定值,第二個(gè)是不為null的返回值,第三個(gè)是為null的返回值

條件表達(dá)式(1和2是mysql和oracle通用):

1. 給emp表中員工起中文名稱: select e.ename,case e.ename when 'SMITH' then '曹操' when 'WARD' then '諸葛' else '無名' end from emp e; 2. 判斷emp表中員工工資,高于3000,顯示高收入,1500-3000中等,其余低等 select e.ename, case when e.ename > 3000 then '高收入' when e.ename > 1500 then '中等收入' else '低收入' end from emp e; 3. oracle專用: select e.ename, decode(e.ename 'SMITH' , '曹操' , 'WARD' , '諸葛' , '無名') 中文名 from emp e; 中文名表示起別名,在oracle中,除了起別名,都用單引號(hào),別名可以不用引號(hào)或者使用雙引號(hào)

多行/聚合函數(shù):作用于多行,返回一個(gè)值

select count(1) from emp; -- 查詢總數(shù)量 select sum(sal) from emp; -- 工資總和 select max(sal) from emp; -- 最大工資 select min(sal) from emp; -- 最低工資 select avg(sal) from emp; -- 平均工資

分組查詢

1. 查詢出每個(gè)部門的平均工資:select e.deptno,avg(e.sal)from emp egroup by e.deptno 2. select [字段列表] from 表名 where 條件 group by 字段 having 條件; --- 字段列表: group by之后的字段和聚合統(tǒng)計(jì)函數(shù) 3. where和having的區(qū)別: where: 在group by分組之前進(jìn)行條件的過濾 having: 在group by分組之后進(jìn)行條件的過濾

多表查詢

1. 笛卡爾積(沒有任何意義) 2. 等值連接select * from emp e, dept d where e.deptno = d.deptno; 3. 內(nèi)連接select * from emp e inner join dept d on e.deptno = d.deptno; 4. 外連接(左/右) select * from emp e left join dept d on e.deptno = d.deptno; select * from emp e right join dept d on e.deptno = d.deptno; select * from emp e full join dept d on e.deptno = d.deptno;

自連接查詢:

關(guān)鍵在于起別名 查詢出員工的姓名和員工領(lǐng)導(dǎo)的姓名 select e1.ename. e2.ename from emp e1. emp e2 where e1.mgr = e2.empno;

子查詢(盡量使用多表查詢,不要使用子查詢-----sql優(yōu)化)

子查詢返回一個(gè)值(=)子查詢返回一個(gè)集合(in)子查詢返回一張表(子查詢,把查詢出的結(jié)果看作一個(gè)表起別名來使用)

Oracle的分頁:

rownum偽列,配合三層嵌套子查詢完成 條件中的rownum是從1開始的,不能設(shè)置大于某個(gè)數(shù)字,所以考慮使用別名 select * from (select rownum rn,t.* from ( select e.* from emp e order by sal desc ) t where rownum < 11 ) where rn > 5;

視圖和索引

視圖:1. 視圖的概念:提供一個(gè)查詢窗口,所有數(shù)據(jù)來自于原表2. 視圖的操作:創(chuàng)建視圖(必須有dba權(quán)限)create or replace view v_name as 查詢語句;使用視圖 select * from v_name; 視圖修改字段(可以修改,但是不推薦) update v_emp set job='CLERK' where ename='ALLEN'; commit; 創(chuàng)建只讀視圖 create view v_name as 查詢語句 with read only; 3. 視圖的作用: 1. 視圖可以屏蔽掉敏感字段(數(shù)據(jù)安全) 2. 方便操作,數(shù)據(jù)的統(tǒng)一 4. 創(chuàng)建表(將查詢結(jié)果存入表中): create table table_name as 查詢語句; ----- create table emp as select * from scott.emp; 索引: 1. 索引的概念: 在表的列上構(gòu)建一個(gè)二叉樹,達(dá)到大幅度提高查詢效率的目的,但是索引會(huì)影響增刪改的效率 2. 索引創(chuàng)建的時(shí)機(jī): 1. 數(shù)據(jù)量大的表 2. 經(jīng)常查詢的表 3. 針對(duì)什么樣的字段建立索引: 經(jīng)常在where條件后的字段 4. 索引的分類: * 單列索引 1. 創(chuàng)建: create index idx_name on table_name(column_name); 2. 觸發(fā)規(guī)則(單行函數(shù),模糊查詢都會(huì)影響索引的觸發(fā),也就是不會(huì)觸發(fā)索引): 單列索引觸發(fā)規(guī)則,條件必須是索引列中的原始值 * 復(fù)合索引 1. 創(chuàng)建: create index idx_name on table_name(column_name1,column_name2); 2. 觸發(fā)規(guī)則: 復(fù)合索引第一列為優(yōu)先檢索列. 如果要觸發(fā)復(fù)合索引,必須包含有優(yōu)先檢索列中的原始值

pl/sql編程語言

1. 概念:pl/sql編程語言對(duì)sql語言的擴(kuò)展,使得sql語言具有過程化編程的特性.主要用來編寫存儲(chǔ)過程和存儲(chǔ)函數(shù)的. 2. 聲明方法:declarei number(2) := 10; ====> 定義普通變量 s varchar2(10) := '小明'; ena table_name.column_name%type; ====> 定義引用型變量,類型與表的字段類型一樣 emprow emp%rowtype; ====> 記錄型變量 begin dbms_output.put_line(i); ====> 輸出 dbms_output.put_line(s); select ename into ena from emp where empno = 1; ====> 使用查詢語句為變量賦值 dbms_output.put_line(ena); select * into emprow from emp where empno = 1; -- 不能直接輸出emprow,輸出emprow.column來輸出內(nèi)容 dbms_output.put_line(emprow.ename || '工作為' || emprow.job); end; 3. if判斷: declare i number(3) := &i; ====> 輸入值,將值給i begin if 條件1 then 條件1滿足執(zhí)行的邏輯 elsif 條件2 then 條件2滿足執(zhí)行的邏輯 else 條件都不滿足執(zhí)行的邏輯 end if; end; -------------------------------------------- declare -- 輸入值 i number(2) := &i; begin if i < 18 then dbms_output.put_line('未成年'); elsif i < 30 then dbms_output.put_line('青年'); elsif i < 50 then dbms_output.put_line('壯年'); else dbms_output.put_line('老年'); end if; end; 4. loop循環(huán): 1. while循環(huán): declare i number(2) := 1; ===> 如果i遞增越界,會(huì)報(bào)異常 begin while 條件 loop 執(zhí)行邏輯(輸出等); 條件變量的改變; ===> i := i+1; end loop; end; 2. exit循環(huán)(掌握掌握): declare i number(2) := 1; begin loop exit when 條件; ===> 條件符合,退出循環(huán) 執(zhí)行邏輯(輸出等); 條件變量的改變; end loop; end; 3. for循環(huán) decalre begin for i in 1..10 loop ===> 兩個(gè)點(diǎn)代表范圍 執(zhí)行邏輯; end loop; end; 5. 游標(biāo)的使用: 游標(biāo): 可以存放多個(gè)對(duì)象,多行記錄(臨時(shí)存放多行數(shù)據(jù)). declare cursor c1 is select * from emp; ====> 定義游標(biāo) emprow emp%rowtype; begin open c1; ===> 打開游標(biāo) loop fetch c1 into emprow; ====> 獲取游標(biāo)中的一行記錄 exit when c1%notfound; ====> 查找不到對(duì)象的時(shí)候自動(dòng)退出(notfound是游標(biāo)中的屬性,用來判斷是否還有數(shù)據(jù)) dbms_output.put_line(emprow.ename); end loop; close c1; ===> 關(guān)閉游標(biāo) end; -------------------------------------------------------- 為指定部門漲工資 declare cursor c3(dno emp.deptno%type) is select empno from emp where deptno = dno; eno emp.empno%type; begin open c3(20); loop fetch c3 into eno; exit when c3%notfound; update emp set sal=sal + 100 where empno = eno; commit; end loop; close c3; end;

存儲(chǔ)過程和存儲(chǔ)函數(shù)

1. 存儲(chǔ)過程(提高復(fù)用性,提高業(yè)務(wù)邏輯的執(zhí)行效率):1. 概念: 提前已經(jīng)編譯好的一段pl/sql片段,放置在數(shù)據(jù)庫端,可以直接被調(diào)用,這一段pl/sql一般都是固定步驟的業(yè)務(wù).2. 創(chuàng)建語法(參數(shù)類型不能加長(zhǎng)度):create or replace procedure 過程名(參數(shù)名 in/out 數(shù)據(jù)類型) ===> in可以省略 AS/IS 變量的聲明; begin PLSQL子程序體; end; ------------------------------------------------------ 給指定員工漲工資: create or replace procedure p1(eno in emp.empno%type) as begin update emp set sal=sal+100 where empno = eno; commit; end; 3. 調(diào)用存儲(chǔ)過程(兩種) 通過PL/SQL進(jìn)行調(diào)用 declare begin p1(1); end; 通過java程序調(diào)用 2. 存儲(chǔ)函數(shù): 1. 創(chuàng)建(返回的參數(shù)類型和參數(shù)的類型不能加長(zhǎng)度): create or replace function fun_name(參數(shù)名 in type,....) return 參數(shù)類型 is 變量名 變量類型; begin 執(zhí)行邏輯; return 結(jié)果變量; end 函數(shù)名; ---------------- 存儲(chǔ)函數(shù)算年薪 create or replace function fun_salyear(eno in number) return number is yearsal number(10); begin select sal*12+nvl(comm,0) into yearsal from emp where empno = eno; return yearsal; end; 2. 調(diào)用: 存儲(chǔ)函數(shù)在調(diào)用的時(shí)候返回值必須接受. declare 返回變量的聲明 begin 返回變量 := 函數(shù)名(參數(shù)); 邏輯處理; end; ----------------- declare yearsal number(10); begin yearsal := fun_salyear(7788); dbms_output.put_line(yearsal); end; 3. out參數(shù)的使用: 存儲(chǔ)過程算年薪: --------- 使用存儲(chǔ)過程測(cè)試out參數(shù)的使用 create or replace procedure pro_yearsal(eno in emp.empno%type,yearsal out number) is begin select sal*12+nvl(comm,0) into yearsal from emp where empno = eno; end; ----------- 測(cè)試 declare yearsal number(10); begin pro_yearsal(7788,yearsal); dbms_output.put_line(yearsal); end; 另外一種寫法: ---- 存儲(chǔ)過程計(jì)算年薪的另外一種寫法 create or replace procedure pro_yearsal2(eno in emp.empno%type,yearsal out number) is s number(10); c emp.comm%type; begin select sal*12,nvl(comm,0) into s,c from emp where empno = eno; yearsal := s + c; end; ---- 調(diào)用存儲(chǔ)過程 declare yearsal number(10); begin pro_yearsal2(7788,yearsal); dbms_output.put_line(yearsal); end; 4. in和out的參數(shù)區(qū)別是什么? in: 輸入的參數(shù)(默認(rèn)值) out: 輸出參數(shù)(對(duì)外暴露的變量) 調(diào)用的時(shí)候需要傳入的值就是輸入?yún)?shù),調(diào)用的時(shí)候不需要傳入值并且在執(zhí)行完成后還需要獲取的值是輸出參數(shù). 5. 存儲(chǔ)過程和存儲(chǔ)函數(shù)的區(qū)別 1. 語法區(qū)別: * 關(guān)鍵字不一樣: procedure和function * 存儲(chǔ)函數(shù)比存儲(chǔ)過程多了兩個(gè)return 2. 本質(zhì)區(qū)別: 存儲(chǔ)函數(shù)有返回值,存儲(chǔ)過程沒有返回值. > 實(shí)際開發(fā)中,還是存儲(chǔ)過程用的比較多.

觸發(fā)器

1. 觸發(fā)器的概念:制定一個(gè)規(guī)則,在我們做增刪改操作前(before)后(after),只要滿足規(guī)則,自動(dòng)觸發(fā),無需調(diào)用. 2. 分類語句級(jí)觸發(fā)器: 在insert/update/delete語句的時(shí)候觸發(fā)一次,不包含有for each row的就是語句級(jí)觸發(fā)器. 行級(jí)觸發(fā)器: 在insert/update/delete語句的時(shí)候影響多少行就觸發(fā)多少次,包含有for each row的就是行級(jí)觸發(fā)器. 3. 偽記錄變量: 一般在修改的刪除的時(shí)候用的多,用于備份,下面兩個(gè)只能用于行級(jí)觸發(fā)器. :old,獲取操作前的數(shù)據(jù) :new,獲取操作后的數(shù)據(jù) 4. 創(chuàng)建語句級(jí)觸發(fā)器 create or replace trigger trigger_name before/after insert/update/delete on table_name declare begin 邏輯的執(zhí)行; end; ---------------------------------------------- ---- 創(chuàng)建語句級(jí)觸發(fā)器 create or replace trigger tri_name after insert on person declare begin dbms_output.put_line('插入一條數(shù)據(jù)'); end; ---- 滿足條件即可觸發(fā)觸發(fā)器 insert into person values(s_person.nextval,'b'); 5. 觸發(fā)器的觸發(fā): 只要滿足條件就觸發(fā). 6. 創(chuàng)建行級(jí)別的觸發(fā)器: create or replace trigger trigger_name before/after insert/update/delete on table_name for each row declare begin 邏輯的執(zhí)行; end; --------------------------------------------- ---- 創(chuàng)建行級(jí)插入觸發(fā)器觸發(fā)器,輸出插入的id值 create or replace trigger tri_id after insert on person for each row declare begin dbms_output.put_line('插入的數(shù)據(jù)id是:' || :new.pid); end; ---- 滿足條件即可觸發(fā)觸發(fā)器 insert into person values(s_person.nextval,'b'); 7. pl/sql拋出異常(第一個(gè)參數(shù)是異常的編碼,第二個(gè)是異常的提示信息) raise_application_error(-20001~-20999之間,'提示信息'); 8. 觸發(fā)器實(shí)現(xiàn)主鍵自增(行級(jí)觸發(fā)器) create or replace trigger trigger_name before insert on table_name for each row declare begin select seq_person.nextval into :new.主鍵名 from dual; end; ---------------------------------- ---- 創(chuàng)建主鍵自增的觸發(fā)器(主鍵自增一定是行級(jí)觸發(fā)器,并且在插入之前) create or replace trigger auid before insert on person for each row declare begin select s_person.nextval into :new.pid from dual; end; ---- 使用主鍵自增的觸發(fā)器 insert into person(pname) values ('小zhi'); select * from person;

存儲(chǔ)函數(shù)和觸發(fā)器的兩個(gè)小例子:

---- 創(chuàng)建不能給員工降薪的觸發(fā)器 create or replace trigger tri_raise_sal before update on emp for each row declare begin if :old.sal > :new.sal then raise_application_error(-20001,'不能給員工降薪'); end if; end; update emp set sal = sal - 1 where empno = 7788; ---- 使用存儲(chǔ)函數(shù)實(shí)現(xiàn)提供部門id,查詢部門名稱 create or replace function fun_ename_dname(dno dept.deptno%type) return dept.dname%type is dna dept.dname%type; begin select dname into dna from dept where deptno = dno; return dna; end; ---- 使用上面的存儲(chǔ)函數(shù) select e.ename, fun_ename_dname(e.deptno) from emp e; select e.ename, d.dname from emp e, dept d where e.deptno=d.deptno;

java程序連接Oracle數(shù)據(jù)庫

oracle10g----> ojdbc14.jar oracle11g----> ojdbc6.jar與mysql相比,不同的地方在于驅(qū)動(dòng)包不同,url不同. 1. 首先需要注意的是oracle的ojdbc的驅(qū)動(dòng)jar包從maven中央倉庫下載不下來,所以只能手動(dòng)向本地倉庫進(jìn)行安裝:mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=D:/ojdbc14.jar --- 后面的Dfile是你本地的ojdbc14.jar存放的位置 2. 使用java連接oracle的步驟: // 加載數(shù)據(jù)的驅(qū)動(dòng) Class.forName("oracle.jdbc.driver.OracleDriver"); // 獲取數(shù)據(jù)庫的連接,ip是oracle服務(wù)所在服務(wù)器的ip,username表示用戶名,password表示密碼 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@ip:1521:orcl","username","password";) // 得到預(yù)編譯的Statement對(duì)象(增刪改查的時(shí)候使用) PreparedStatement ps = connection.preparedStatement("sql語句"); // 設(shè)置預(yù)編譯sql語句中的占位符 preparedStatement.setObject(1,"值"); // 執(zhí)行數(shù)據(jù)庫查詢操作 ResultSet rs = ps.executeQuery(); // 處理結(jié)果集 while(rs.next()){ 邏輯處理; } // 釋放資源 rs.close(); ps.close(); connection.close(); 3. 使用java執(zhí)行存儲(chǔ)過程和存儲(chǔ)函數(shù) /** * java調(diào)用存儲(chǔ)過程 * {?= call <procedure-name>[(<arg1>,<arg2>, ...)]} 調(diào)用存儲(chǔ)函數(shù)使用 * {call <procedure-name>[(<arg1>,<arg2>, ...)]} 調(diào)用存儲(chǔ)過程使用 * @throws Exception */ @Test public void testProcedure() throws Exception{ // 加載數(shù)據(jù)庫驅(qū)動(dòng) Class.forName("oracle.jdbc.driver.OracleDriver"); // 得到連接 Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.88.131:1521:orcl", "itheima", "itheima"); // 得到預(yù)編譯的Statement對(duì)象 CallableStatement cs = connection.prepareCall("{call pro_yearsal(?,?)}"); // 替換占位符 cs.setObject(1,7788); cs.registerOutParameter(2, OracleTypes.NUMBER); // 執(zhí)行查詢操作 cs.executeQuery(); // 輸出結(jié)果 System.out.println(cs.getObject(2)); // 釋放資源 cs.close(); connection.close(); } /** * java調(diào)用存儲(chǔ)過程 * {?= call <procedure-name>[(<arg1>,<arg2>, ...)]} 調(diào)用存儲(chǔ)函數(shù)使用 * {call <procedure-name>[(<arg1>,<arg2>, ...)]} 調(diào)用存儲(chǔ)過程使用 * @throws Exception */ @Test public void testFunction() throws Exception{ // 加載數(shù)據(jù)庫驅(qū)動(dòng) Class.forName("oracle.jdbc.driver.OracleDriver"); // 得到連接 Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@192.168.88.131:1521:orcl", "itheima", "itheima"); // 得到預(yù)編譯的Statement對(duì)象 CallableStatement cs = connection.prepareCall("{?=call fun_salyear(?)}"); // 替換占位符 cs.setObject(2,7788); cs.registerOutParameter(1, OracleTypes.NUMBER); // 執(zhí)行查詢操作 cs.executeQuery(); // 輸出結(jié)果 System.out.println(cs.getObject(1)); // 釋放資源 cs.close(); connection.close(); }

轉(zhuǎn)載地址:https://www.cnblogs.com/wadmwz/p/9806854.html

轉(zhuǎn)載于:https://www.cnblogs.com/Stir-friedEggplant/p/9897519.html

總結(jié)

以上是生活随笔為你收集整理的oracle的学习笔记(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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