<pre name="code" class="plain"><pre name="code" class="plain"><pre name="code" class="plain">一 登录口令
1 c:\sqlplus / as sysdba
1.1 普通用户登录
1.1.1
d:\sqlplus scott/密码 ----普通用户登录
quit ----退出
1.1.2
d:\sqlplus
请输入用户名:scott
输入口令:
1.2 超级用户登录
c:\sqlplus /nolog
SQL>connect / as sysdba
二 基本select 语句
SELECT *|{[DISTINCT] column|expression [alias],...} FROM table;
----语法结构
注意:
SQL 语言大小写不敏感。
SQL 可以写在一行或者多行
关键字不能被缩写也不能分行
各子句一般要分行写。
使用缩进提高语句的可读性。
2.1查看用户有什么表
SQL> select * from tab;
tab是数据字典 (oracle超级管理员分配给普通用的资源....,tab关键字....)
2.2查询dept(部门表)的所有记录
SQL>select * from dept;
2.3查看表结构
SQL> desc dept
2.4 控制输出行宽度和业长度
SQL> set linesize 150; ----设置行宽,分号可选
SQL> set pagesize 150; ----设置页大小,分号可选
SQL> select * from emp;
2.5 设置列宽度,两种表示方法
SQL> col empno for 9999; ----empno列占据四个位
SQL> select * from emp;
SQL> col empno for a10;----empno列占据十个位
SQL> select * from emp;
2.6 清屏
SQL>host cls;
2.7 只显示一部分
SQL> select empno,ename,job,sal,comm from emp;
2.8 将指令作为别名显示
SQL> select empno as "员工编号",ename "员工姓名",job 工作,sal 工资,comm 奖金, nvl(sal*12+comm, sal*12) 年薪 from emp;
注意:
select ename as(可以省略) "员工姓名" , empno "编号", job 工作(引号也可以省略), sal "月 薪"(不能省略) , sal*12 年薪 from emp;
--1别名: 省掉"" as
--2类名,有空格时, 不能省掉""
2.9 空值问题
2.9.1 NULL空值 任何数和null运算都为null (null无穷大)
2.9.2 空值不是空 null != null
2.10 nvl滤空函数
null滤空函数: nvl (a, b) -- 当a是空的时候,返回b( 其中 b可以是数字/字符串)
2.11 ed(或者edit)命令 ----在文本编辑器中编辑刚刚写入的指令(最好能去掉文本中的“/”)
紧接着输入SQL>/即可重新编译该指令
2.12 where 命令初探,输出符合指令的表格数据
SQL> select * from emp where comm is null;
SQL> select * from emp where comm is not null;
2.13 连接符:||
2.14 伪表dual是数据字典 (oracle超级管理员分配给普通用的资源....,tab关键字....)
SQL> select sysdate from dual;
SYSDATE
--------------
24-3月 -16
2.15 DISTINCT:
(1)在 SELECT 子句中使用关键字 ‘DISTINCT’ 删除重复行 SQL> select distinct deptno from emp;
DEPTNO
----------
30
20
10
(2) 2)DISTINCT 修饰多个字段的时, 当部门编号和工种都一样的时候,认为是重复的...
否则 不同行. (即,是或的关系) ====DISTINCT 2个字段 (两个部门只要有一个名称不同即可)
sql 和sql*plus的区别:
<img src="https://img-blog.youkuaiyun.com/20160324223439725" alt="" />