oracle 學習
1 用plsql 連接 plsql cyts_cc/cyts_cc@cyts
2 sqlplusw 打開oracle sql*plus 界面。
3 plsql 中commond window 實現了sql*plus 的所有功能。
4 programmer window 和 test windown 實現了編程和調試的功能。
5 pl/sql 的結構
? create or replace procedure test
? declare
??? c_name varchar(5);
? begin
??? select name into c_name from emp where id=@no;
??? dbms output.put_line('客戶名稱:'||c_name);
? exception
??? when no_data_found then
??? dbms_output.put_line('請輸入正確雇員號!');
end test;
輸入no得值
6 匿名塊/命名塊
命名塊主要是為了在嵌套結構是區分層次
<<outter>>
declare
??? c_name varchar(5);
? begin
???? <<inner>>
???? begin
???????? ....
???? end;
??? select name into c_name from emp where id=@no;
??? dbms output.put_line('客戶名稱:'||c_name);
? exception
??? when no_data_found then
??? dbms_output.put_line('請輸入正確雇員號!');
end test;
7 調用 存儲過程
?exec pro_name
?call pro_name
8 調用函數
?call anual_income into income
9 保用于邏輯作合相關的過程和函數,包括包頭,和包體,在包頭中只定義存儲過程or函數,在包體中
? 定義實現。
10 標量變量
varchar2(n)max 4000 char(n) max 2000 number(p,s) p 總的位長,s 小數電后面的位長
date ,timestamp,long(類似于varchar) max 32760,long raw 二進制 32760
binary_fload 和 binary_double oralce 10g 用于高精度計算高速計算。
11 定義標量變量
?c_max_value constant number(3,2):=5.5
?constant,default,not null,:=
12 %type
13 復合變量
?1 pl/sql 記錄 類似于高級語言中的結構
?? type emp_record_type is record(
???? name emp.ename%type
???? salary emp.sal%type);
?? emp_record emp_record_type;
? 2 pl/sql 表,類似于高級語言中的數組,單其下標可以為負,且元素個數沒有上下限。
??? declare
???? type ename_table_type is table of emp.ename%type
???? index by binary_integger;
???? ename_table ename_table_type;
??? select ename into ename_table(-1) from emp where &enomo='1118'
? 3 嵌套表結構還有些看不懂,先放下,以后在看
?14 參照變量
?? 參照變量是指由于存放指針的變量。通過石油參量變量可以使用相同的對象。
?? 1 ref cursor
??? 當顯示游標時,需要在定義顯示游標時制定響應的select語句,當使用游標變量時,在定義是不需
?? 指定select 語句,而是在游標指定select 語句
??? declare
???? type c1 is ref cursor
???? emp_cursor c1
??? ...............
??? begin
???? ipen emp_cursor for select ename,sal from emp where deptno=10;
???? loop
????? fetch emp_sursor into v_ename,v_sal;
????? exit when emp_cursor%not found
????? ...........
????? end loop;
??? close emp_sursor;
?? 2 ref obj_type
??? 可以引用對象類型
??? create or replace type home_type as object(
?????? street varchar2(50),city varchar2(20),
?????? owner varchar(10)
??? );
??? create table homes of home_type;
??? insert into homes values('222','3333');
???
??? create table person(
????? id number(6) primary key,
????? name varchar2(10),
????? addr ref home_type
??? );
??? inert into person select 1,'22',ref(p) from homes p where p.owner='22'
?14 lob 變量
??? lob 分為內部lob(clob,blob,nclob ) 和外部lob(bfile),內部lob 存在數據庫內,支持事務。外部
??? lob 存在外部,不支持事務?