oracle 基本查询语句及实例

1、查询所有列

select * from 表名;

2、查询表结构

     desc 表名;

3、查询指定列

select ename,sal,job from 表名;

4、oracle中查看所有表和字段

获取表:

select table_name from user_tables; //当前用户的表       

select table_name from all_tables; //所有用户的表   

select table_name from dba_tables; //包括系统表

select table_name from dba_tables where owner='用户名'

5、where字句

    select * from 表名 where 字段>数值;

    select * from 表明 where to_char(字段,'yyyy-mm-dd')>'1982-1-1';    to_char转换函数

    select * from 表明 where to_char(字段,'yyyy')='1980';

    select * from 表明 where to_char(字段,'mm')='4';

    显示工资在2000到2500工资

 select * from 表名 where 字段>=2000 and 字段<=2500;

 select * from 表明 where 字段 between 2000 and 2500;

6、模糊查询 like

      %:表示任意0到多个字符  ;  _ : 表示任意单个字符

如何显示首字母为S的员工姓名及工资

      select eaname, sal from 表名 where eaname like 'S%' ;

如何显示第三个字母为O的所有员工姓名及工资

      select eaname, sal from 表名 where eaname like '__O%';

7、where语句使用 in

      如何显示empno 为 123,345,678的雇员情况

     1、select * from  表明 where empno=123 or empno=345 or empno=678;

           select * from 表明 where empno in (123,345,678);

      2、is null 空值查询

          select * from 表明 where 字段名 is null ;

       3、oracle逻辑运算符

           查询工资高于500或是岗位为MSN的雇员,同时还要满足他们的姓名首字母大学J

          select * from 表明 where (sal>500 or job='MSN') and (enname like 'J%' );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值