码字定式之SQL(5)

  1. --等值连接
  2. select dname, loc, empno, ename from emp a, dept b where a.deptno=b.deptno and b.deptno=20;
  3. --自连接
  4. select a.empno, a.sal, b.empno, b.ename, b.sal from emp a, emp b where a.mgr=b.empno and a.ename=‘SCOTT‘;
  5. --笛卡尔积
  6. select a||‘+‘||b||‘=‘||(a+b) as "3*3加法表" from (select rownum a from all_objects where rownum<4), (select rownum b from all_objects where rownum<4);
  7. --内连接
  8. select empno, ename, sal, salgrade.grade from emp, salgrade where emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
  9. select empno, ename, sal, salgrade.grade from emp inner join salgrade on emp.deptno=10 and emp.sal between salgrade.losal and salgrade.hisal;
  10. --反连接
  11. select * from emp where deptno not in (select deptno from dept where loc in(‘NEW YORK‘, ‘DALLAS‘));
  12. select * from dept where deptno not in (select deptno from emp);
  13. --半连接
  14. select * from emp a where exists (select 1 from dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno);
  15. select a.* from emp a, dept b where loc=‘NEW YORK‘ and a.deptno=b.deptno;
  16. select * from dept a where exists (select 1 from emp b where a.deptno=b.deptno and b.sal>2900);
  17. select a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;
  18. select distinct a.* from dept a , emp b where a.deptno=b.deptno and b.sal>2900;

来自为知笔记(Wiz)

时间: 2024-08-30 08:51:26

码字定式之SQL(5)的相关文章

码字定式之SQL(1)

“定式”就是说这些知识是前人总结的经验,需要记忆的一些东西. 这些东西同样博大精深,但是拘泥于此就会陷进去.因为这些实战中有可能你3年都用不到. 怎么说呢,高手请绕道,初学者应该可以看看. 提供一个好使的兵器:pl sql develop 自带oracle客户端 ,解压就能用,支持12c. http://download.csdn.net/detail/gaoguosheng/6476241 学sql没别的窍门,就是每天练习. 本节列举一些最基础的sql : 单表 select * from e

码字定式之SQL(3)

oracle 中有个很重要的同义词 dual. 往dual中插入数据是作死的节奏,记住这点就可以. insert into dual values('20'); 你再执行 select count(*) from dual; 和 select count(dummy) from dual; 呵呵,看不懂了吧. 再试试 delete from dual: 发现执行两次才可以删除... 你会说好吧,b 给个大家装B的 语句 :set autot on explain;  -- 用于开启执行计划的,对

码字定式之SQL(4)

一些子查询 select empno, ename from emp where mgr in (select empno from emp where job='MANAGER'); select * from dept where deptno not in (select distinct deptno from emp); select * from dept where deptno not in (select deptno from emp); select empno, enam

码字定式之SQL(7)

With 子句从 oracle 9i 开始支持 --不用connect by,只用dual表,构造出1到128 with a as (select 1 from dual union all select 1 from dual) select rownum from a, a, a, a, a, a, a; --做一个5*5的乘法表 with multiplier as (select rownum n from dual connect by rownum<6) select a.n||'*

码字定式之SQL(2)

select 基本构成之经典格式 select * from emp; select * from emp where empno>8000; select empno,ename,sal,comm from emp where sal<comm; select deptno,count(*) from emp group by deptno; select deptno,sum(sal) total_sal from emp where job='MANAGER' group by dept

码字定式之SQL(6)

--外连接(用(+)书写) --查询出所有部门的雇员信息 select b.deptno, b.dname, a.* from emp a, dept b where a.deptno(+)=b.deptno ; --查询出所有部门的雇员数 select b.deptno, count(*) from emp a, dept b where a.deptno(+)=b.deptno group by b.deptno; select b.deptno, count(empno) from emp

sql注入总结

本实验测试是基于sqli-labs的实验环境 环境配置:php+mysql 环境搭建请参考 http://www.freebuf.com/articles/web/34619.html Sql注入定义: 就是通过把sql命令插入到web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行的sql命令的目的 sql注入分类: 基于联合查询 基于错误回显 基于盲注,分时间盲注和布尔型的盲注 基于user-agent 基于feferer 基于cookie 二次注入 宽字节注入 注入一个网站

【渗透攻防Web篇】SQL注入攻击高级

前言 前面我们学习了如何寻找,确认,利用SQL注入漏洞的技术,本篇文章我将介绍一些更高级的技术,避开过滤,绕开防御.有攻必有防,当然还要来探讨一下SQL注入防御技巧. 目录 第五节 避开过滤方法总结 5.1.大小写变种 5.2.URL编码 5.3.SQL注释 5.4.空字节 5.5.二阶SQL注入 第六节 探讨SQL注入防御技巧 6.1.输入验证 6.2.编码输出 正文 第五节 避开过滤方法总结 Web应用为了防御包括SQL注入在内的攻击,常常使用输入过滤器,这些过滤器可以在应用的代码中,也可以

必杀技———SQL基础整理系列(一)

SQL(Structured Query Language)——结构化查询语言 SQL语言的组成部分 数据定义语言 (DDL:Data Definition Language) 负责数据结构定义与数据库对象定义的语言,由CREATE.ALTER.DROP三个语法所组成,操作的对象包括关系表.视图.索引等. 数据操纵语言(DML: Data Manipulation Language) 其语句包括动词SELECT(查询).INSERT(添加).UPDATE(修改).DELETE(删除)表中的行.