oracle数据库

select {distinct} * | 具体列  别名

from table

{where 条件}

{order by 排序字段1,排序字段2 asc | desc}

简单查询语句

灵活显示查询信息

select '编号是:'||empno||'的雇员,姓名是:'||ename||',工作是:'||job from emp;

使用四则运算

select ename, sal*12 income from emp;

限定查询

查询出工资大于1500的所有雇员信息

select * from emp

where sal>1500;

查询每月可以得到奖金的雇员信息

select * from emp

where comm is not null;

无奖金的雇员

select * from emp

where comm is null;

要求查询出,基本工资大于1500,同时可以领取奖金的雇员信息

select * from emp

where sal>1500 and comm is not null;

select * from emp

where sal>1500 or comm is not null;

select * from emp

where not (sal>1500 and comm is not null);

要求查询基本工资1500--3000的全部工资

select * from emp

where sal>1500 and  sal<3000;

========between min  and  max========

select * from emp

where sal between 1500 and 3000;  包括等于

要求查询出在1981年雇佣的全部雇员信息(1981-1-1,1981-12-31)

select * from emp

where hiredate between ‘1-1月 -81’ and ‘31-12月 -81’;

where hiredate like '%81%'

查询出姓名是smith的雇员信息

select * from emp

where ename='SMITH'; =====oracle区分大小写======

查询出雇员编号是7369,7499,7521的雇员的具体信息

select * from emp

where empno=7369 or empno=7499 or empno=7521;

where empno in (7369,7499,7521);

======模糊查询like========

_ : 可以匹配一个字符        % :可以匹配多个字符

select * from emp

where ename like '_M%';

where ename like '%M%';

=========order by子句===========<排序肯定是放在整个sql语句的最后执行>

工资低到高排序

select * from emp order by sal;  //默认低到高

工资由高到底排序

select * from emp

order by sal desc;

查询10个部门的所有雇员信息,工资由高到低排序,工资相等则按雇员日期由早到晚排序

select * from emp

where deptno=10

order by sal desc,hiredate asc;

==================================================================

¥¥¥¥¥¥¥¥¥¥单行函数¥¥¥¥¥¥¥¥¥¥¥

==================================================================

、、、、、、数据库中最大的区别就是函数的支持上不同、、、、、、

字符函数: 接受字符输入并且返回字符/数值

==将小写字母变为大写字母==<upper()>

select upper('smith') from dual;

==将字符串变为小写字母表示==<lower()>

select lower('HELLO, WORLD') from dual;

==将每个单词首写字母大写,其他小写==<initcap()>

select initcap('HELLO,WORLD') from dual;

==连接操作==  ||  和concat()函数

select concat('hello ','world') from dual;

==字符串截取 substr()---字符串长度length()--字符串替换replace()==

----substr()截取点从0或者1的截取效果一样,较智能-----

select substr('hello',1,3)  截取字符串,

length('hello')  字符串长度,

replace('hello','l','x')  字符串替换

from dual;

===显示雇员的姓名以及姓名的后三个字符===

select ename, substr(ename,length(ename)-2)) from emp;

select ename, substr(ename,-3,3) from  emp;

数值函数: 接受数值输入并且返回数值

四舍五入: round()

select round(789.536) from dual;  ====>789

select round(789.536,2) from dual; ====>789.54

select round(789.536,-2) from dual;=====>800

截断小数位:trunc()

select trunc(789.536) from dual; =====>789

select trunc(789.536,2) from dual;

取余 mod()

select mod(10,3) from dual;

==================================================================

^^^^^^^^^^^^^^^^^日期函数: 对日期型数据进行操作^^^^^^^^^^^^^^^^^^^^^^^

==================================================================

日期 + / - 数字 = 日期        日期 - 日期 = 天数

==显示部门10雇员进入公司的周数==

当前日期 ===>可使用sysdate()函数

当前日期-雇佣日期 =天数 / 7 = 周数

select empno,ename,round((sysdate-hiredate)/7) from emp;

===求出给定日期范围的月数months_between()====

select empno,ename,round(months_between(sysdate,hiredate)) from emp;

=======在指定日期加上指定的月数,求之后的日期add_months()  ========

select add_months(sysdate,4) from dual;

======= 下一月的今天是哪个日期next_day() ========

select next_day(sysdate,'星期一') from dual;

======= 求出给定日期的最后一天last_day() ========

select last_day(sysdate) from dual;

|===========================================================================|

|*************转换函数: 从一种数据类型转换成另一种数据类型*************************|

|===========================================================================|

to_char: 转换成字符串

to_number: 转换成数字

to_date: 转换成日期

-----查询所有雇员的雇员编号,姓名,雇用日期----------

select empno,ename,to_char(hiredate,'yyyy') year,

to_char(hiredate,'mm') months,

to_char(hiredate,'dd') day

from emp;

select empno,ename,to_char(sal,'$99,999') from emp;

select empno,ename,to_char(sal,'L99,999') from emp;

select to_number('123')+to_number('123') from dual;

select to_date('2016-02-25','yyyy-mm-dd') from dual;

|===========================================================================|

|************************通用函数: NVL函数,DECODE函数*************************|

|===========================================================================|

==求出每个雇员的年薪==    nvl函数=将指定的null值变为指定的内容

select empno,ename,nvl(comm,0),(sal+nvl(comm,0))*12 income from emp;

====验证decode函数,类似于if-else语句  ====

select decode(1,1,'内容=1',2,'内容=2',3,'内容=3') from dual;

总结:

1,oracle的主要用户:

超级管理员:sys/manager

普通管理员:system/change_on_install

普通用户:scott/tiger

2,sqlplus的一些常用命令:

set linesize 300

set pagesize 30

ed a    /  @a

conn sys/manager as sysdba

3,sql基础语法的格式

4,单行函数,decode函数最重要!

Oracle中sql的基本使用的更多相关文章

  1. oracle中sql语句的优化

    oracle中sql语句的优化 一.执行顺序及优化细则 1.表名顺序优化 (1) 基础表放下面,当两表进行关联时数据量少的表的表名放右边表或视图: Student_info   (30000条数据)D ...

  2. Oracle中SQL语句分类

    Oracle中SQL语句分类如下:1.DML语句 insert/delete/update/select/merge/explan plan/lock table2.DDL语句 create/atlt ...

  3. 转:Oracle中SQL语句执行过程中

    Oracle中SQL语句执行过程中,Oracle内部解析原理如下: 1.当一用户第一次提交一个SQL表达式时,Oracle会将这SQL进行Hard parse,这过程有点像程序编译,检查语法.表名.字 ...

  4. oracle 中SQL 语句开发语法 SELECT INTO含义

    oracle 中SQL 语句开发语法 SELECT INTO含义 在ORACLE中SELECT INTO是如何使用的,什么意思?和SQL SERVER的不一样?   和sqlserver的不一样sql ...

  5. 跟踪oracle中sql语句运行过程及相关知识拓展

    select * from v$sqlarea; select * from v$sqlarea where first_load_time>'2010-11-27/09:30:00'; 这种方 ...

  6. oracle中SQL根据生日日期查询年龄的方法

    方法:SELECT Trunc(MONTHS_BETWEEN(SYSDATE,BIRTH_DATE)/12) FROM 某表 Trunc函数在这里对带有小数位数的数字取整数部分: SYSDATE为or ...

  7. oracle中sql查询语句的执行顺序

    查询语句的处理过程主要包含3个阶段:编译.执行.提取数据(sql查询语句的处理主要是由用户进程和服务器进程完成的,其他进程辅助配合) 一.编译parse 在进行编译时服务器进程会将sql语句的正文放入 ...

  8. Oracle中SQL调优(SQL TUNING)之最权威获取SQL执行计划大全

    该文档为根据相关资料整理.总结而成,主要讲解Oracle数据库中,获取SQL语句执行计划的最权威.最正确的方法.步骤,此外,还详细说明了每种方法中可选项的意义及使用方法,以方便大家和自己日常工作中查阅 ...

  9. Oracle 中sql文件的导入导出

    导出 一般导入的时候我用的是命令行 imp c##zs/@orcl fromuser=c##zs touser=c##zs file=D:\java\.dmp ignore=y c##zs 是创建的用 ...

随机推荐

  1. windows azure中国 里面建立一个虚拟机,与虚拟机建立通信 里面部署IIS,外网访问

    在windows azure中国 里面建立一个虚拟机,里面部署IIS,外网不能访问么? 外网访问的地址是给的那个DNS地址 ,比如我的是 DNS 名称 urbanairserver.cloudapp. ...

  2. ArrayList的使用方法【转载】

    *** Source URL: http://i.yesky.com/bbs/jsp/view.jsp?articleID=889992&forumID=150 *** 1.什么是ArrayL ...

  3. Ubuntu 14.10 下grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...

  4. IOS网络开发概述

    概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力 ...

  5. Qemu文档

    http://wiki.qemu.org/Manual http://qemu.weilnetz.de/qemu-doc.html http://www.linuxcertif.com/man/1/q ...

  6. 【LeetCode】172. Factorial Trailing Zeroes

    Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your ...

  7. Windows系统下安装Beautiful Soup4的步骤和方法

    1.到http://www.crummy.com/software/BeautifulSoup/网站上下载,最新版本是4.3.2. 2.下载完成之后需要解压缩,假设放到D:\Python27下. 3. ...

  8. CODEVS1533 互斥的数(哈希表)

    给定一个集合,要求一个最大子集,满足两两之间不互斥.对两个数x,y互斥的定义是,y=p*x. 先对集合中的数从小到大排序后线性扫,若一个数x可以取则取,取完之后p*x这个数不可取.由于数字较大,使用哈 ...

  9. 【转】利用 Bootstrap 进行快速 Web 开发

    原文转自:http://blog.jobbole.com/53961/ 了解如何使用 Bootstrap 快速开发网站和 Web 应用程序(包括移动友好型应用程序).Bootstrap 以 LESS ...

  10. Jquery autocomplete插件的使用

    简单用法: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...