2. 支持DDL语句的审计,数据库表创建表、删除表、修改表结构(DDL)
1)创建表:
create table student
(
stuid varchar2(11) not null,--学号:'S'+班号(7位数)+学生序号(3位数)(1)
stuname varchar2(50) not null,--学生姓名
sex char(20) not null,--性别
age number(20) not null,--年龄
classno varchar2(20) not null,--班号:'C'+年级(4位数)+班级序号(2位数)
idnumber varchar2(20) default '身份证未采集' not null--身份证
)
2)查看表定义:
待补充
3)增加表字段:
alter table student add (address varchar(20) default '');
5)字段改名:
alter table student rename column address to stu_address;
alter table tb_AW modify (name varchar(30) default '');
6)删除字段:
alter table student drop column stu_address;
4)删除表:
drop table Student;
5)清空表:
create TABLE tb_AW(
name varchar(10),
sex varchar(30)
);
insert into tb_AW values('Joe','男');
insert into tb_AW values('周欣红','女');
select * from tb_AW;
truncate table tb_AW;
3. 支持DCL语句的审计,授予、解除用户访问权限、拒绝用户访问(DCL)
1)添加用户并设置密码:
create user liujd identified by 123
2)查询用户:
select * from dba_sys_privs where grantee='liujd';
3)授予权限:
grant create table to liujd
4)修改用户密码:
alter user liujd identified by 123456
5)收回权限:
revoke create table from liujd
6)删除用户:
DROP USER liujd CASCADE;
4. 支持DML语句的审计,检索、更新数据、添加行、删除行(DML)
1)添加:
insert into Student values('01' , '赵雷' , '男' , '22' , '11' , '41130319970513680X');
insert into Student values('02' , '钱电' , '男' , '23' , '21' , '41130319980513680X');
insert into Student values('03' , '孙风' , '男' , '24' , '31' , '41130319990513680X');
2)修改表数据:
update Student set stuname = '周生玉' where stuid = '01'
3)查找表数据:
SELECT * from Student
4)条件查询
select stuname 姓名 from Student;
select * from Student where stuname = '周生玉';
select * from Student where stuname like '%生%';
select * from Student where classno between 10 and 20
select * from Student where stuname in('周生玉','孙风');
select u.classno,u.stuname from Student u order by u.classno desc;
5)删除表数据:
delete from Student where stuname = '周生'
5. 支持数据库存储过程审计
1)新建存储过程:
create or replace procedure TEST_COUNT04(v_id in int,v_name out varchar2)
is
BEGIN
SELECT stuname into v_name from student where stuid = v_id;
dbms_output.put_line(v_name);
commit;
END;
2)调用:
DECLARE
v_name varchar(200);
BEGIN
TEST_COUNT04('01',v_name);
END;
3)查看存储过程
SELECT text
FROM user_source
WHERE NAME = 'TEST_COUNT04'
ORDER BY line;
3)删除:
drop procedure TEST_COUNT04
6. 函数:
1)创建函数:
create or replace FUNCTION func_student1(v_id in varchar2)
RETURN varchar2
is
name varchar2(100);
BEGIN
SELECT stuname into name from student where stuid = v_id;
RETURN name;
END func_student1;
2)调用:
select func_student1('01') from dual;
3)删除:
DROP FUNCTION func_student1;
7. 视图:
1)创建视图:
CREATE OR REPLACE VIEW stutest
AS
SELECT * FROM student
WITH READ ONLY
2)调用视图:
SELECT * FROM stutest;
3)查看视图:
select * from user_views t
4)删除视图:
DROP VIEW stutest
8. 索引:
1)创建索引:
CREATE UNIQUE INDEX UQ_ENAME_IDX ON Student(stuid);
2)查看索引:
select * from user_indexes where table_name=upper('student');
select * from user_ind_columns where index_name=('UQ_ENAME_IDX');
select dbms_metadata.get_ddl('INDEX','UQ_ENAME_IDX') from dual
3)删除索引:
drop index UQ_ENAME_IDX;
9. 事务:未执行commit之前,数据不会添加,执行之后会进行添加;SELECT * FROM zyh0816.score;验证是否添加数据
1)提交事务:
BEGIN
UPDATE student SET age = age+100 where stuid = 02;
COMMIT;
END;
2)回滚事务:
BEGIN
UPDATE student SET age = age+100 where stuid = 02;
ROLLBACK;
END;
3)使用savepoint部分回滚
savepoint-oracle.txt
10. 超长SQL语句审计:
超长sql语句-oracle.txt
11. 中文乱码审计:
create table student4
(
stuid varchar2(11) not null,--学号:'S'+班号(7位数)+学生序号(3位数)(1)
stuname varchar2(50) not null,--学生姓名
sex char(20) not null,--性别
age number(3) not null,--年龄
classno varchar2(20) not null,--班号:'C'+年级(4位数)+班级序号(2位数)
idnumber varchar2(20) default '身份证未采集' not null--身份证
)
insert into student4 values('01' , '赵雷' , '男' , '22' , '11' , '41130319970513680X');
insert into student4 values('02' , '钱电' , '男' , '23' , '21' , '41130319980513680X');
12. 报表特权操作补充:
1)创建角色:
create role testRole;
2)授权角色:
grant select on student4 to testRole;
3)删除角色:
drop role testRole;