• 技术文章 >数据库 >MySQL

    mysql与oracle语法区别有哪些?

    yangyang2020-06-03 11:14:36原创2918

    mysql与oracle语法区别:

    1、在MySQL中from 后的表如果是(select.......)这种,那么后面必须有别名

    2、连接字符串在Oracle中用|| ,MySQL中用concat('a','b','c')

    3、mysql没有像orcale的动态游标,只有显示游标

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    DELIMITER $$ 

       

    DROP PROCEDURE IF EXISTS `test`.`liyukun`$$ 

       

    CREATE DEFINER=`ids`@`localhost` PROCEDURE `liyukun`(out z int

       

       

       

    BEGIN 

       

        declare count1 int

        DECLARE done INT DEFAULT 0;   

          

        declare v_haoma varchar(50); 

        declare v_yingyeting varchar(100); 

           

           

        DECLARE cur1 CURSOR FOR select haoma,yingyeting  from eryue where id<2;   

        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;   

       //这里和oracle有区别,Oracle的PL/SQL的指针有个隐性变 

    量%notfound,Mysql是通过一个Error handler的声明来进行判断的 

       

        

         OPEN cur1;   

         cur1: LOOP   

             FETCH cur1 INTO v_haoma,v_yingyeting;   

             IF done=1 THEN   //如果没有数据了,则离开   

                 LEAVE cur1;   

             ELSE 

              

             select count(*) into count1 from year2012 where haoma=v_haoma ; 

             if(count1=0) then 

                 

             insert into year2012(haoma, yingyeting)  

             values(v_haoma,v_yingyeting); 

                

             else  

             set z = z+1; 

             update year2012 set eryue = ‘100’ where haoma=v_haoma;   

       

             end if; 

       

       

             END IF; 

         END LOOP cur1;   

         CLOSE cur1;   

       

           

       

        END$$ 

       

    DELIMITER ;

    4、orcale用decode()来转换数据,mysql用case when:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    SELECT

    sql 中 case when  Title,

    sql 中 case when 'Price Range'=

    sql 中 case when CASE

    sql 中 case when WHEN price ISNULLTHEN'Unpriced'

    sql 中 case when WHEN price <10THEN'Bargain'

    sql 中 case when WHEN price BETWEEN10and20THEN'Average'

    sql 中 case when ELSE'Gift to impress relatives'

    sql 中 case when END(必须有end)

    5、Orcale中没有TOP,是通过

    1

    select * from (select * from A order by id desc) where rownum=1

    注:不能直接写 select * from A where rownum=1 order by id desc 因为语句执行的顺序是先where再order by ,如果这样写就无法按id的排序来取第一个了。

    不能写rownum=2或rownum>1这样,因为Orcale 默认必须包含第一条。

    如果非要取第二条的话,可以写成:

    1

    select * from (select id,rownum as row_num from lws_q_bl_result r where r.sample_id = 'B10226072') where row_num=2

    mysql:

    limit是mysql的语法

    1

    select * from table limit m,n

    其中m是指记录开始的index,从0开始,表示第一条记录

    n是指从第m+1条开始,取n条。

    1

    select * from tablename limit 2,4

    即取出第3条至第6条,4条记录

    6、Orcale,MySql while循环比较

    Orcale:

    1

    2

    3

    4

    5

    while num<10

    loop

    str := to_char(num);

    num := num+1;

    end loop;

    mysql:

    1

    2

    3

    4

    5

    while num<10

    do

    str := to_char(num);

    num := num+1;

    end while;

    7、orcale 生成唯一序列是 select sys.guid() from dual ,mysql是 select uuid() from dual

    推荐:MySQL教程

    专题推荐:mysql oracle
    上一篇:本地连接mysql的url怎么写? 下一篇:mysql空间不足怎么解决?

    相关文章推荐

    • mysql影响性能的因素有哪些?• mysql安装odbc失败怎么解决?• 怎么操作mysql

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网