zoukankan      html  css  js  c++  java
  • oracle PLSQL /sqlserver2005基本操作对比

    CASE 的语法。在一般的 SELECT 中,其语法如下:
    SELECT <myColumn> =
    CASE
    WHEN <A> THEN <somethingA>
    WHEN <B> THEN <somethingB>
    ELSE <somethingE>
    END //************************************************************************

    sql server2005中测试如下

    SELECT [createdate],
    monthnumber=case month(createdate) 
        when 12  then '十二'
        when 11  then '十一'
        when 10  then '十'
        when 9  then '九'
        when 8  then '八'
        when 7  then '七'
        when 6  then '六'
        when 5  then '五'
        when 4  then '四'
        when 3  then '三'
        when 2  then '二'
        when 1  then '一'
        else '未知'
        end +'月' 
    FROM [dbo].[zhq_content]

    另外一种
    SELECT [createdate],
    monthnumber=case 
        when month(createdate)=12  then '十二'
    /*    when 11  then '十一'
        when 10  then '十'
        when 9  then '九'
        when 8  then '八'
        when 7  then '七'
        when 6  then '六'
        when 5  then '五'
        when 4  then '四'
        when 3  then '三'
        when 2  then '二'
        when 1  then '一'*/
        else '未知'
        end +'月' 
    FROM [dbo].[zhq_content]

    //sql  server 2005中if   else用法

    declare  @a  int;
    declare  @b  nvarchar(50);
    set @a=10;
    if @a=8
     set @b='b8'
    else if @a=9   -- not  elseif
     set @b='b9'
    else
     set @b='b10'
    print @b;

    //sql server2005中字符长度

    declare  @a  nvarchar(50);
    declare  @b  nvarchar(50);
    set @a='100.00中';
    set @b=datalength(@a)--len(@a) 12

    print @b;  --14

    //字符截取

    declare  @a  nvarchar(50);
    declare  @b  nvarchar(50);
    set @a='100.00';
    set @b=substring(@a,1,3)--substring  和C#中的有区别(从0开始) 这里是从1开始
    print @b;
    --isnull(,)

    //oracle*************************************************************


    substr(,,)注意不是substring(,,) 如下图可知

     

    nvl(,)--与sql  server中isnull差不多。。。。

  • 相关阅读:
    一个帖子掌握android所有控件、ProgressBar 、Android 动画效果、SQLite、四大组件、Android多媒体(转
    Android开发交流群
    我的程序里 《我的歌声里》程序员版
    《老罗Android开发视频教程安卓巴士》(Android 开发)
    #百度360大战# 我为什么要支持360
    安卓巴士移动开发者周刊第九期
    水杯题的非常好的解释
    [LeetCode] Jump Game
    [LeetCode] Longest Common Prefix
    [CareerCup][Google Interview] 寻找动态的中位数
  • 原文地址:https://www.cnblogs.com/jasenkin/p/1654043.html
Copyright © 2011-2022 走看看