oracle第二天学习内容
来源:互联网 发布:python 函数对象 编辑:程序博客网 时间:2024/04/30 14:50
Scott用户被锁定解决:
登陆sqlplus
Alter user scott account unlock;
修改自己密码
修改别人密码,请使用system或者sys用户
Show linesize;
Set linesize 100;
Show pagesize;
Show parameter instance_name;
创建用户:
Create user 用户名 identified by 密码;
权限分成两种:
1. 系统权限:
Create session,table,index,view,sequence
2. 对象权限:crud
角色
预定义角色
Dba,connect.resource
自定义角色
权限赋予:
Grant 权限/角色 to 用户;
Grant select/update/delete/insert/all on 表名 to 用户;
分配方案去给某个用户;
事务: transaction
Dml操作来说.(CUD), 操作的执行,commit;提交.
创建多个保存点
Savepoint 节点名称;
操作...
Rollback to 节点名称;
脏读:当一个事务读另外一个事务尚未提交的修改时,产生脏读,oracle不会出现脏读
如果事务能够读到另外一个事务尚未提交的修改,产生脏读
不可重复读:同一查询在同一书事务中多次进行。。由于其他事务提交所做的修改或删除。每次返回不同的结果集。
相同的两次查询产生不一致的结果
幻读:同一查询在同一事务中多次进行,由于其他事务所做的插入操作,每次返回不同的结果集,此时发生幻读。
表:
Dump(字段名)可以统计字符所占位数
数据类型
文本
Char
Varchar2
Nchar 使用unicode编码方式
Nvarchar2
Clob字符大对象
Blob二进制数据。图片
数字
Number(p,s) p表示有效位,s表示小数
日期
Oracle日期默认格式‘dd-mm-yyyy’
表管理:
Alert table 表名 add (列明 数据类型);
Alter table 表名 modify(雷鸣 数据类型)
Alter table 表名 drop column(列明)
Rename 表名 to 新明
Desc 表名 可以表述表的名称
Select abs(-100) from dual ; dual虚表
对于null值处理
Nvl(列明,0) 把列为空的取0;
||对列进行拼接
select *from emp where to_char(hiredate,'yyyy')='1980';
avg不会对为null的进行统计
select rownum from emp;
select t2.*from (select t1.*,rownum rn from (select* from emp) t1 where rownum<6) t2where rn>3
约束:
Not null
Unique
Primary key
Foreign key
Check
Oracle 中制定外键
Name varchar2(20) references 表名(列明)
Age number check (age>0 and age<100)
Sex char(2) check(sex in(‘男’,’女’));
Alter table 表名 modify 字段名 not null;
Alter table 表名 add constraint 约束名 约束种类(字段);
Alter table 表名 drop constraint 约束名称;
Alter table 表名 drop primary keycascade;
序列:
Create sequence myseq
Start with 1
Increment by 1
Minvalue 1
Maxvalue 30000
Cycle //表示到30000以后。从1重新开始
Nocache
;
Cache 10表示一次产生10个使用
Insert 时使用序列名.nextval获取下一个值
Currval表示当前索引值
第一次nextval后才能使用currval
Create index index_name on 表名(列明);
savepoint aa;
delete from emp;
rollback to aa;
create procedure pro1 is
begin
insert into emp(empno,ename) values (13,'123');
end;
/
exec pro1;
create procedure pro2(in_empno number) is
begin
delete from emp where empno=in_empno;
end;
/
declare
/*¶¨Ò岿·Ö°üÀ¨±äÁ¿³¨ÁÁÓαê*/
begin
/*Ö´Ðв¿·Ö*/
exception
/*ÀýÍⲿ·Ö*/
end;
begin
dbms_output.put_line('hello world');
end;
/
--set serveroutput on; ´ò¿ªÊä³ö
declare
v_ename varchar2(20);
begin
select ename into v_ename from emp whereempno=&eno;
dbms_output.put_line('hello' || v_ename);
end;
/
--½«ÉÏÃæµÄ¿é¸Ä³É´æ´¢¹ý³Ì£¬¼ÇµÃɾ³ýdeclare
create procedure pro3 is
v_ename varchar2(20);
begin
select ename into v_ename from emp whereempno=&in_empno;
dbms_output.put_line('hello' || v_ename);
end;
/
create procedure pro4(in_empno number) is
v_ename varchar2(20);
begin
select ename into v_ename from emp whereempno=in_empno;
dbms_output.put_line('hello' || v_ename);
end;
/
declare
v_ename varchar2(20);
begin
select ename into v_ename from emp whereempno=&eno;
dbms_output.put_line('hello' || v_ename);
exception
when no_data_found then
dbms_output.put_line('no data');
end;
/
create procedure procedure_name(v_name in v_type...v_nameoutv_type) is
--¶¨Òå±äÁ¿
begin
procedure;
end;
/
create or replace procedure pro5(in_emp in number,in_salin number)is
begin
update emp setsal=in_sal where empno=in_emp;
end;
/
show error;
commit; µ÷ÓÃʱÅöµ½execute·½·¨²»Ö´ÐУ¬µÈ´ý
create or replace procedure pro6(in_emp in number,in_salout number)is
begin
select sal into in_salfrom emp where empno=in_emp;
end;
/
- oracle第二天学习内容
- oracle学习第二天
- Oracle学习第二天
- Oracle 学习第二天
- oracle数据库学习第二天
- 第二周学习内容
- oracle学习第二天(函数,CURD)
- Oracle 学习DBA的日常工作 第二天
- ORACLE的学习笔记第二天----3.30
- 玩转oracle学习第二天
- 笔记:ORACLE数据库基础学习 第二天
- 第二周oracle学习
- Oracle学习第二记
- HTML---第二天内容
- OA的学习--第二天的内容--日志和BaseDao
- Java Web 初级程序员 : 第二天学习内容
- oracle再学习内容
- 《C程序设计语言》书籍内容学习第二弹
- css中辅助类和响应式工具所有测试方法案例
- 关于HashMap和TreeMap的一些注意点
- Android UI开发: 横向ListView(HorizontalListView)及一个简单相册的完整实现 (附源码下载)
- 深入浅出ClassLoader
- 【题解】Leetcode.241.Different Ways to Add Parentheses
- oracle第二天学习内容
- js进阶学习之--面向对象(一)
- 网易测编程试题-CD收录歌曲计算
- scala进阶1-泛型
- 1602显示屏的使用
- el表达式跟ognl表达式的区别
- android之存储篇_SQLite数据库_让你彻底学会SQLite的使用
- Hibernate映射类型、Java类型、标准SQL类型、Hibernate对象类型
- [Latex学习笔记]数学公式基本命令