一、用户的创建、删除及修改
u 创建用户
语法 create user 用户名 identified by 密码;
新建用户必须在有管理员权限的账号下进行。
新建用户是没有任何权限的,若新用户想连接服务器,只有管理员才能赋予权限。
赋予新建用户连接数据库的权限 grant create session to abc (abc为新建用户)
赋予用户dba的权限 grant dba to abc ;
dba是除了重启数据库、修改字符集的权限没有外具有其余权限的数据库管理员
修改密码
alter user 用户名 identified by 密码。
删除用户
drop user 用户名;
二、基本查询
show user 查看当前用户
select * from tab 查看所有的表
SQL> set linesize 120 设置行宽 ,每一行 120字符
SQL> col ename for a8 设置ename的列宽,a代表字符串,8代表字符串宽度为8
SQL> col sal for 9999 9999代表四位数,设置sal的位数为四位数
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------------------------------------ -------------- ----------
AA VIEW
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
查询表名与mysql语法一样 select 列名1,列名2,列名3,....列名4 from 表名;
SQL> --查询员工号 姓名 月薪 年薪 年收入
SQL> select empno,ename,sal,sal*12 年薪,comm 奖金,sal*12+comm 年收入
2 from emp;
comm奖金中包含null值。在Oracle中,null!=null,需要nvl(comm,0),加nvl判断,如果为null,则赋值为0.
1 select empno,ename,sal,sal*12 年薪,comm 奖金,sal*12+nvl(comm,0) 年收入 nvl判断值如果为空,则赋值给它0
2* from emp;
1 select *
2 from emp
3* where comm is null 要用is 不要用=
SQL> --DISTINCT 去掉重复的记录
select distinct 字段名 from 表格名,出去重复的记录
distinct作用于后面所有的列。
SQL> select concat('Hello',' World') from dual;
链接字符,其中dual是管理员提供的伪表。
SQL> --查询员工信息: ****的薪水是****
SQL> select ename||'的薪水是'||sal 一列
2 from emp;
||为连接符。
save保存,导出该表。