五 08
一、Oracle 中 CASE 的的功能跟一般程序语言中 CASE 的功能大致一样,是 IF ELSE 的加强,用于多条件下的判别,基本语法为
CASE [expression]
WHEN <condition1> THEN <value1>
WHEN <condition2> THEN <value2>
ELSE <value>
END
当 CASE 有 expression 时,通过 expression 与 condition 的值进行比较,确定返回值。
当 CASE 后没有 expression 时,condition 为待求值表达式,通过 condition 中的条件确定返回值。
EX1: 用于select
SELECT Title,’Price Range’ =
CASE
WHEN price IS NULL THEN ‘Unpriced’
WHEN price < 10 THEN ‘Bargain’
WHEN price BETWEEN 10 and 20 THEN ‘Average’
ELSE ‘Gift to impress relatives’
END
FROM titles
EX2: 用于Group By
SELECT ‘Number of Titles’, Count(*)
FROM titles
GROUP BY
CASE
WHEN price IS NULL THEN ‘Unpriced’
WHEN price < 10 THEN ‘Bargain’
WHEN price BETWEEN 10 and 20 THEN ‘Average’
ELSE ‘Gift to impress relatives’
END
二、Oracle 中使用 WITH 的作用是将 with 后子查询命名,放到 select 子句前,供select子句使用
EX1:
WITH
a AS (SELECT * FROM bd_member WHERE ROWNUM<10),
b AS (SELECT * FROM tp_trade_card)
SELECT a.MEMBER_NAME, b.CARD_NO
from a,b
where a.BD_MEMBER_ID = b.BD_MEMBER_ID
Related posts
八 03
一、类声明
public:类是可以公共访问的
abstract:类不能被实例化
final:类不能被子类化
class NameOfClass:类声明
extentds Super:类的超类
implements Interfaces:类所实现的接口
Read the rest of this entry »
Related posts
七 28
一、创建和使用数组
1)声明一个变量来引用数组int[]/float[]/boolean[]/Object[]/String[] anArray
2)使用new操作符显式地创建数组 如:anArray = new int [10],创建了数组之后此数组还不包含任何对象,是空的。必须显式地创建对象并将他们放在数组中。
3)数组初始化,实际上这样写是先创建然后在初始化数组 boolean [] answers = {true,false,false,true};
4)访问数组:anArray[i],i为数组索引
Read the rest of this entry »
Related posts
七 28
练习解答
1.
1
2
3
4
5
6
7
8
9
10
11
12
13
| public class EX438_1
{
public static void main(String[] args)
{
System.out.println( Integer.toHexString(65)); // 将65转换成16进制数
System.out.println( Integer.toHexString(945678).toUpperCase());
System.out.println( Integer.parseInt("230",5));//将字符串以5为基数表示的integer,如“230”转换成整数值65
System.out.println( Integer.valueOf("230",5));
System.out.println( Double.isNaN(34.23));//检查浮点数是否具有特殊值NaN
}
} |
Read the rest of this entry »
Related posts
七 27
Java平台包含三个用于字符数据处理的类。
1)Character:该类的实例可以包含单个字符值,也可以用于操作和检查单字符数据的简便方法。
2)String:该类用于处理由多个字符组成的不可改变的数据。
3)StringBuffer:该类用于存储和操作由多个字符组成的可改变的数据。
Sting类提供了好几个不同的构造器,允许使用不同的数据源提供字符串初始值。
1
2
3
4
5
6
7
8
9
| String();//创建空字符串
String(byte[]);//创建字符串,其值由一个字节数组的内容设置
String(byte[],int,int);//参数表示字节数组的偏移量和长度
String(byte[],int,int,String);//String参数指定将字节转换成字符所用的字符编码
String(byte[],String);
String(char[]);
String(char[],int,int);
String(String);//不建议使用这种具有字符串直接值参数的构造器,它创建了两个相同的字符串
String(StringBuffer);//由字符串缓冲区设定其值 |
Read the rest of this entry »
Related posts
Recent Comments