欢迎光临散文网 会员登陆 & 注册

Oracle创建或查看或删除用户,DBA,rownum伪列进行分页,增删改查语句等【诗书画唱】

2021-03-03 23:53 作者:诗书画唱  | 我要投稿

前言:每次写这种技术专栏都要花很多小时且累,所以没时间做高创的视频,同时阅读量和点赞或慷慨三连的人很少。但是学习为主嘛!学好一些东西后,创作更多更高创的作品给你们!

点赞或慷慨三连吧!

下面我是用DBA管理员创建表的,如果用sccot的账号创建表前,可能要先给权限:


--登录sys超级管理员账号执行

--创建一个名为SSHC的账户

create user SSHC

--设置密码为1

identified by orcl

--设置默认表空间为user

default tablespace users

--设置临时表空间为temp

temporary tablespace temp

--解锁账号,允许登录oracle

account unlock;


--允许SSHC用户登录到orcl数据库

grant connect to SSHC;

--允许SSHC用户使用存储空间

grant resource to SSHC;




内容概括:

作业
讲义

创建用户的步骤

oracle中的常用的数据类型

lob:存储视频和音频以及大文件,存放大文件

number(10,2)



oracle数据库中的伪列:

rowid:当需要对数据库中的数据进行编辑时,就必须显示rowid

rownum:使用rownum进行分页查询


mysql:limit进行分页

oracle:rownum伪列进行分页


以你的名字首字母为账号创建一个账号,密码自定(授予他dba的权限)【DBA(数据库管理员) DBA是数据库管理员认证,英文是Database Administrator。 】

oracle登录身份有三种: 1、normal 普通身份; 2、sysdba 系统管理员身份; 3、sysoper 系统操作员身份。


创建一个商品信息表(id,name,price,type)和商品类型表(id,name)

--查看用户或角色所拥有的角色:

select * from dba_role_privs;

Oracle中常用的部分语句个人总结

查看Oracle中所有用户或角色的权限等等

PLSQL设置编辑器的字体大小的方法 

oracle 删除用户命令和部分命令

查看Oracle中所有用户的方法

关于甲骨文公司的扩展知识

在商品信息表和商品类型表中输入数据进行测试。

关于外键的添加 



关于外键的添加 START


【外键的话,是保存副表的内容的完整性的。比如副表(我理解我为补充表)

比如类型表,如果是组合查询时的下拉框的话,就是查询类型表。使用了

外键把主表的信息表和类型表联系起来后,就是

主表的typeid的数值中只会出现副表中出现的加了主键的编号id列

<int类型,有主键>出现的数值,添加数据到信息表的时候,

有一列typeid<int类型,无主键>,

防止操作员添加了无type表的id值到typeid列中,那么就是无效的数据,

加了外键后,这种无效的数据是添加不到信息表里的。)】





【直接创建完整约束的表(写项目的时候,一般就是用这种方法建表。

同时建表的时候,一般用管理员的身份创建表的时候,不用授权,但是

普通用户要。这是为了安全,2个不同的公司,互相合作时,交互时授权后

才能访问更安全)】



create table spInformation 


(


id number primary key,


name varchar2(30),


price number(9,2),


typeid int


);


create table spType


(id number primary key,


name varchar2(30));



--删除表

drop table spInformation;

drop table spType;


--加外键

【表创建成功后再添加外键约束

添加外检约束 :alter table 从表表名 add constraint 

外键约束名称 foreign key(列名) references 主表名称(主键列名)】

alter table spInformation add constraint

 FK_spInformation foreign key(typeid) references spType(id);

——————————————————————————————————————————————————————


---建基本的表(一般是不会去用这种方法建表的):


create table spInformation 


(


id number,


name varchar2(30),


price number(9,2),


type varchar2(30)


);


create table spType


(id number primary key,


name varchar2(30));


--查询表


select * from spInformation; 


select * from spType; 




--通过sql语句给商品信息表的id添加主键约束

alter table spInformation 

add constraint PK_id primary key(id);

--name添加唯一约束

ALTER TABLE spInformation

ADD CONSTRAINT unique_spInformation

UNIQUE (name) 

--id添加外键约束

【表创建成功后再添加外键约束

添加外检约束 :alter table 从表表名 add constraint 

外键约束名称 foreign key(列名) references 主表名称(主键列名)】

alter table spType add constraint

 FK_spInformation foreign key(id) references spInformation(id);

--价格添加检查约束(1-99999999元)

Alter table spInformation

Add constraint CK_spInformation check(99999999>price and price>=1)

--在商品信息表和商品类型表中输入数据进行测试。

insert into spInformation values(1,'诗书画唱牌商品',999.99,'名牌类');


insert into spType values(1,'名牌类');

--select * from user_tablespaces ;

--select * from user_tablespaces ;










关于外键的添加 END



讲义 START


PLSQL:漂亮SQL,oracle图形化的管理界面


使用oracle数据库:

打开后台服务界面,打开Oracle服务项

打开PLSQL,登录数据库


放大字体:工具-首选项-从左边选中“字体”选项-调整字体大小

切换账号:会话-登录-重新输入账号密码进行登录

mysql:默认账号root

sqlserver:默认账号sa

oracle:默认账号scott,超级管理员账号sys,system,密码orcl


oracle数据库中的权限管理非常严格。


oracle中写sql语句:文件-新建-SQL WINDOW


创建用户的步骤

1、使用超级管理员登录

2、执行创建用户的sql语句


oracle中的常用的数据类型:

varchar2:可变长度字符串类型

char:固定长度字符串类型

number:数值类型

date:日期类型

lob:存储视频和音频以及大文件,存放大文件

number(10,2)


oracle数据库中的伪列:

rowid:当需要对数据库中的数据进行编辑时,就必须显示rowid

rownum:使用rownum进行分页查询


mysql:limit进行分页

oracle:rownum伪列进行分页



讲义 END



作业 START

1、以你的名字首字母为账号创建一个账号,密码自定(授予他dba的权限)【DBA(数据库管理员) DBA是数据库管理员认证,英文是Database Administrator。 】

oracle登录身份有三种: 1、normal 普通身份; 2、sysdba 系统管理员身份; 3、sysoper 系统操作员身份。


首先想创建一个新用户,一般用SYSDBA的类型的权限的用户

之后点“新建”,“SQL Windows”。







以你的名字首字母为账号创建一个账号,密码自定(授予他dba的权限) START



create user X identified by sshcPwd;


grant connect,resource,dba to X;



以你的名字首字母为账号创建一个账号,密码自定(授予他dba的权限) END


--查看数据库里面所有用户:


select * from dba_users;




--用户及用户下面所有表的删除:


drop user   X cascade;


--查看用户或角色所拥有的角色或权限:

select * from dba_role_privs;

创建管理员X成功!




2、创建一个商品信息表(id,name,price,type)和商品类型表(id,name)



create table spInformation 


(


id number,


name varchar2(30),


price number(9,2),


type varchar2(30)


);






create table spType


(


id number,


name varchar2(30)


);


--查看用户或角色所拥有的角色:

select * from dba_role_privs;

--查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)

select * from V$PWFILE_USERS


--创建一个商品信息表(id,name,price,type)和商品类型表(id,name)


create table spInformation 

(

id number primary key,

name varchar2(30),

price number(9,2),

type varchar2(30)

)



create table spType

(

id number primary key,

name varchar2(30)

)


--查询表

select * from spInformation; 

select * from spType; 

--笛卡尔积:将多个表的数据进行一一对应,所得的结果为多表的笛卡尔积

select * from spInformation,spType;

--多表查询

select * from spInformation,spType where spInformation.name=spType.name


--删除表

drop table spInformation


--number型的相关知识 


oracle中不管什么数字(正常数字,不包括0000001这样的),都可以用number来存,

只是后面的参数略有不同,你说的小数,可以用number(n,2)来保存就可以了。


还是number型。

参考以下定义:

number ( precision, scale)

    precision表示数字中的有效位。如果没有指定precision的话,oracle将使用38作为精度。

    scale表示数字小数点右边的位数,scale默认设置为0.  如果把scale设成负数,

    oracle将把该数字取舍到小数点左边的指定位数。

--查看用户或角色所拥有的角色:

select * from dba_role_privs;

--查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)

select * from V$PWFILE_USERS


--创建一个商品信息表(id,name,price,type)和商品类型表(id,name)


create table spInformation 

(

id number,

name varchar2(30),

price number(9,2),

type varchar2(30)

);



create table spType

(

id number,

name varchar2(30)

);



--通过sql语句给商品信息表的id添加主键约束,name添加唯一约束,

--type添加外键约束,价格添加检查约束(1-99999999元)

alter table spInformation 

add constraint PK_id primary key(id); 




--查询表

select * from spInformation; 

select * from spType; 

--笛卡尔积:将多个表的数据进行一一对应,所得的结果为多表的笛卡尔积

select * from spInformation,spType;

--多表查询

select * from spInformation,spType where spInformation.name=spType.name


--删除表

drop table spInformation;

drop table spType;

--number型的相关知识 


oracle中不管什么数字(正常数字,不包括0000001这样的),都可以用number来存,

只是后面的参数略有不同,你说的小数,可以用number(n,2)来保存就可以了。


还是number型。

参考以下定义:

number ( precision, scale)

    precision表示数字中的有效位。如果没有指定precision的话,oracle将使用38作为精度。

    scale表示数字小数点右边的位数,scale默认设置为0.  如果把scale设成负数,

    oracle将把该数字取舍到小数点左边的指定位数。

    

    

    --表创建后,添加主键约束 

语法: 

alter table 表名 

add constraint 主键名称(一般主键名称为”PK_”开头) primary key(要设为主键的列名); 

例: 

alter table T_Grade 

add constraint pk_gradeId primary key (gradeId);





3、通过sql语句给商品信息表的id添加主键约束,name添加唯一约束,type添加外键约束,价格添加检查约束(1-99999999元)


--通过sql语句给商品信息表的id添加主键约束


alter table spInformation 


add constraint PK_id primary key(id);




--name添加唯一约束

ALTER TABLE spInformation

ADD CONSTRAINT unique_spInformation

UNIQUE (name) 

--id添加外键约束


【表创建成功后再添加外键约束


添加外检约束 :alter table 从表表名 add constraint 

外键约束名称 foreign key(列名) references 主表名称(主键列名)】



alter table spType add constraint

 FK_spInformation foreign key(id) references spInformation(id);


--价格添加检查约束(1-99999999元)


Alter table spInformation

Add constraint CK_spInformation check(99999999>price and price>=1)



4、在商品信息表和商品类型表中输入数据进行测试。


--在商品信息表和商品类型表中输入数据进行测试。


insert into spInformation values(1,'诗书画唱牌商品',999.99,'名牌类');


insert into spType values(1,'名牌类');





作业 END


关于甲骨文公司的扩展知识 START

https://wenwen.sogou.com/z/q829455879.htm

关于甲骨文公司的扩展知识 END



查看Oracle中所有用户的方法 START

https://zhidao.baidu.com/question/432789002177092324



方法如下:


输入select * from dba_users; 即可。


常用语句:


一,查看数据库里面bai所有用户:


select * from dba_users; 

前提是你是有dba权限的帐号,如sys,system。


二,查看你能管理的所有用户:


select * from all_users;  


三,查看当前用户信息 :


select * from user_users; 




扩展资料:


Oracle数据库最新版本为Oracle Database 12c。Oracle数据库12c引入了一个新的多承租方架构,使用该架构可轻松部署和管理数据库云。


此外,一些创新特性可最大限度地提高资源使用率和灵活性,如Oracle Multitenant可快速整合多个数据库,而Automatic Data Optimization和Heat Map能以更高的密度压缩数据和对数据分层。


这些独一无二的技术进步再加上在可用性、安全性和大数据支持方面的主要增强,使得Oracle数据库12c 成为私有云和公有云部署的理想平台。


Oracle数据库具有完整的数据管理功能: 


1)数据的大量性


2)数据的保存的持久性


3)数据的共享性


4)数据的可靠性


查看Oracle中所有用户的方法 END

oracle 删除用户命令和部分命令 START

好文推荐:https://blog.csdn.net/yang_road/article/details/2305045



SQLPLUS 环境下

   ① 用户及用户下面所有表的删除

   drop user  username cascade;

   ② 创建用户

   create user username identified by password ;

   修改密码

   alter user system identified by [password]

   ③ 分配表空间

    alter user username default tablespace  表领空间 quota unlimited on 表领空间 ;

    创建表空间

    CREATE TABLESPACE "ts" 

    LOGGING 

    DATAFILE 'E:/ORACLE/ORADATA/TEST/ts.ora' SIZE 50M 

    EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT  AUTO

   ④ 权限赋予

    grant create session to username ;

    (create session :连接数据库的权限 )




oracle 删除用户命令和部分命令 END



PLSQL设置编辑器的字体大小的方法 START



很多时候,会搜索,会尝试,会思考才是更重要的技能。




菜单栏—工具—首选项—用户界面(左边列表)—字体—编辑器(点击选择调整)。 其他的字体也可以在那里设置。

PLSQL设置编辑器的字体大小的方法 END



查看Oracle中所有用户或角色的权限等等 START



推荐好文:https://mp.weixin.qq.com/s?src=11&timestamp=1614779792&ver=2924&signature=VwdW8RzALXGOkhAckOM3FD489ej5dpgY9INVTEngMTyVqXWlLKCpvWsESBGOvC-x3vREfL95fDefakUlrTQpDPBhTs4iPq-XgNNWzU*VZJ-zL98FgTrs3CWuNqttsjpR&new=1



1.查看所有用户:

select * from dba_users;

select * from all_users;

select * from user_users;


2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):

select * from dba_sys_privs;

select * from user_sys_privs;


3.查看角色(只能查看登陆用户拥有的角色)所包含的权限

sql>select * from role_sys_privs;


4.查看用户对象权限:

select * from dba_tab_privs;

select * from all_tab_privs;

select * from user_tab_privs;


5.查看所有角色:

select * from dba_roles;


6.查看用户或角色所拥有的角色:

select * from dba_role_privs;

select * from user_role_privs;


7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)

select * from V$PWFILE_USERS


比如我要查看用户 wzsb的拥有的权限:

SQL> select * from dba_sys_privs where grantee='WZSB';

比如我要查看用户 wzsb的拥有的角色:

SQL> select * from dba_role_privs where grantee='WZSB';

查看一个用户所有的权限及角色

select privilege from dba_sys_privs where grantee='WZSB'

union

select privilege from dba_sys_privs where grantee in 

(select granted_role from dba_role_privs where grantee='WZSB' );




select * from dba_role_privs;



查看Oracle中所有用户或角色的权限等等 END




Oracle中常用的部分语句个人总结 START


create table spInformation 


(


id number,


name varchar2(30),


price number(9,2),


type varchar2(30)


);


create table spType


(id number,


name varchar2(30));


--查询表


select * from spInformation; 


select * from spType; 




--通过sql语句给商品信息表的id添加主键约束

alter table spInformation 

add constraint PK_id primary key(id);

--name添加唯一约束

ALTER TABLE spInformation

ADD CONSTRAINT unique_spInformation

UNIQUE (name) 

--id添加外键约束

【表创建成功后再添加外键约束

添加外检约束 :alter table 从表表名 add constraint 

外键约束名称 foreign key(列名) references 主表名称(主键列名)】

alter table spType add constraint

 FK_spInformation foreign key(id) references spInformation(id);

--价格添加检查约束(1-99999999元)

Alter table spInformation

Add constraint CK_spInformation check(99999999>price and price>=1)

--在商品信息表和商品类型表中输入数据进行测试。

insert into spInformation values(1,'诗书画唱牌商品',999.99,'名牌类');


insert into spType values(1,'名牌类');

--select * from user_tablespaces ;

--select * from user_tablespaces ;






Oracle中常用的部分语句个人总结 END

SQL语句代码增删改查例子 START


--登录sys超级管理员账号执行

--创建一个名为J190802的账户

create user j190802

--设置密码为1

identified by orcl

--设置默认表空间为user

default tablespace users

--设置临时表空间为temp

temporary tablespace temp

--解锁账号,允许登录oracle

account unlock;


--允许j190802用户登录到orcl数据库

grant connect to j190802;

--允许j190802用户使用存储空间

grant resource to j190802;


--登录j190802账号执行代码

--创建一个表

create table userinfo(

    id number primary key,

    act varchar2(30) not null,

    pwd varchar2(30) not null,

    birth date

);

--新增语句

insert into userinfo values(2,'小明',789,sysdate);

--修改语句

update userinfo set pwd = 888 where id = 1;

--删除

delete from userinfo where id = 2;


select * from userinfo;

--显示rowid

select t.*,t.rowid from userinfo t;

--显示rownum

select rownum,t.* from userinfo t;


--创建学生表

create table stu(

   stuno number,

   stuname varchar2(20),

   address varchar2(30)

);

--给学生表添加一个sex属性

alter table stu add sex char(2);

--删除表:delete和drop

--删除stu表中的所有数据

--delete from stu;

--将stu表结构都删除了

--drop table stu;

--给stu表的stuno添加一个主键约束

alter table stu 

add constraint pk_stu

primary key(stuno);


create table product(

    id number primary key,

    pname varchar2(30) not null,

    price number(10,2),

    ptype number

);

create table protype(

    id number primary key,

    tname varchar2(30) not null

);

--添加外键约束

alter table product 

add constraint fk_product

foreign key(ptype)

references protype(id);


insert into protype values(1,'书籍');

insert into protype values(2,'家电');

insert into protype values(3,'食品');

insert into product values(1,'德芙巧克力',8.5,3);

insert into product values(2,'java实践',44.8,1);


--stu表中的stuname不能为空

alter table stu

modify stuname not null;


--Product表中的price必须在1到1000之间

alter table product

add constraint ck_price 

check(price between 1 and 1000);

--报错,价格超过1000了

--insert into product values(3,'电冰箱',3200,2);




SQL语句代码增删改查例子 END




Oracle创建或查看或删除用户,DBA,rownum伪列进行分页,增删改查语句等【诗书画唱】的评论 (共 条)

分享到微博请遵守国家法律