PLSQL 新建普通用户

1、使用system登录

2、File-->NEW-->SQL WINDOW

3、执行语句  

--创建用户
--create user 用户名 identified by 密码
create user scott identified by luckily
--给用户赋予权限
--赋予数据库登录链接权限
grant connect to scott;
--赋予资源操作权限
grant resource to scott;

Oracle忘记用户密码

1、cmd打开windows命令窗口

2、输入命令:sqlplus /nolog

3、输入命令:conn /as sysdba

4、输入命令:alter user 要修改的用户名 identified by 新的密码;

--单表查询
select *from emp
  --查询表中某个特定字段
  select empno from emp
  select empno,job from emp
  --给查询结果中的字段使用别名,as可省略
  select empno 员工编号,job as 工作, ename as "员工姓名" from emp
  --连接符: select 字段名||‘字符’||字段名 ... from 表名
  select empno||'的姓名是'||ename as "信息" from emp
  --去除重复:select distinct 字段名 from 表名
  --注意:去重是按行去重,多行数据相同取其一
  select distinct job from emp
  --排序:desc 降序 asc 升序
  select *from emp order by empno desc --单字段排序
  select *from emp order by empno,job asc --多字段排序
  --字段的逻辑运算
  select empno,ename,sal*2+1000 from emp
  select empno,ename,sal*2+1000,sal+comm from emp

  --条件限定(where)
    --各类运算符:=等于,>大于,<小于,>=大于或等于,<=小于或等于,<>不等于
    select *from emp where sal > 500
    --between and (查询900-2000的数据)
    select *from emp where sal between 900 and 2000
    --in (要么等于多少,要么等于多少)
    select *from emp where sal in(800,1600)
    --like(模糊查询,%表示任意匹配,有或者没有都可以,_表示有,并且只有一个)
    select *from emp where ename like '%a'
    --is null(查询为null的数据)
  select *from emp where job is null
  --逻辑运算符:AND与 OR或 NOT非
  select *from emp where sal<800 or sal>1500
--关联查询(需要两张表,left on)
--统计函数:count总数 max最大 min最小 avg平均
select count(*)from emp where sal>800 --统计工资高于800的人数
select max(sal),min(sal) from emp where deptno = 20 --统计deptno里为20的sal最大最小值
select avg(sal) from emp --sal的平均值
--分组函数group
select avg(sal),deptno from emp --统计deptno里的平均值
group by deptno
--having:对分组函数进行条件判断
select avg(sal),deptno from emp
group by deptno
having avg(sal)>2000 --统计大于2000的平均值
--子查询:子查询即可以简单的理解成同时执行多条sql语句将一条sql语句的查询结果作为条件来执行另一条sql语句
select count(*)from emp where sal>
(
select sal from emp where ename = 'SMITH'
)
--分页查询:rownum
select *from emp where rownum <= 5 --查询五条数据
select *from
(
select *from(select *from emp order by sal desc)
)
where rownum<=5 --查询薪水最高的五条记录

--Oracle创建新表
create table hero(
id number,
name varchar2(100),
hp number,
mp number,
speed number,
sex char(4),
birth date,
uskill varchar2(100)
)

--为新表添加数据
insert into hero values(001,'流浪法师',500,500,365,'男','08-4月-2005','曲径折跃');
insert into hero values(002,'战争之王',530,580,385,'男','18-9月-2008','大荒星陨');
insert into hero values(003,'弗拉基米尔',523,0,395,'男',to_date('2000-09-01','yyyy-mm-dd'),'鲜血潮汐');
insert into hero values(004,'拉克丝',500,600,309,'女','19-2月-2010','终极闪光');
insert into hero values(005,'虚空恐惧',600,570,378,'女','22-10月-2012','盛宴');
select *from hero
--修改数据
update hero set birth = to_date('2000-09-01','yyyy-mm-dd') where id = 3;
--删除数据
delete from hero where id = 5;
--舍去表:truncate table hero
--修改表结构:alter
--增加新的一列:alter table hero add (kills number)
--修改列:alter table hero modify(name varchar2(300))
--删除列:alter table hero drop column kills
--删除表:drop table 表名

约束种类 
唯一约束 unique 不可重复 
非空约束 not null 不能为空必须制定值 
主键约束 primary key 通常是给id使用的,同时具备了unique和not null约束 
外键约束 foreign key

Oracle_20200416的更多相关文章

随机推荐

  1. [Oracle19C ASM管理] ASM服务的启停

    自动方式启停 crsctl stat res -t 查看ASM服务的状态,it's ok that ora.ons和ora.diskmon是OFFLINE [grid@centos7-19c.loca ...

  2. Hyper-v 安装openwrt

    安装注意事项: 1.只能选一代,网卡可以使用新版2.网卡高级设置,MAC地址欺骗一定要选上,不选外部交换机不能上网.3.防火墙做wan口转发4.防火墙wan口,两个reject改为 accept . ...

  3. error: the option `Z` is only accepted on the nightly compiler

    问题记录 $ cargo expand Checking helo v0.1.0 (/Users/Buzz/Documents/git/rust-lang/hello) error: the opti ...

  4. 论文笔记:To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem?

    论文笔记:To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem? Conclusion 如果对象平均大小 ...

  5. php微信公众号开发之生成带参数的二维码

    参考微信公众平台:https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric ...

  6. oracl ocp认证到底有没有用!!!

    从一个网友听说有个OCP专家认证,我们本地也有,要1万3,问题是我想真的学东西而不是为了考证,不知道这个培训能学到多少呀.

  7. Python学习笔记调式之抛出异常

    随笔记录方便自己和同路人查阅. #------------------------------------------------我是可耻的分割线--------------------------- ...

  8. BBS 项目分析

    项目开发流程 # 1.核心 文章的增删改查 # 2.表关系分析 确定表的数量,确定表的基础字段,最后确定表的外键字段 # 3.表 1.用户表 2.个人站点表 3.文章表 4.文章分类表 5.文章标签表 ...

  9. tomcat 1 - Servlet 容器

    Socket socket = new Socket ( "yahoo.com", 80); OutputStream os = socket.getOutputStream(); ...

  10. Java流程控制之while循环详解

    while循环 while循环 do...while循环 for循环 在Java5中引入了一种主要用于数组的增强型for循环 while循环 while循环是最基本的循环,它的结构为 while(布尔 ...