oracle的使用流程,oracle简单使用

创建用户 并给连接数据库权限

1)create user CJ identified by DSJCJ;

2)grant create session to CJ;

oracle11g 用户默认的密码过期时间为 180 天,过期后无法使用,所以 数据创建好后,第一步要去检查一下这个过期时间,如果过期时间有期限,需要修改成 无限期,

查看:Select * FROM dba_profiles s Where s.profile='DEFAULT' AND resource_name='PASSWORD_LIFE_TIME';

工作常见问题记录(国盛)

修改为无限期:ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

连接方式

acd0bfa63287f9d1834241f8a96cb6ed.png

Oracle简单使用

Emp数据表

1.sqlplus命令

1)Scott用户登录:Sqlplus scott/tiger

查询emp表的全部内容

Select * from emp;

问题:

(1)表格的显示格式混乱

(2)所有表格都有标题行

设置每行显示的数据长度:set linesize 300;

设置每次显示胡行数:set pagesize 30;

再执行 select * from emp;

命令格式:col job for a8; 列空格设定8

Col job for a8;

select * from emp;

2)调用记事本:

利用“ed”命令启动本机记事本程序(例如notepad,vim)

ed hello;(在打开的hello.sql中编写语句然后保存,一般保存在C:\Users\Administrator\hello.sql)

@hello; (执行@文件名)

利用@指定也可调用磁盘上的文件,如果后缀也是“*.sql”也可以不用写后缀,否则都要写

@d:aa ; (执行d盘中aa.sql文件)

Ed d:aa ; (打开该文件)

Ed a.txt (打开记事本,写好)

@a.txt (执行要加后缀名)

3)显示用户Show user

切换用户:Conn 用户名/密码

切到sys用户 Conn sys/change_on_install as sysdba

Select * from emp;查询不出 因为该表属于scott用户 为:emp.scott

用 select * from emp.soctt

Show user

Conn sh

4)调用本机程序

不使用用户登录:Sqlplus /nolog

在sqlplus中考虑到用户可能使用系统命令,所以使用到一个host命令,

拷贝文件:copy 原文件 目标位置文件

Copy d:aa.sql c:1.sql; (不在用户中拷贝,在nolog中拷贝)

Sqlplus scott/tiger

Host copy d:aa.sql d:bb.sql ; (在sqlplus中拷贝用host)

2.简单查询

1)[数据的投影操作]---指查询需要的数据列 查询员工编号,姓名,工资,职位

Select empno,ename,sal,job from emp;

除了基本查询列之外,在简单查询中也支持四则运算。

查出编号,姓名,并计算年薪,如下:

Select empno,ename,sal12 from emp;

Select empno,ename,sal12 income from emp;

Select empno 员工编号,ename 姓名,sal*12 年薪 from emp;

2)连接查询--描述

Select empno || ename from emp;

可以将连接优化下,中间使用文字描述,“编号:XXX”

普通数字:直接写 字符:加单引号

Select ename|| 1 from emp;

Select empno||’hello’ emp;

Select ‘编号:’||empno||’姓名:’||ename from emp;

3)简单查询--消除掉重复内容:

Select job from emp;

Select distinc job from emp;(消除相同的职位)

Select distinc ename,job from emp;(这两列所有数据都存在,在这distinc比较的是姓名和职位没有同时重复的存在)

3 scott 用户表四张

630582ae4ff4457f9373d3723e6a370c.png

1)部门表:dept

Desc dept;

b082b7d82005ac1a49379e5a96658be9.png

Select * from dept;

7307cbdda5a2fd1174bc4cb3fbeff60a.png

2)雇员表emp(一个部门多个雇员)

a2bfb4927938cd47478f5054a9c1392d.png

Select * from emp;

582e148554c95f5e5e4dc87c6c86e127.png

3)工资等级编号(salgrade)

9733d5e71fd9a7442ba23c3d85e426c5.png

4f9d53ed4f647324ea21025ef2e32bb0.png

4)工资表(bonus)

554982cd9eb3dfb759d7d9fdcb9fb3b6.png

该表是空的没任何数据

4 sql限定查询(and or)

查询工资大于1200:Select * from emp where sal >1200;

工资大于1200总人数:Selelct count(*) from emp where sal >1200;

工资小于3000且不是办事员:Select * from emp where job <>’CLERK’ AND sal <3000;

Betwneen..and 范围

工资在1500到3000雇员

Select from emp where sal >1500 and sal<3000;

Select from emp where sal between 1500 and 3000;

查询1981年雇佣雇员信息:

Select * from emp where hiredata between ‘01-1月-1981’ end ‘31-12月-1981’;

查询所有领取佣金的雇员信息(comm字段佣金),查询不是空

Select * from emp where comm is not null ;

4 sql限定查询(and or)

查询工资大于1200:Select * from emp where sal >1200;

工资大于1200总人数:Selelct count(*) from emp where sal >1200;

工资小于3000且不是办事员:Select * from emp where job <>’CLERK’ AND sal <3000;

Betwneen..and 范围

工资在1500到3000雇员

Select from emp where sal >1500 and sal<3000;

Select from emp where sal between 1500 and 3000;

查询1981年雇佣雇员信息:

Select * from emp where hiredata between ‘01-1月-1981’ end ‘31-12月-1981’;

查询所有领取佣金的雇员信息(comm字段佣金),查询不是空

Select * from emp where comm is not null ;

IN操作符

查询雇员编号7369,7566,7788员工信息

Select * from emp where empno IN(7369,7566,7788);

查询雇员编号不是7369,7566,7788的员工信息

Select from emp where empno NOT IN(7369,7566,7788);

Select from emp where empno not IN(7369,7566,7788,null);错的not in中不能有null

模糊查询like

查询所有雇员姓名中以字母开头为A的员工:

Select * from emp where ename like ‘A%’; 第一个字母为A

Select * from emp where ename like ‘_A%’; 第二个字母为A

Select * from emp where ename like ‘%A%’; 有A的

如果like查询没有设置关键字表示查询全部

Select from emp where ename like ‘%%’ 名字不管是什么全部

Select count() from emp where ename like ‘%%’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值