數(shù)據(jù)庫(kù)編程總概括
- SQL是執(zhí)行語(yǔ)句,沒(méi)有什么語(yǔ)法只是執(zhí)行方法
- PL/SQL是語(yǔ)言,對(duì)SQL的編程規(guī)范總結(jié),形成語(yǔ)法,方法和對(duì)象
SQL學(xué)習(xí)知識(shí)概要
- select
- select ? from ? join on ? where ? group by ? having ? order by ?
- select ? from (select ? from ? order by ? ) where rownum <6
- select ? from (select ?,rownum row_id from (select ? from ? order by ?) order by ? ) where row_id bewteen 6 and 10
- DML
- insert into ? values(?,?,?)
- delete from ? where ?
- update ? set ? = ?
- DDL
- create table ?
- drop table ?
- TCL
- commit
- rollback
- DCL
- grant
PL/SQL學(xué)習(xí)知識(shí)概要
定義變量結(jié)構(gòu)
- ? 【constant】number 【not null】【:=?】
變量類型
- 標(biāo)量類型
- 組合類型
RECORD
TABLE
CURSOR- 引用類型
- 大類型
基本語(yǔ)法結(jié)構(gòu)
- 語(yǔ)法結(jié)構(gòu)
declare
??
begin
??
exception
??
end;- 打印
dbms_out_put.putline('Hello,World');- 執(zhí)行
/
對(duì)SQL語(yǔ)句的使用
- select into
- 單個(gè)
- RECORD
- TABLE
- CURSOR
- DML
- TCL
- DDL
- ddl的動(dòng)態(tài)SQL
- using的動(dòng)態(tài)SQL
PL/SQL匿名函數(shù)(存儲(chǔ)函數(shù))
- 語(yǔ)法格式
create or replace procedure ?(?,?)
is
begin
??
end;- 查看過(guò)程
desc ?- 調(diào)用(無(wú)參)
call ?- 調(diào)用(有參,out)
declare
??
begin
?(?)
exception
??
end;
PL/SQL匿名函數(shù)(存儲(chǔ)函數(shù))
- 語(yǔ)法格式
create or replace function ?(?,?)
return ?
is
begin
return ?
end;- 刪除函數(shù)
drop function ?- 調(diào)用函數(shù)
- 語(yǔ)法結(jié)構(gòu)
declare
??
begin
dbms_out_put.put_line(?(?,?));
end;
創(chuàng)建數(shù)據(jù)庫(kù)
? create database 數(shù)據(jù)庫(kù)名[charset:字符編碼集]
? create database 數(shù)據(jù)庫(kù)名
? create database if not exites 數(shù)據(jù)庫(kù)名[charset:字符編碼集]
查看數(shù)據(jù)庫(kù)
? show databases
查看數(shù)據(jù)庫(kù)的創(chuàng)建SQL語(yǔ)句
? show create database 數(shù)據(jù)庫(kù)名
更新數(shù)據(jù)庫(kù)
? alter database 數(shù)據(jù)庫(kù)名 charset-字符編碼集
刪除數(shù)據(jù)庫(kù)
? drop database 數(shù)據(jù)庫(kù)名
? drop database if exites 數(shù)據(jù)庫(kù)名
使用數(shù)據(jù)庫(kù)
? use 數(shù)據(jù)庫(kù)名
數(shù)據(jù)庫(kù)的操作
創(chuàng)建表
? create table 表名(
? name varchar(10) not null,
? sex char(1) not null,
? id int auto_increment primary key,
? id varchar(40) default '地址不詳',
? score decimal(3,1)
? )
查看表
? show tables;
查看表的創(chuàng)建SQL語(yǔ)句
? show create table 表名 \G;
查看表結(jié)構(gòu)
? describe 表名;
刪除表
? drop table 表名;
如果數(shù)據(jù)庫(kù)不支持中文的編碼
? 刪除不支持的表
? 重新創(chuàng)建設(shè)置編碼集
數(shù)據(jù)的操作
插入數(shù)據(jù)
? insert into 表名 values (a,b,c);
? 自動(dòng)增長(zhǎng)可以寫null
? 默認(rèn)值可以寫default
修改數(shù)據(jù)
? update 表名 set 字段:值 where條件
刪除數(shù)據(jù)
? delete from 表名 where條件
查詢數(shù)據(jù)
? 分頁(yè)查詢:select * from emp limit(3,2);