数据库检索记录

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 ; 

 

猜你喜欢

转载自openopenjava.iteye.com/blog/1557918