oracle日常操作

1、把本机Oracle用户sys、system密码全部改为oracle;
2、创建一个本地管理的表空间TS_ESTORE,并指定区(extent)大小为128K,文件的初始大小为1M,自动扩展,每次扩展为500k。
3、创建一个用户estore,设定密码为estore,默认表空间为TS_ESTORE。
4、为用户eStore设定下列权限:
ü 连接数据库
ü 创建和执行PL/SQL程序
ü 可以创建、修改、删除任意表
ü 可以创建、删除任意视图
5、用ESTORE用户登录数据库,创建用户信息表usersü 用户ID(自增长数值型、主键)--创建一个S_USERS序列,该值从序列中获得
ü 用户名称(字符型,30位)
ü 用户密码(字符型,8位)
ü 联系地址(字符型,80位)
ü EMAIL(邮件,60位)
ü 创建日期(日期型,默认为当前日期)
6、用下列信息初始化该用户信息表users:
ü 张三,zhang3,师大,[email protected]
ü 李四,li4,师大,[email protected]
ü 王五,wang5,师大,[email protected]
7、编写一个显式游标,分别用WHILE、LOOP循环将用户信息表users中的所有记录在控制台打印出来。
8、使用FOR 语句的隐式游标实现第7题的功能。(提示:直接在FOR语句的IN中编写SQL语句)。
9、编写一个存储过程P_Login,根据输入参数userId,password实现以下逻辑:
ü 判断用户信息表USERS中userID=输入的userId参数的用户是否存在(提示:用select count(1) into 变量,来判断。)
ü 如果用户不存在,在控制台打印出:用户不存在
ü 判断用户信息表中,password是否正确
ü 如果不正确在控制台中打印出:用户密码错误
要求:需要用EXCEPTION处理异常信息。
10、 创建一个表:USER_LOG,包含以下字段:
ü 操作描述(提示:指insert、delete或update)
ü 用户ID
ü 旧的用户名称(字符型,30位)
ü 新的用户名称(字符型,30位)
ü 更新时间(date型)
编写一个行级触发器,记录对学生信息表的所有更新操作(insert、delete、update),并将更时间、学生姓名、学生ID记录到USER_LOG表中。
ㄗs晨星oО  15:07:23
上面是问题
ㄗs晨星oО  15:07:42
1.---
alter user sys identified by orcale;
alter user system identified by orcale;

2.---
create tablespace TS_ESTORE
datafile 'filespec' size 1M
autoextend on next 500K
extent management local uniform size 128k;

3.---
create user estore identified by estore
default tablespace TS_ESTORE;

4.---
grant connect,RESOURCE 8 privs,create any table,alter any table,delete any table,
create any view,delete any view to eStore;
--RESOURCE 8 privs 具有程序开发最的权限 (??)

5.---
connect estore/estore

create table users (
id number not null primary key,
username varchar2(30),
userpass varchar2(8),
useraddr varchar2(80),
useremail varchar2(60),
created date default sysdate);

create sequence S_USERS start with 1 increment by 1;

create or replace triggrt users_id_trigger
before insert on users for each now
declare
next_no number;
begin
select S_USERS.nextval into next_no from dual;
:new.id :=next_no;
end;

6.---
insert into users (username,userpass,useraddr,useremail) values ("张三","zhang3","师大","[email protected]");
insert into users (username,userpass,useraddr,useremail) values ("李四","li4","师大","[email protected]");
insert into users (username,userpass,useraddr,useremail) values ("王五","wang5","师大","[email protected]");

7.---
set serveroutput on

declare
uid users.id%type;
uname users.username%type;
upass users.userpass%type;
uaddr users.useraddr%type;
umail users.useremail%type;
ucreatedtime users.created%type;
cursor mycur is select * from users;
begin

open mycur;
fetch mycur into uid,uname,upass,uaddr,umail,ucreatedtime;
dbms_output.put_line("loop循环输出:");
loop
dbms_output.put_line(uid||" "||uname||" "||upass||" "||uaddr||" "||umail||" "||ucreatedtime);
exit when mycur%notfound;
end loop;
close mycur;

open mycur;
fetch mycur into uid,uname,upass,uaddr,umail,ucreatedtime;
dbms_output.put_line("while循环输出:");
while mycur%found loop
dbms_output.put_line(uid||" "||uname||" "||upass||" "||uaddr||" "||umail||" "||ucreatedtime);
end loop;
close mycur;

end;

8.---
set serveroutput on

declare
begin
dbms_output.put_line("for语句隐式游标循环输出:");
for my_record in (select * from users) loop
dbms_output.put_line(my_record.uid||" "||my_record.uname||" "||my_record.upass||" "||my_record.uaddr||"

"||my_record.umail||" "||my_record.ucreatedtime);
end loop;
end;

9.---
set serveroutput on

create or replace P_Login (userId in users.id%type,password in users.userpass%type)
as
user_count number;
user_not_exist exception;
user_pass_error exception;
begin
select count(1) into user_count from users where id = userId;
if user_count = 0 then raise user_not_exist;
elsif user_count<>0 then
select count(1) into user_count from users where id = userId and userpass = password;
if user_count = 0 then raise user_pass_error;
elsif user_count <> 0 then
dbms_output.put_line("用户名密码正确!!");
endif;
endif;
exception
when user_not_exist then dbms_output.put_line("用户不存在");
when user_pass_error then dbms_output.put_line("用户密码错误");
end;

10.---
create table USER_LOG
(op varchar2(10),
id number,
oldid number,
newid number
updatedtime date);

create sequence S_USER_LOG start with 1 increment by 1;

create or replace triggrt users_op_trigger
after insert or update or delete on users
for each now
begin
if inserting then
insert into USER_LOG values ("insert",S_USER_LOG.nextval,old.id,new.id,sysdate);
elsif updating then
insert into USER_LOG values ("update",S_USER_LOG.nextval,old.id,new.id,sysdate);
elsif deleting then
insert into USER_LOG values ("delete",S_USER_LOG.nextval,old.id,old.id,sysdate);
endif;
end;

你可能感兴趣的:(oracle日常操作)