oracle自学笔记

SQL语句不区分大小写,可以写在一行或者多行,关键字不能缩写也不能分行,使用缩进提高可读性

修改密码为oracle:
alter user sys identified by oracle account unlock;

oracle备份(EXP)
exp sys@orcl file=D:\sys.dmp
oracle恢复(imp)
imp userid=uname/pwd tables=ce file=/home/oracle/data-bak/ce.dmp;

select:标识,选择那些列
from:标识,从那些表选择

select ID,name from tables; :选择特定的列
select后跟列名from后跟表名
连接符用||表示(把列与列,列与字符连接在一起)

重复行
默认情况下查询会返回全部行,包括重复行
删除重复行
在select子句中使用关键字“DISTINCT”删除重复行

where子句
在select后面可以加where子句,用来限定查询的结果集
比如要查询姓名为XS的学生:
select * from t_c11_zyryda where xm='xs';

desc/describe用来查看数据的表结构
desc dba_users;

distinct(去重)查找的结果不需要有重复的数据出现时用
selec distinct product_name from prcduct;

判断是否为空(不好喊任何内容)
select * from school where address is null;

查看时间
select sysdate from dual;

三天后的时间
select sysdate +3 from dual;

列的别名(加入关键字AS,别名使用双引号)
SQL> select sysdate as 当前时间 from dual;
当前时间

2018/9/4 10

加减乘除计算器
select 8*8 from dual;

ORACLE默认表
emp表
empno 员工编号,唯一的 主键
ename 员工姓名
job 工作
mgr 员工经理编号
hiredate 入职日期
sal 工资
comm 奖金
deptno 部门编号
ioc 地址

select语句
select ename,job,sal from emp;(查询员工姓名,工作,工资)
select 列(后面跟列,)...列 from 表名字 where 列;
select * from emp where sal>2000;(查找工资大于2000的员工)
rollback 回滚
commit 提交

批量插入语句
insert info 表名字 values()
insert into test values(null,'SYS_C00521',51,null);
insert table test as select from emp;
select
from test update ,会把test表所有行锁住(不要用)
select * from test ename=范冰冰 for update(只锁定一行)

update修改语句
select * from test;

update test set sal =10000;(实际工作中加where条件,不然修改的是整个表

猜你喜欢

转载自blog.51cto.com/1362336072/2171692