Oracle基本操作语句一

公司很快就要上Oracle ERP,不懂Oracle实在不行呐,在学习的过程中总结了一些基本的操作语句,摘录下来与大家共享,多多指教.

(1) 查询所有的记录  select * from scott.emp
(2) 查询所有记录的某些字段  select empno,ename,job from scott.emp
(3) 查询某些字段的不同记录  select distinct job from scott.emp

(4) 单条件的查询 select empno,ename,job from scott.emp where job='manager'

    其中等号可以换成其他运算符:

    != 不等于 select empno,ename,job from scott.emp where job!='manager'

    ^= 不等于 select empno,ename,job from scott.emp where job^='manager'

    <>不等于  select empno,ename,job from scott.emp where job<>'manager'

    <小于  select sal from scott.emp where sal<1000

    >大于 select sal from scott.emp where sal>1000

    <=小于等于 select sal from scott.emp where sal<=1000

    >=大于等于  select sal from scott.emp where sal>=1000

    in 在列表  select sal from scott.emp where sal in(1000,2000)

    not in 不在列表 select sal from scott.emp where sal not in(1000,2000)

    between...and 介于..与..间 select sal from scott.emp where sal  between 1000
    and 2000

    not between...and 不介于..与..之间  select sal from scott.emp where sal not
    between 1000 and 2000

    like 模式匹配  select ename from scott.emp where ename like 'M%'
    (%表示任意长度的长度串)

                  select ename from scott.emp where ename like 'M_'
                  (_表示一个任意的字符)


   is null 是否为空  select ename from scott.emp where ename is null

   is not null 不为空 select ename from scott.emp where ename is not null

    or(或)  select ename from scott.emp where ename='joke' or ename='jacky'

    and(与) select ename from scott.emp where ename='and' or ename='jacky'

    not(非) select ename from scott.emp where not ename='and' or ename='jacky'


(5)字段运算(+ - * /) select ename, sal,mgr,sal+mgr from scott.emp

(6)字段重命名 select ename 姓名,empno 工号, job 工作 from scott.emp

(7)无条件多表查询 select scott.ename,scott.job dept.dname,dept.loc from scott,dept;

等值多表查询 select scott.ename,scott.job dept.dname,dept.loc from scott,dept where scott.ename=dept.dname;

非等值多表查询 select scott.ename,scott.job dept.dname,dept.loc from scott,dept where scott.ename!=dept.dname and scott.job!='工人';

(8)嵌套查询(IN) select empno,ename,sal,job from scott.emp where sal in(select sal from scott.emp where ename='ward');

嵌套查询(ANY) select empno,ename,sal,job from scott.emp where sal > any(select sal from scott.emp where ename='ward');

嵌套查询(SOME) select emp.empno,emp.ename,emp.job,emp.sal from scott.emp where sal=some(select sal from scott.emp where job='manage');

嵌套查询(Exists) select emp.empno,emp.ename,emp.job,emp.sal from scott.emp,scott.dept where exists(select * from scott.emp where
scott.emp.deptno=scott.dept.deptno);

嵌套查询(Union)并集  (select deptno from scott.emp) union (select deptno from
scott.dept)

嵌套查询(intersect)交集  (select deptno from scott.emp) intersect (select deptno from scott.dept)

嵌套查询(minus)补集  (select deptno from scott.emp) minus (select deptno from scott.dept)

RowNUM 行号运用

(1) select RowNUM,ename from scott.emp;

(2) select ename,sal,from scott.emp where (RowNUM>3 and RowNUM<7) order by sal;

这些是基本的吧,似乎跟MS-SQL相差不大,个人感觉,Oracle重在管理与配置部分吧.先学到这[em01]

上一篇: 无选择内容出现 不能在 DropDownList 中选择多个项
下一篇: Oracle基本操作语句(二)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 5750
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭