zoukankan      html  css  js  c++  java
  • mysql 临时变量,临时表

    创建临时表 CREATE TEMPORARY TABLE tmp_table ```

    CREATE TEMPORARY TABLE tmp_table SELECT * FROM  `tb_fdt_courseitem` WHERE `StudentId`='0e02d67f-02ba-4cb7-87de-d5e1d4dcfa8e'
    AND  `StartDate`>='2012-01-01'
    AND `EndDate`<='2013-12-31'
    GROUP BY   `SubjectId`;

    查询
    SELECT * FROM tmp_table;

    删除
    DROP TEMPORARY TABLE IF EXISTS tmp_table;

    1. -- Mysql 存储过程
    2. /* 
    3. set @result = 0; 
    4. create procedure login(     -- 定义参数,有in、out、inout三种类型
    5. in user varchar(10), 
    6. in pass varchar(10), 
    7. out result int
    8.     ) 
    9. begin
    10. declare passd varchar(10);-- declare 声明临时变量、类型,然后用set 进行赋值,declare 临时变量只能放在begin end 区域中,而其作用域也只是在begin end 中, 而 set @ 定义的变量是全局变量
    11. select password into passd from login where username=user; 
    12.         if passd like pass then --  If 语句,后面要加上 End IF,就像是case 后也要加 End Case  一样
    13. select 'Login Success' as Massage; 
    14. set result = 1; 
    15. else
    16. select 'Login Failed' as Message; 
    17. set result =0; 
    18. end if; 
    19. end; 
    20. */ 
    21. -- 调用存储过程  call login('root','root',@result);
    22. -- 删除存储过程  drop procedure login
    23. create procedure translate( 
    24.     id int
    25. begin
    26. case id 
    27. when 1 then
    28. select 'one' as trans; 
    29. when 2 then
    30. select 'two' as trans; 
    31. when 3 then
    32. select 'three' as trans; 
    33. else
    34. select 'no trans' as trans; 
    35. end case; 
    36. end; 
    37. /* 
    38. case 用法有两种: 
    39.     1. 条件变量在when 中 
    40. select name, case
    41. when age>10 then xxxxx 
    42. else
    43.                 xxxxxx 
    44. end case
    45.     2. 条件变量在case 中 
    46. select name,case age 
    47. when >10 then xxx  
    48. else xxxxxs 
    49. end case
    50. */ 

    //再来一个演示

    1. BEGIN   
    2.     DECLARE long_status VARCHAR(20);   
    3.     IF in_status = 'O' THEN   
    4.         SET long_status='Overdue';   
    5.     ELSEIF in_status = 'U' THEN   
    6.         SET long_status='Up to date';   
    7.     ELSEIF in_status = 'N' THEN   
    8.         SET long_status='New';   
    9.     END IF;   
    10.     RETURN(long_status);   
    11. END; 

    //给指定时间,增加一天

    DATE_ADD(OrderDate,INTERVAL 1 DAY)

    //指定时间,转换为 年月日

    DATE_FORMAT(p_time,'%Y-%m-%d')

  • 相关阅读:
    批量编译当前目录下4gl文件
    oracle数据库查看表
    Oracle中授权(grant)和同义词(synonym)
    Oracle中的instr()函数 详解及应用
    T100的程序错误提示方法
    六种 主流ETL 工具的比较
    oracle恢复数据到某个时间点
    Oracle统计一个小时内,一天内、一个星期内、一个月内、一年内的数据
    Linux top命令的用法详细详解
    Win10操作系统无法访问局域网共享文件夹的问题
  • 原文地址:https://www.cnblogs.com/joeylee/p/2842287.html
Copyright © 2011-2022 走看看