日期:2014-05-16 浏览次数:20444 次
假设有下面的一张表:
CREATE TABLE FOO( FOOID NUMBER(10), FIRSTCOL NUMBER(10), SECONDCOL NUMBER(10) );
DECLARE N_FOOID FOO.FOOID%TYPE; N_FIRSTCOL FOO.FIRSTCOL%TYPE; N_SECOND FOO.SECONDCOL%TYPE; BEGIN N_FOOID :=0; DELETE FROM FOO; FOR I IN 0 .. 200 LOOP N_FOOID := N_FOOID+1; SELECT TRUNC(DBMS_RANDOM.VALUE(0, 200)), TRUNC(DBMS_RANDOM.VALUE(0, 200)) INTO N_FIRSTCOL,N_SECOND FROM DUAL; INSERT INTO FOO(FOOID,FIRSTCOL,SECONDCOL) VALUES(N_FOOID,N_FIRSTCOL,N_SECOND); END LOOP; END;
FOOID FIRSTCOL SECONDCOL 1 1 19 2 134 172 3 25 176 4 99 56 5 41 17 6 65 55 7 73 0
SELECT * FROM FOO T ORDER BY (CASE WHEN T.FIRSTCOL>T.SECONDCOL THEN T.FIRSTCOL ELSE T.SECONDCOL END);
SELECT * FROM FOO T ORDER BY GREATEST(T.FIRSTCOL,T.SECONDCOL);