首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

数据库检索记要

2012-07-04 
数据库检索记录1.连接列值: DB2,Oracle使用||作为连接运算符。select ename || works as a || job as msg

数据库检索记录
1.连接列值:
DB2,Oracle使用||作为连接运算符。

  select ename || 'works as a' || job as msg from emp where deptno='10'

MySQL使用concat函数
 
  select concat(ename,'works as a',job) as msg from emp where deptno='10'  

SQL Server使用"+"号作为连接运算符
 
  select ename + 'works as a' + job as msg from emp where deptno='10'  


2.限制返回的行数:
  DB2 :
 
 select * from emp fetch first 5 rows only

  MySQL :
 
 select * from emp limit 5 

  Oracle:
 
 select * from emp where rownum < 5 


3.从表中随机取出5条记录:
  DB2 :
 
 select * from emp order by rahnd() fetch first 5 rows only

  MySQL :
 
 select * from emp order by rand() limit 5 

  Oracle:
 
 select * from ( select ename , job from emp order by dbms_random.value() ) where rownum < =5 ; 

 

热点排行