1. 程式人生 > >Oracle語句詳解

Oracle語句詳解

ORACLE支援五種型別的完整性約束

NOT NULL (非空)--防止NULL值進入指定的列,在單列基礎上定義,預設情況下,ORACLE允許在任何列中有NULL值.

CHECK (檢查)--檢查在約束中指定的條件是否得到了滿足.

UNIQUE (唯一)--保證在指定的列中沒有重複值.在該表中每一個值或者每一組值都將是唯一的.

PRIMARY KEY (主鍵)--用來唯一的標識出表的每一行,並且防止出現NULL值,一個表只能有一個主鍵約束.

POREIGN KEY (外部鍵)--通過使用公共列在表之間建立一種父子(parent-child)關係,在表上定義的外部鍵可以指向主鍵或者其他表的唯一鍵.ORACLE支援五種型別的完整性約束

NOT NULL (非空)--防止NULL值進入指定的列,在單列基礎上定義,預設情況下,ORACLE允許在任何列中有NULL值.

CHECK (檢查)--檢查在約束中指定的條件是否得到了滿足.

UNIQUE (唯一)--保證在指定的列中沒有重複值.在該表中每一個值或者每一組值都將是唯一的.

PRIMARY KEY (主鍵)--用來唯一的標識出表的每一行,並且防止出現NULL值,一個表只能有一個主鍵約束.

POREIGN KEY (外部鍵)--通過使用公共列在表之間建立一種父子(parent-child)關係,在表上定義的外部鍵可以指向主鍵或者其他表的唯一鍵.

1--設定每行顯示多少字元  setlinesize  300;

2 設定每頁顯示多少條記錄 set pagesize 30;

3 使用者名稱的切換: 如 conn system/tiger

Conn sys/change_on_install as sysdba(注意超級使用者 在後面加assysdba)

4 在超級使用者下查詢普通使用者的表是查不到的 必須這樣查詢  如 select * fromscott.emp(普通使用者下的emp表)

5 檢視當前是那個使用者身份登入: show user;

6 檢視有多少張表: select * from tab;(注意不同使用者下的表是不同的)

7查看錶的結構: desc emp(emp為表名)

8 取出重複的列(DISTINCT):

如 SELECTDISTINCT  JOB EMP(去掉job的重複的值)

9字串的連結操作用:  ||

10 查詢有獎金的員工: select* from emp where comm is not null;

11 查詢沒有獎金的員工資訊: select * from emp where comm is null;

12 兩個條件以上就得用and 如查詢工資大雨1500和有獎金的員工 select * from emp where                                                                                                          sal>1500  and comm is not null;

13 表示兩個條件有一個滿足就可就用:or 如查詢工資大於1500或者沒有獎金的員工資訊

Select * from emp where sal>1500 or comm is not null;

14取反可以用not 如 查詢員工工資不大於1500和有獎金的員工資訊如:

 Select * from emp where not(sal>1500  or comm is not null);

15 在什麼什麼之間用between----and----如查詢工資在1500和3000之間的員工資訊:

Select * from emp  where sal  between 1500 and 3000;

16   查詢員工編號是2323,4555, 2222的員工具體資訊: 如

Select * from emp where empno in(2323,4555,2222);

17.l模糊查詢  like 一般結合"%"和"_"使用其中%:表示可以匹配任意長度的內容,"_"表示匹配一個長度放入內容  如:  查詢員工姓名中第二哥字母是M的員工資訊:

Select * from emp where ename LIKE '_M%';

又如姓名中包含M的員工  Select * from emp where ename LIKE  '%M%';

18oracle中不等於有兩種表示方式"<>"和"!="

19 排序用order by {asc desc}其中asc 是升序排列如果不寫就預設按升序排列desc是按降序排列 排序語句放在sal語句的最後如: 按員工工資進行排序

Select * from emp order by sal asc(升序)

Selecct * from emp order by sal desc(降序)

Select * from emp where deptno='10' order by sal desc,hiredate asc;(查詢部門10的員工工資的升序排列如果工資相等就按員工的入職時間排序)

20.group by 用於對查詢的結果進行分組統計: 顯示每個部門的平均工資和最高工資  如:

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

Having  子句用於限制分組顯示結果: 顯示平均工資大於2000的的部門號和他的平均工資?

如:select avg(sal), deptno from emp group by deptnohaving avg(sal)>2000;

2. 單行函式:

1 小寫變大寫: upper 如 select * from empwhere ename=upper('smith');

講一個字串變為小寫字母表示 如: select  lower('HELLO WORLD') FROMDUAL;

將單詞的首字母變大寫 用 INITCAP 如: SELECTINITCAP('HELLO WORLD') FROM DUAL;

2.字串的操作

  Substr()擷取字串 length()字串的長度 replace()替換字串

3數值函式

四捨五入: round();

截斷小數位:trunc();

一.入門部分

1.    建立表空間

create tablespace schooltbs datafile ‘D:\oracle\datasource\schooltbs.dbf’size 10M autoextend on;

2.    刪除表空間

drop tablespace schooltbs[including contents and datafiles];

3.    查詢表空間基本資訊

select *||tablespace_name from DBA_TABLESPACES;

4.    建立使用者

create user  lihua

identified by lihua

default tablespace schooltbs

temporary tablespace temp;

5.    更改使用者

alter user lihua

identified by 123

default tablespace users;

6.    鎖定使用者

alter user lihua account lock|unlock;

7.    刪除使用者

drop user lihua cascade;--刪除使用者模式

8.    oracle資料庫中的角色

connect,dba,select_catalog_role,delete_catalog_role,execute_catalog_role,exp_full_database,imp_full_database,resource

9.    授予連線伺服器的角色

grant connect to lihua;

10.授予使用表空間的角色

grant resource to lihua with grant option;--該使用者也有授權的許可權

11.授予操作表的許可權

grant select,insert on user_tbl to scott;--當前使用者

grant delete,update on lihua.user_tbl to scott;--系統管理員

12.修改表的結構(alter)

Alter table  表名 add(列的名稱,列的型別);

二.SQL查詢和SQL函式

1.SQl支援的命令:

資料定義語言(DDL):create,alter,drop

資料操縱語言(DML):insert,delete,update,select

資料控制語言(DCL):grant,revoke

事務控制語言(TCL):commit,savepoint,rollback

2.Oracle資料型別

字元,數值,日期,RAW,LOB

字元型

char:1-2000位元組的定長字元

varchar2:1-4000位元組的變長字元

long:2GB的變長字元

注意:一個表中最多可有一列為long

Long列不能定義唯一約束或主鍵約束

long列上不能建立索引

過程或儲存過程不能接受long型別的引數。

數值型

number:最高精度38

日期時間型

date:精確到ss

timestamp:秒值精確到小數點後6

函式

sysdate,systimestamp返回系統當前日期,時間和時區。

更改時間的顯示

alter session set nls_date_language=’american’;

alter session set nls_date_format=’yyyy-mm-dd’;

Oracle中的偽列

像一個表列,但沒有儲存在表中

偽列可以查詢,但不能插入、更新和修改它們的值

常用的偽列:rowid和rownum

rowid:表中行的儲存地址,可唯一標示資料庫中的某一行,可以使用該列快速定位表中的行。

rownum:查詢返回結果集中的行的序號,可以使用它來限制查詢返回的行數。

3.資料定義語言

用於操作表的命令

create table

alter table

truncate table

drop table

修改表的命令

alter table stu_table rename to stu_tbl;--修改表名

alter table stu_tbl rename column stu_sex to sex;--修改列名

alter table stu_tbl add (stu_age number);--新增新列

alter table stu_tbl drop(sex);--刪除列

alter table stu_tbl modify(stu_sex varchar2(2));--更改列的資料型別

alter table stu_tbl add constraint pk_stu_tbl primary key(id);--新增約束

4.資料操縱語言

select,update,delete,insert

利用現有的表建立表

create table stu_tbl_log as select id,stu_name,stu_age from stu_tbl;--

選擇無重複的行

select distinct stu_name from stu_tbl;--

插入來自其他表中的記錄

insert into stu_tbl_log select id,stu_name,stu_age from stu_tbl;

5.資料控制語言

grant,revoke

6.事務控制語言

commit,savepoint,rollback

7.SQL操作符

算術操作符:L+-*/

比較操作符:L=,!=,<>,>,<,>=,<=,between-and,in,like,isnull

邏輯操作符:Land,or,not

集合操作符:Lunion,union all,intersect,minus

連線操作符:L||

示例中stu_tbl_log中的資料如下:

        ID STU_NAME                STU_AGE

---------- -------------------- ----------

      1000 李華                          20

      1001 accp                         20

      1003 nimda                         3

stu_tbl中的資料如下:

        ID STU_NAME             ST    STU_AGE

---------- -------------------- -- ----------

      1000 李華                  男         20

      1001 accp                 男         20

      1002 admin                男         30

示例:

select (3+2)/2 from dual;--算術操作符,結果:2.5

select * from stu_tbl where stu_age>=20;--比較操作符

select * from stu_tbl where stu_name like '%a%';--比較操作符:like

select * from stu_tbl where stu_name like 'a___';--比較操作符:like

select * from stu_tbl where stu_age in(20,30);--比較操作符:in

select * from stu_tbl where stu_age between 20 and 30;--比較操作符:between

select stu_name from stu_tbl union all

select stu_name from stu_tbl_log;--集合操作符:unionall,測試結果具體如下:

STU_NAME

-----------

李華

accp

admin

李華

accp

nimda

已選擇6行。

select stu_name from stu_tbl union

select stu_name from stu_tbl_log;--集合操作符:union,測試結果具體如下:

STU_NAME

---------

accp

admin

nimda

李華

select stu_name from stu_tbl intersect

select stu_name from stu_tbl_log;--集合操作符:intersect,測試結具體如下:

STU_NAME

----------

accp

李華

select stu_name from stu_tbl minus

select stu_name from stu_tbl_log;--集合操作符:minus,測試結果如下:

STU_NAME

----------

Admin

從中可以看出:

minus是獲取第一張表獨有的資料

intersect是獲取兩張表中都有的資料

union是整合兩張表的資料,都有的只顯示一次

union all是純粹的兩張表資料整合

select id,stu_name||' '||stu_sex as name_sex,stu_age

from stu_tbl;--連線操作符||,測試結果具體如下:

        ID NAME_SEX                   STU_AGE

---------- ----------------------- ----------

      1000 李華    男                         20

      1001 accp   男                         20

      1002 admin  男                         30

8.SQL函式

單行函式:從表中查詢的每一行只返回一個值,可出現在select子句,where子句中

日期函式

數字函式

字元函式

轉換函式:ToChar(),ToDate(),ToNumber()

其他函式:

Nvl(exp1,exp2):表示式一為null時,返回表示式二

Nvl2(exp1,exp2,exp3):表示式一為null時返回表示式三,否則返回表示式二

Nullif(exp1,exp2):兩表示式相等時,返回null,否則返回表示式一

分組函式:基於一組行來返回

Avg,Min,Max,Sum,Count

Group by,having

分析函式

Row_number,rank,dense_rank

示例:

select u.user_name,sum(oi.order_num*oi.order_price) as total,row_number()over (order by sum(oi.order_num*oi.order_price) desc) as sort fromorder_item_tbl

  oi,user_tbl  u,order_tbl o where oi.order_id = o.id and o.user_id = u.id group by u.user_name;

三.鎖和資料庫物件

1.鎖:資料庫用來控制共享資源併發訪問的機制。

鎖的型別:行級鎖,表級鎖

行級鎖:對正在被修改的行進行鎖定。行級鎖也被稱之為排他鎖。

在使用下列語句時,Oracle會自動應用行級鎖:

insert,update,delete,select…… for update

select……for update允許使用者一次鎖定多條記錄進行更新。

使用commit or rollback釋放鎖。

表級鎖:

lock table user_tbl in mode mode;

表級鎖型別:

行共享 row share

行排他 row exclusive

共享 share

共享行排他 share row exclusive

排他 exclusive

死鎖:兩個或兩個以上的事務相互等待對方釋放資源,從而形成死鎖

2.資料庫物件

oracle資料庫物件又稱模式物件

資料庫物件是邏輯結構的集合,最基本的資料庫物件是表

資料庫物件:

表,序列,檢視,索引

序列

用於生成唯一,連續序號的物件。

建立語法:

create sequence user_id_seq

start with 1000

increment by 1

maxvalue 2000

minvalue 1000

nocycle

cache 1000;--指定記憶體中預先分配的序號

訪問序列:

select user_id_seq.currval from dual;

select user_id-seq.nextval from dual;

更改刪除序列:

alter sequence user_id_seq maxvalue 10000;--不能修改其start with

drop sequence user_id_seq;

在Hibernate中訪問序列:

user_id_seq

檢視

以經過定製的方式顯示來自一個或多個表的資料

建立檢視:

create or replace view

user_tbl_view (vid,vname,vage)

as select id,user_name,age from user_tbl

[with check option]|[with read only];

建立帶有錯誤的檢視:

create force view user_tbl_force_view as

select * from user_table;--此時user_table可以不存在

建立外聯接檢視:

create view user_stu_view as

select u.id,u.user_name,u.password,s.ddress

from user_tbl u,stu_tbl s

where u.s_id(+)=s.id;--哪一方帶有(+),哪一方就是次要的

刪除檢視:

drop user_stu_view;

索引

用於提高SQL語句執行的效能

索引型別:

唯一索引,點陣圖索引,組合索引,基於函式的索引,反向鍵索引

建立標準索引:

create index user_id_index on user_tbl(id) tablespace schooltbs;

重建索引:

alter index user_id_index rebuild;

刪除索引:

drop index user_id_index;

建立唯一索引:

create unique index user_id_index on user_tbl(id);

建立組合索引:

create index name_pass_index on user_tbl(user_name,password);

建立反向鍵索引:

create index user_id_index on user_tbl(id) reverse;

四.使用PL/SQL

可用於建立儲存過程,觸發器,程式包,給SQL語句的執行新增程式邏輯。

支援SQL,在PL/SQL中可以使用:

資料操縱命令

事務控制命令

遊標控制

SQL函式和SQL運算子

支援面向物件程式設計(OOP)

可移植性

更佳的效能,PL/SQL經過編譯執行

分為三個部分:宣告部分,可執行部分和異常處理部分

[declare

declarations]

begin

executable statements

[exception

handlers]

end;

開啟輸出

set serverout on;

--根據輸入編號獲取某學員的成績--if

declare

score user_tbl.score%type;

begin

select score into score from user_tbl where id='&id';

if score>90 then

dbms_output.put_line('優秀');

elsif score>80 then

dbms_output.put_line('良好');

elsif score>60 then

dbms_output.put_line('及格');

else

dbms_output.put_line('差');

end if;

end;

--根據學員姓名獲取某學員的成績--if

declare

score user_tbl.score%type;

begin

select score into score from user_tbl where user_name='&name';

if score>90 then

dbms_output.put_line('優秀');

elsif score>80 then

dbms_output.put_line('良好');

elsif score>60 then

dbms_output.put_line('及格');

else

dbms_output.put_line('差');

end if;

end;

--case的使用

declare

grade user_tbl.grade%type;

begin

select grade into grade from user_tbl where id='&id';

case grade

when 'A' then dbms_output.put_line('優異');

when 'B' then dbms_output.put_line('優秀');

when 'C' then dbms_output.put_line('良好');

else dbms_output.put_line('一般');

end case;

end;

--基本迴圈

declare

i number(4):=1;

begin

loop

dbms_output.put_line('loop size:'||i);

i:=i+1;

exit when i>10;

end loop;

end;

--while迴圈

declare

i number(4):=1;

begin

while i<=10 loop

dbms_output.put_line('while loop size='||i);

i:=i+1;

end loop;

end;

--for迴圈

declare

i number(4):=1;

begin

for i in 1..10 loop

dbms_output.put_line('for loop Size:'||i);

end loop;

end;

declare

i number(2):=1;

j number(2):=1;

begin

for i in reverse 1..9 loop

for j in 1..i loop

dbms_output.put(j||'x'||i||'='||j*i||' ');

end loop;

dbms_output.put_line('');

end loop;

end;

--動態SQL

declare

userId number(2);

sql_str varchar2(100);

userName user_tbl.user_name%type;

begin

execute immediate 'create table testExe(id number,test_namevarchar2(20))';

userId:='&userId';

sql_str:='select user_name from user_tbl where id=:id';

execute immediate sql_str into userName using userId;

dbms_output.put_line(userName);

end;

(or

declare

 id_param number:='&id_param';

 sql_str varchar2(100);

 name_param stu_tbl.stu_name%type;

 begin

 sql_str:='select stu_name fromstu_tbl where id=:p';

 execute immediate sql_str intoname_param using id_param;

 dbms_output.put_line(name_param);

 end;

 /

)

--異常處理

declare

grade number(4);

begin

grade:='&grade';

case grade

when 1 then dbms_output.put_line('好的');

--else dbms_output.put_line('不好');

end case;

exception

when case_not_found then

dbms_output.put_line('輸入型別不匹配!');

end;

--系統異常

declare

rowD user_tbl%rowtype;

begin

select * into rowD from user_tbl;

dbms_output.put_line(rowD.id||''||rowD.user_name||' '||rowD.password);

exception

when too_many_rows then

dbms_output.put_line('不能將多行賦予一個屬性!');

end;

or

declare

rowD user_tbl%rowtype;

begin

select * into rowD from user_tbl where id=5;

dbms_output.put_line(rowD.id||' '||rowD.user_name||' '||rowD.password);

exception

when too_many_rows then

dbms_output.put_line('不能將多行賦予一個屬性!');

when no_data_found then

dbms_output.put_line('沒有您要查詢的資料!');

end;

--自定義錯誤

declare

invalidError exception;

category varchar2(20);

begin

category:='&category';

if category not in('附件','頂盤','備件') then

raise invalidError;

else

dbms_output.put_line('您輸入的類別是:'||category);

end if;

exception

when invalidError then

dbms_output.put_line('無法識別的類別!');

end;

--引發應用程式異常

declare

app_exception exception;

grade user_tbl.grade%type;

begin

select grade into grade from user_tbl where id=&id;

if grade='A' then

raise app_exception;

else

dbms_output.put_line('查詢的等級為:'||grade);

end if;

exception

when app_exception then

raise_application_error(-20001,'未知的等級!');

end;

五、遊標管理

遊標型別:隱式遊標,顯式遊標,REF遊標

REF遊標用於處理執行時才能確定的動態SQL查詢的結果

==========隱式遊標==========

在PL/SQL中使用DML語句時自動建立隱式遊標

隱式遊標自動宣告、開啟和關閉,其名為SQL

隱式遊標的屬性:

%found         SQL語句影響實質後返回true

%notfound      SQL語句沒有影響實質後返回true

%rowcount      SQL語句影響的行數

%isopen        遊標是否開啟,始終為false

示例:

begin

update user_tbl set score=score+5;

if SQL%found then

    dbms_output.put_line('資料被更改: '||SQL%rowcount);

elsif sql%notfound then

    dbms_output.put_line('沒有找到資料!');

end if;

if SQL%isopen then

    dbms_output.put_line('Open');

else

    dbms_output.put_line('Close');

end if;

end;

==========顯式遊標==========

在PL/SQL的宣告部分定義查詢,該查詢可以返回多行

J         宣告遊標

J         開啟遊標

J         從遊標中取回資料

J         關閉遊標

宣告遊標完成兩個任務:

給遊標命名

將一個查詢與遊標關聯

cursor cursor_name is select statement;

開啟遊標:

    open cursor_name;

取資料:

    fetch cursor_name intorecord_list;

關閉遊標:

    close cursor_name;

顯式遊標的屬性:

%found         執行最後一條fetch語句成功返回行時為true

%notfound      執行最後一條fetch語句未能返回行時為true

%rowcount      返回到目前為止遊標提取的行數

%isopen        遊標是否開啟

示例:

declare

users user_tbl%rowtype;

cursor boys_cur is select * from user_tbl where sex='h';

begin

open boys_cur;

loop

fetch boys_cur into users;

exit when boys_cur%notfound;

dbms_output.put_line(users.user_name||' '||users.password);

dbms_output.put_line(boys_cur%rowcount);

end loop;

close boys_cur;

end;

帶參的顯式遊標

declare

users user_tbl%rowtype;

cursor boys_cur(sexParam varchar2)

is select * from user_tbl where sex=sexParam;

begin

open boys_cur('&sex');

loop

fetch boys_cur into users;

exit when boys_cur%notfound;

dbms_output.put_line(users.user_name||' '||users.password);

dbms_output.put_line(boys_cur%rowcount);

end loop;

close boys_cur;

end;

使用顯式遊標更新行

declare

cursor user_update_cur is select sex from user_tbl for update;

usersex user_tbl.sex%type;

begin

open user_update_cur;

loop

fetch user_update_cur into usersex;

exit when user_update_cur%notfound;

dbms_output.put_line(usersex);

if usersex = 'M' then

    update user_tbl setscore=score-5 where current of user_update_cur;

else

    update user_tbl set score=score+5where current of user_update_cur;

end if;

end loop;

close user_update_cur;

commit;

end;

循環遊標

declare

cursor user_cur is select * from user_tbl;

begin

for username in user_cur loop

   dbms_output.put_line(username.user_name||'  '||username.sex);

end loop;

end;

==========REF遊標==========

REF遊標和遊標變數用於處理執行時動態執行的SQL查詢

建立遊標變數的步驟:

J         宣告REF遊標型別

J         宣告REF遊標型別的變數

宣告型別的語法

Type ref_cursor_name is ref cursor [return return_type];

開啟遊標變數的語法

Open cursor_name for select_statement;

----宣告強型別的遊標

declare

type ref_cur is ref cursor return user_tbl%rowtype;

users_cur ref_cur;

----宣告弱型別的遊標

declare

type ref_cur is ref cursor;

users_cur ref_cur;

示例

----強型別

declare

type ref_cur is ref cursor return user_tbl%rowtype;

users_cur ref_cur;

users user_tbl%rowtype;

begin

open users_cur for select * from user_tbl where user_name='ny2t92';

loop

    fetch users_cur into users;

    exit when users_cur%notfound;

   dbms_output.put_line(users.user_Name);

end loop;

close users_cur;

end;

----弱型別

declare

type ref_cur is ref cursor;

my_cur ref_cur;

users user_tbl%rowtype;

stus stu_tbl%rowtype;

begin

open my_cur for select * from user_tbl;

loop

    fetch my_cur into users;

    exit when my_cur%notfound;

   dbms_output.put_line(users.user_Name);

end loop;

close my_cur;

open my_cur for select * from user_tbl where user_name='ny2t92';

loop

    fetch my_cur into users;

    exit when my_cur%notfound;

   dbms_output.put_line(users.user_Name);

end loop;

close my_cur;

open my_cur for select * from stu_tbl;

loop

fetch my_cur into stus;

exit when my_cur%notfound;

dbms_output.put_line(stus.stu_Name);

end loop;

close my_cur;

end;

----動態SQL遊標

declare

type ref_cur is ref cursor;

my_cur ref_cur;

users user_tbl%rowtype;

username varchar2(20);

sqlstmt varchar2(200);

begin

username:='&username';

sqlstmt := 'select * from user_tbl where user_name= :name';

open my_cur for sqlstmt using username;

loop

    fetch my_cur into users;

    exit when my_cur%notfound;

   dbms_output.put_line(users.user_Name);

end loop;

close my_cur;

end;

六.子程式

子程式分為:儲存過程和函式,它是命名的PL/SQL塊,編譯並存儲在資料庫中。

子程式的各個部分:宣告部分,可執行部分,異常處理部分。

過程----執行某些操作

函式----執行操作並返回值

==========儲存過程==========

建立過程的語法:

create or replace procedure

proce_name (parameter_list)

is|as

local variable declaration

begin

executable statements

exception

exception_handlers

end proce_name;

過程引數的三種模式:

In----用於接收呼叫的值,預設的引數模式

Out----用於向呼叫程式返回值

In out----用於接收呼叫程式的值,並向呼叫程式返回更新的值

執行過程的語法:

Execute proce_name(parameter_list);

Declare

Variable var_list;

Begin

Proce_name(var_list);

End;

將過程執行的許可權授予其他使用者:

Grant execute on proce_name to scott;

Grant execute on proce_name to public;

刪除儲存過程:

Drop procedure proce_name;

==========函式==========

建立函式的語法:

Create or replace function

Fun_name (parameter_list)

Return datatype is|as

Local declarations

Begin

Executable statements;

Return result;

Exception

Exce_handlers;

End;

函式只能接收in引數,不能接受out或in out引數,形參不能是PL/SQL型別

函式的返回型別也必須是資料庫型別

訪問函式的方式:

J         使用PL/SQL

J         使用SQL語句

Select fun_name(parameter_list) from dual;

相關推薦

Oracle語句

ORACLE支援五種型別的完整性約束 NOT NULL (非空)--防止NULL值進入指定的列,在單列基礎上定義,預設情況下,ORACLE允許在任何列中有NULL值. CHECK (檢查)--檢查在約束中指定的條件是否得到了滿足. UNIQUE (唯一)--保證在指定的列

SELECT INTO 和 INSERT INTO SELECT 兩種表複製語句(SQL資料庫和Oracle資料庫的區別)

https://www.cnblogs.com/mq0036/p/4155136.html 我們經常會遇到需要表複製的情況,如將一個table1的資料的部分欄位複製到table2中,或者將整個table1複製到table2中,這時候我們就要使用SELECT INTO 和 INSER

java程式設計師菜鳥進階(二)oracle基礎(二)oracle查詢語句和資料排序

本文所以練習都是基於oracle自帶提供的一個數據庫進行的。資料庫中包含員工表emp。部門資訊表dept。員工工資工總表下面是三個表的表結構:一:基本查詢語句1.最簡單的查詢所有列語句Select * from emp;2.查詢指定列表的查詢語句Select empno ,e

oracle序列

pan 知識庫 引用 dpt 默認 數據 指定 sta ima 序列: 是oacle提供的用於產生一系列唯一數字的數據庫對象。 l 自動提供唯一的數值 l 共享對象 l 主要用於提供主鍵值 l 將序列值裝入內存可以提高訪問效率 創建序列: 1、 要有創建序列的權限

OracleOracle中NLS_LANG變量的使用

make fault tro territory font pin onclick 添加 其中 目錄結構: // contents structure [-] 關於NLS_LANG參數 NSL_LANG常用的值 在MS-DOS模式和Batch模式中

MySQL之SELECT 語句

限制 right ont 定義 過程 lar load avg sel 本文參考實驗樓的SELECT 語句詳解結合自己操作部分而寫成。 註意:大多數系統中,SQL語句都是不區分大小寫的,但是出於嚴謹和便於區分保留字和變量名,在書寫的時,保留字應大寫,而變量名應小寫。所謂的保

SQL update select結合語句及應用

應用 comm 執行 sel ron 詳解 strong 閱讀 等於 SQL update select結合語句詳解及應用 2013年10月1日 MK 數據庫 19 閱讀 157639次 QL update select語句 最常用的update語法是: 1 2

ORACLE觸發器

etc 遊標 target with get ger 獨立 erer mon 作者:indexman 觸發器是許多關系數據庫系統都提供的一項技術。在oracle系統裏,觸發器類似過程和函數,都有聲明,執行和異常處理過程的PL/SQL塊。 8.1 觸發器類型 觸

Python的 if .else.elif語句

python語句If 語句 是用來判斷的Python 編程中 if 語句用於控制程序執行 用來檢測一個條件:如果條件為 (真)true,就會運行這個語法塊,如果為Fales 就跳過不執行。 elif是依附於if存在的,兩者之間的運算邏輯相同,如果僅僅需要一次判斷,則僅用if就可以,如果需要多路判斷則在if後面

Oracle索引

png 匹配 時間 相同 空間 表示 單列 設置 ogg Oracle索引詳解(一) ### --索引介紹 ??索引對於Oracle學習來說,非常重要,在數據量巨大的狀況下,使用恰到好處的索引,將會使得數據查詢時間大大減少,於2017/12/25暫時對Oracle中的索引進

MySQL常用SQL語句之SHOW語句

disable ret gpl cati host write flush none mat SQL語句之SHOW語句 SHOW DATABASES – 顯示當前所有數據庫的名稱 mysql> SHOW DATABASES; SHOW TABLES – 顯示當前數

【shell】Linux shell if 語句

linux shell 運維 自動化運維 if語句 1.1 if語句解釋 if 是判斷語句,if語句的作用跟 [ ] 差不多,一般判斷比較多或者執行的語句比較多的話,那麽就會使用if 1.2 if 格式 第一種格式 if [ 判斷條件 ];then 內容 else 內容

PHP循環語句

循環語句循環結構 一、while循環 while(表達式) { 循環體;//反復執行,直到表達式為假 } 代碼: $index = 1; while ($index<5) { print "Number is {$index} "; $index++; } print "

MySQL用戶管理及SQL語句

shel row 不能 mode form lte entos 本體 lin 1.1 MySQL用戶管理 1.1.1 用戶的定義   用戶名+主機域 mysql> select user,host,password from mysql.user; +--

C#基礎之流程控制語句

集合 必須 清晰 循環 remove 很難 使用 fault code C#程序的執行都是一行接一行、自上而下地進行,不遺漏任何代碼。為了讓程序能按照開發者所設計的流程進行執行,必然需要進行條件判斷、循環和跳轉等過程,這就需要實現流程控制。C#中的流程控制包含了條件語句、循

1.1 MySQL用戶管理及SQL語句

3.1 match format cmake caf 物理 字符串類 float 都是 1.1 MySQL用戶管理 1.1.1 用戶的定義   用戶名+主機域 mysql> select user,host,password from mysql.use

[轉]MySQL-5.7 Update語句

表達式 nor lec tle cat dep keyword join author 原文地址:https://www.cnblogs.com/tongxiaoda/p/7908977.html .語法 (1)單表 UPDATE [LOW_PRIORITY] [IGNOR

git branch 常用語句

-a 遠程 git push gin 常用 --delete check 分支 常用語句 刪除遠程分支 git push origin --delete <branchName> 查看本地分支 git branch 創建本地新分支 git branch <

PLSQL Developer連線遠端Oracle配置

一、安裝Instant Client  1. 下載Instant Client(輕量級的客戶端),作為本地Oracle環境 。     https://download.csdn.net/download/qq_40110871/10747501 2.

MySQL(MariaDB)常用SQL語句

DDL(Data Definition Language)資料定義語言 這些語句定義了不同的資料段、 資料庫、表、列、索引等資料庫物件的定義。常用的語句關鍵字主要包括 create、drop、alter 等。 資料庫管理 --刪除資料庫 drop database if