alter table tbname drop(ziduan) 删除
alter table tbname modify(ziduan varchar2(100)) 修改 字段类型容量不能改小
59.去掉约束
alter table tbname drop constraint yueshuname;
60.添加约束
alter table tbname add constraint yueshuname foreign key (class) references class (id);
61.删除表
delete from tbname;
62.oracle默认的一个表user_tables 装的当前用户下有多少表,(数字字典表)
select table_name from user_tables
63.oracle有多少个数字字典表都放在表 dictionary 中
select table_name from dictionary;
64.索引 index
create index syname on tbname(ziduan1,ziduan2);
65.删除索引
drop index syname;
66.序列 oracle独特的 自动递增
create sequence sename;
drop sequence sename;删粗序列
select sename.nextval from dual;查询的结果会递增
67.三范式
不存在冗余数据
第一范式要求:要有主键,列不可分
第二范式要求:不能存在部分依赖 (分割为n张表)
第三范式要求:属性不能依赖其它属性
68.PL_SQL 语言 斜杠/执行
set serveroutput on;
begin
dbms_output.put_line('HelloWorld');
end;
69.PL_SQL 语言 declare 声明变量 以v_开头
declare
v_name varchar(20);
begin
v_name := 'myname'; := 赋值符号
dbms_output.put_line(v_name);
end;
/
69.PL_SQL 语言 异常
declare
v_num number := 0;
begin
v_num := 2/v_num;
dbms_output.put_line(v_num);
exception
when others then
dbms_output.put_line('error');
end;
70.PL_SQL 语言 常用变量的类型
binary_integer: 整数,主要用来计数而不是用来表示字段类型
number:数字类型
char: 定长字符串
varchar2: 变长字符串
date: 日期
long: 长字符串,最长2GB
boolean: 布尔类型,可以取值为 true、false和null值,默认null
71.PL_SQL 语言 constant
相当于java中的 fianl;
72.PL_SQL 语言 -- 单行注释
73.PL_SQL 语言 %type 属性
v_empno emp.empno%type; 变量v_empno的类型随表emp中字段empno的类型变化而变化
SpringMVC+mybatis HTML5 全新高大尚后台框架_集成代码生成器
74.Table变量类型 相当于java中的数组,type表示定义了一种新的数据类型
declare
type type_table_emp_emono is table of emp.empno%type index by binary_integrt;
v_empnos type_table_emp_empno;
begin
v_empnos(0) := 7369;
v_empnos(2) := 7339;
v_empnos(-1) := 9999;
dbms_output.put_line(v_empnos(-1));
end;
75.Record变量类型 相当于java中的类
declare
type type_recors_dept is record
(
dname dept.dname%type,
loc dept.loc%type
);
v_temp type_record_dept;
begin
v_temp.deptno := 50;
v_temp.dname := 'aaaa';
v_temp.loc := 'bj';
dbms_output.put_line(v_temp.deptno || ' ' || v_temp.dname);
end;
76.使用%rowtype声明record变量
declare
v_temp dept%rowtype;
begin
v_temp.deptno := 50;
v_temp.dname := 'aaaa';
v_temp.loc := 'bj';
dbms_output.put_line(v_temp.deptno || ' ' || v_temp.dname);
end;
77.PL_SQL语句的运用,select语句中必须有关键字into,并且只有一条数据
declare
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
select ename.sal into v_ename.v_sal from emp where empno = 7369;
dbms_output.put_line(v_ename || ' ' || v_sal);
end;
同上
declare
v_emp emp%rowtype;
begin
select * into v_emp from emp where empno = 7369;
dbms_output.put_line(v_emp.ename || ' ' || v_emp.sal);
end;
87.PL_SQL语句的运用 insert
declare
v_deptno dept.deptno%type := 50;
v_dname dept.dname%type := 'aaaa';
v_loc dept.loc%type := 'bj';
begin
insert into dept2 values (v_deptno, v_dname, v_loc);
commit;
end;
88.PL_SQL语句的运用
dbms_output.put_line(sql%rowcount || '条记录被影响')
89,PL_SQL语句的运 ddl语句在PL_SQL语句中前加 excute immediate
begin
execute immediate 'create table tbname (nnn varchar2(20) default ''aaa'')';
90.PL_SQL语句 if语句 取出7369的薪水,如果<1200,则输出'low',如果<2000则输出'middle',否则输出'high'
declare
v_sal emp.sal%type;
begin
select sal into v_sal from emp where empno = 7369;
if (v_sal < 1200) then
dbms_output.put_line('low');
elsif (v_sal < 2000) then
dbms_output.put_line('middle');
else
dbms_output.put_line('high');
end if;
end;
91.PL_SQL语句 循环语句
declare
i binary_integer := 1;
begin
loop
dbms_output.put_line(i)
i := i + 1;
exit when (i >= 11);
end loop;
end;
declare
j binary_integer := 1;
begin
where j < 11 loop
dbms_output.