select order where子句

数据库三个名次:

  1. sql:结构化查询语句,操作oracle数据库的语言。
  2. sqlplus:oracle自带的可以输入sql,且将sql执行的结果显示的终端;
  3. pl/sql:程序化的sql语句,sqlplus:oracle自带的可以输入sql,且将sql执行的结果显示的终端;pl/sql:程序化的sql语句,在sql语句的基础上加入一定的逻辑操作,如if ,for 。。。,是之成为一个sql快,完成一定的功能

四种对象

1.table:表格
2.view:视图
3.sequence:序列
4.index:索引
5.synonym:同义
6.program unit 程序单元,pl/sql操作的对象。

五种分类

sql的五大分类:
Data retrivel :数据查询
select
DML:数据操纵语言(行级操作语言):操作的是表格当中一条一条的数据
insert update delete
DDL:数据定义语言(表级操作语言):操作的内容为表格(对象)
create alter drop truncate rename
transaction control :事务控制
commit rollback savepoint
DCl:数据控制语言
grant revoke

delete ,truncate 区别:
delete :删除表中的一条或者多条记录,并不返回表格的初始化状态
truncate:清空表格,并且返回表格的初始化状态

oracle授予权限:
grant resource ,connect to user;
resource:
create trigger
create sequence
create type
create procedure

oracle第二章的内容

1,order by 子句的使用
1)order by 子句的使用
select 语句中的位置:
始终位于最后
2)order by 后可以跟什么:
列名,列的别名,表达式
列出现在select 关键字后的
顺序(列号);
3)order by 后可以跟多列
表示先按第一列排序
如果第一列相同值再按第二列排序
4)ASC表示升序,可省略,DESC表示降序
5)空值永远最大
升序时候,空值在最后面,降序时候,空值在最前面;

 例: sort  rows with  the ORDER BY clause
             1.ASC  -ascending  order,default  .//默认升序排序
             2.DESC - descending  order.  //降序排序
             3.ORDER BY clause  is  last  in select  command.
             SELECT  last_name.dept_id,start_date 
             FROM    s_emp 
             ORDER BY last_name;//按照名字升序来排序
             SELECT  id,last_name name  FROM  student  ORDER BY name DESC;

          SELECT id,first_name,last_name  FROM  student  order by 2;//根据第二列来排序,数字代表查询的第几列;
          SELECT first_name ,id  FROM student   ORDER   BY  2   DESC;
          Null值默认为最大值
          即:NULL  values  are  display   Last  for  ascending   sequences。//升序在最后
          first   for   descending  sequences。//降序在最前面

          使用多列排序:
          SELECT  last_name,id,first_name  FROM student  ORDER BY  id ASC,last_name  DESC;  //按照id的升序,last_name的降序排序。

注意:出现在 order by子句后面的列,不一定出现在select 子句中。

where 子句的使用

   语法:
         SELECT  column_name  FROM tableName   where  col_name  比较操作表达式 逻辑操作符   col_name  比较操作表达式;
         1)作用:对SQL语句返回的数据进行筛选;
         2)位置:紧跟在FROM 子句之后
         3)内容:由一个多个限定条件组成,限定条件由表达式,比较符,字面值组成。
         4)所有字符串和日期要用单引号括起来,数值不需要单引号。

日期在oracle里有特定的格式,‘DD-MON-YY’(具体看日期的显示格式)

limiting Rows selected;
restrict the rows returned by using the where clause,
1.the WHERE clause follow the FROM clase。
2.Condition consist of the following:
1)column name,expression,constant
2)comparision operator
3)Literal
例:SELECT Last_name , dept_id , salary FROM student where id=2;

1)操作运算符号
= > < >= <= !=
2)SQL comparison operate
BETWEEN … AND … //在什么之间的[]闭区间查找
IN (LIST)//在这个列表里面
LIKE//模糊匹配,即值不精确的时候使用通配符,即可代替任何内容的符号
%:统配0到多个字符
_:当且仅当统配一个字符
转义字符:
默认为\,可以指定,指定的时候用escape
符号证明即可,每个转义字符只能转义后面的一个字符
IS NULL // 为空
3)Logical operators
AND
OR
NOT
例子:SELECT id ,last_name FROM student id>3 ORDER BY id DESC;
SELECT id,last_name FROM student WHERE id!=2 ;
SELECT id,last_name FROM student WHERE id <>2 ;

SELECT id,last_name FROM student WHERE id BETWEEN 1 AND 19;//1到19之间。

SELECT id,name FROM student WHERE age IN (14,15,16,17)//查询年龄在14,15,16,17的信息。
SELECT id,name FROM student WHERE last_name LIKE ‘m%’;
SELECT id , last_name FROM student WHERE last_name like ‘_a%'escape '\’;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值