数据库编程总概括
- SQL是执行语句,没有什么语法只是执行方法
- PL/SQL是语言,对SQL的编程规范总结,形成语法,方法和对象
SQL学习知识概要
- 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学习知识概要
定义变量结构
- ▨ 【constant】number 【not null】【:=▨】
变量类型
- 标量类型
- 组合类型
RECORD
TABLE
CURSOR- 引用类型
- 大类型
基本语法结构
- 语法结构
declare
▨▨
begin
▨▨
exception
▨▨
end;- 打印
dbms_out_put.putline('Hello,World');- 执行
/
对SQL语句的使用
- select into
- 单个
- RECORD
- TABLE
- CURSOR
- DML
- TCL
- DDL
- ddl的动态SQL
- using的动态SQL
PL/SQL匿名函数(存储函数)
- 语法格式
create or replace procedure ▨(▨,▨)
is
begin
▨▨
end;- 查看过程
desc ▨- 调用(无参)
call ▨- 调用(有参,out)
declare
▨▨
begin
▨(▨)
exception
▨▨
end;
PL/SQL匿名函数(存储函数)
- 语法格式
create or replace function ▨(▨,▨)
return ▨
is
begin
return ▨
end;- 删除函数
drop function ▨- 调用函数
- 语法结构
declare
▨▨
begin
dbms_out_put.put_line(▨(▨,▨));
end;
创建数据库
⦁ create database 数据库名[charset:字符编码集]
⦁ create database 数据库名
⦁ create database if not exites 数据库名[charset:字符编码集]
查看数据库
⦁ show databases
查看数据库的创建SQL语句
⦁ show create database 数据库名
更新数据库
⦁ alter database 数据库名 charset-字符编码集
删除数据库
⦁ drop database 数据库名
⦁ drop database if exites 数据库名
使用数据库
⦁ use 数据库名
数据库的操作
创建表
⦁ 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;
查看表的创建SQL语句
⦁ show create table 表名 \G;
查看表结构
⦁ describe 表名;
删除表
⦁ drop table 表名;
如果数据库不支持中文的编码
⦁ 删除不支持的表
⦁ 重新创建设置编码集
数据的操作
插入数据
⦁ insert into 表名 values (a,b,c);
⦁ 自动增长可以写null
⦁ 默认值可以写default
修改数据
⦁ update 表名 set 字段:值 where条件
删除数据
⦁ delete from 表名 where条件
查询数据
⦁ 分页查询:select * from emp limit(3,2);