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. ios 检测应用程序升级问题

    app 上其实已经有自动检测我们版本的功能.  其实我也觉得对于一个程序员来说检测功能让,系统来维护更合适和合理.开发者只要告诉苹果即可. 然而今天老大非要实现自己版本更新的问题,因此也查找了相关的资 ...

  2. 捕获异常的两种方式Exception

    1.抛出异常:让调用此方法的代码去管 public static void GetFile() throws Exception{} package com.throwable; import jav ...

  3. C++除法取整

    使用floor函数.floor(x)返回的是小于或等于x的最大整数.如:     floor(2.5) = 2 floor(-2.5) = -3 使用ceil函数.ceil(x)返回的是大于x的最小整 ...

  4. hdu 2068

    ps:长度长到我不想说....WA了无数次...25的阶乘就爆炸... 代码: #include "stdio.h" #define LL long long LL fac(lon ...

  5. ios--NSCalendar NSDateComponents

    原文: ios时间那点事--NSCalendar NSDateComponents http://my.oschina.net/yongbin45/blog/156181 目录[-] iOS时间那点事 ...

  6. Effective C++ ----以对象管理资源

    以对象管理资源 通过对象的析构函数的自动调用来自动释放资源 第一部分:几种典型的以对象管理资源的例子 1. STL::auto_ptr 获取资源后立刻放入资源管理对象 std::auto_ptr< ...

  7. UVA 1639(组合数学)

    根据组合数公式C(m,n),由于m可能达到20万,因此转换为ln,之后可以表达为ln(m!)-ln(n!)-ln((m-n)!); 求每一个c[n]时,也要根据杨辉三角求组合数进行转化. 注意long ...

  8. 重学STM32---(五)ADC

    这两天把外部中断和ADC看了下,个人感觉外部中断不是很难,也就没有把记下来了,毕竟写这个挺浪费时间.ADC是比较复杂的,如果想让完全自由的运用ADC必须经过多次实践可能才可以.由于已经学过库函数,也就 ...

  9. tracking 问题解决

    1.dir,或者C++函数读文件名,不推荐.搞乱了名字 2. matio读写矩阵

  10. POM的配置文件

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...