全部博文(136)
分类: Oracle
2008-05-29 08:27:43
序号 ID
NAME ------- --------- ------------- 1 422_01 yuechaotian1 2 422_02 yuechaotian2 3 422_03 yuechaotian3 4 422_04 yuechaotian4 5 422_05 yuechaotian5 6 422_06 yuechaotian6 7 422_07 yuechaotian7 8 422_08 yuechaotian8 9 422_09 yuechaotian9 10 422_10 yuechaotian10 11 422_11 yuechaotian11 12 422_12 yuechaotian12 13 422_13 yuechaotian13 14 422_14 yuechaotian14 15 422_15 yuechaotian15 16 422_16 yuechaotian16 17 422_17 yuechaotian17 18 422_18
yuechaotian18 |
序号 ID NAME 序号 ID
NAME |
SQL> create table
test_yct(id, name) as 2
select '422_0'||rownum, 'yuechaotian'||rownum from dual connect by rownum
<10; 表已创建。 SQL> insert into
test_yct 2
select '422_1'||(rownum-1), 'yuechaotian1'||(rownum-1) from dual connect
by rownum <10; 已创建9行。 SQL>
commit; 提交完成。 SQL> select * from
test_yct; ID NAME -----------
---------------- 422_01 yuechaotian1 422_02 yuechaotian2 422_03 yuechaotian3 422_04 yuechaotian4 422_05 yuechaotian5 422_06 yuechaotian6 422_07 yuechaotian7 422_08 yuechaotian8 422_09 yuechaotian9 422_10
yuechaotian10 422_11
yuechaotian11 422_12
yuechaotian12 422_13
yuechaotian13 422_14
yuechaotian14 422_15
yuechaotian15 422_16
yuechaotian16 422_17
yuechaotian17 422_18
yuechaotian18 已选择18行。 |
SQL> SELECT A.N, A.ID,
A.NAME, B.N, B.ID, B.NAME 2
FROM (SELECT N, ID, NAME 3
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 4
WHERE MOD(N, 2) = 1) A, 5
(SELECT N, ID, NAME 6
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 7
WHERE MOD(N, 2) = 0) B 8
WHERE A.N + 1 = B.N; N ID
NAME --- -------- ----------------
--- -------
-------------- 1 422_01
yuechaotian1 2 422_02
yuechaotian2 3 422_03
yuechaotian3 4 422_04
yuechaotian4 5 422_05
yuechaotian5 6 422_06
yuechaotian6 7 422_07
yuechaotian7 8 422_08
yuechaotian8 9 422_09
yuechaotian9 10 422_10
yuechaotian10 11 422_11
yuechaotian11 12 422_12
yuechaotian12 13 422_13
yuechaotian13 14 422_14
yuechaotian14 15 422_15
yuechaotian15 16 422_16
yuechaotian16 17 422_17
yuechaotian17 18 422_18
yuechaotian18 已选择9行。 |
SQL> SELECT a.n, A.id,
A.name, b.n, B.id, B.name 2
FROM (SELECT N, id, name 3
FROM (SELECT ROWNUM N, id, name FROM
test_yct) 4
WHERE MOD(FLOOR((N - 1) / 9), 2) = 0) A, 5
(SELECT N, id, name 6
FROM (SELECT ROWNUM N, id, name FROM
test_yct) 7
WHERE MOD(FLOOR((N - 1) / 9), 2) = 1) B 8
WHERE A.N + 9 = B.N; N ID NAME N ID
NAME 已选择9行。 |
SQL> insert into test_yct values('422_19', 'yuechaotian19');
已创建 1 行。
SQL> commit;
提交完成。
SQL> SELECT a.n, A.id,
A.name, b.n, B.id, B.name 2
FROM (SELECT N, id, name 3
FROM (SELECT ROWNUM N, id, name FROM
test_yct) 4
WHERE MOD(FLOOR((N - 1) / 9), 2) = 0) A, 5
(SELECT N, id, name 6
FROM (SELECT ROWNUM N, id, name FROM
test_yct) 7
WHERE MOD(FLOOR((N - 1) / 9), 2) = 1) B 8
WHERE A.N + 9 = B.N(+); N
ID NAME -- -------
------------- --- ------
------------- 1
422_01 yuechaotian1 10
422_10
yuechaotian10 2
422_02 yuechaotian2 11
422_11
yuechaotian11 3
422_03 yuechaotian3 12
422_12
yuechaotian12 4
422_04 yuechaotian4 13
422_13
yuechaotian13 5
422_05 yuechaotian5 14
422_14
yuechaotian14 6
422_06 yuechaotian6 15
422_15
yuechaotian15 7
422_07 yuechaotian7 16
422_16
yuechaotian16 8
422_08 yuechaotian8 17
422_17
yuechaotian17 9
422_09 yuechaotian9 18
422_18
yuechaotian18 19
422_19
yuechaotian19 |
SQL> insert into
test_yct 2
select '422_2'||(rownum-1),
'yuechaotian2'||(rownum-1) 3
from dual connect by rownum <10; 已创建9行。 SQL>
commit; 提交完成。 |
SQL> SELECT a.n, A.ID,
A.NAME, b.n, B.ID, B.NAME 2
FROM (SELECT N, ID, NAME 3
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 4
WHERE MOD(FLOOR((N - 1) / 6), 2) = 0) A, 5
(SELECT N, ID, NAME 6
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 7
WHERE MOD(FLOOR((N - 1) / 6), 2)
= 1) B 8
WHERE A.N + 6 = B.N(+) 9
AND a.n <= 6 10
UNION ALL 11
SELECT a.n, A.ID, A.NAME, b.n, B.ID, B.NAME 12
FROM (SELECT N, ID, NAME 13
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 14 WHERE n > 6 * 2 15
AND MOD(FLOOR((N - 6 * 2 -1) / 9), 2) = 0)
A, 16
(SELECT N, ID, NAME 17
FROM (SELECT ROWNUM N, ID, NAME FROM
test_yct) 18 WHERE n > 6 * 2 19 AND MOD(FLOOR((N - 6 * 2 - 1) /
9), 2) = 1) B 20
WHERE A.N + 9 = B.N(+); N
ID NAME --
------- -------------------- --- --- --------
-------- 1
422_01 yuechaotian1 7
422_07
yuechaotian7 2
422_02 yuechaotian2 8
422_08
yuechaotian8 3
422_03 yuechaotian3 9
422_09
yuechaotian9 4
422_04 yuechaotian4 10
422_10
yuechaotian10 5
422_05 yuechaotian5 11
422_11
yuechaotian11 6
422_06 yuechaotian6 12
422_12
yuechaotian12 13
422_13 yuechaotian13 22
422_22
yuechaotian22 14
422_14 yuechaotian14 23
422_23
yuechaotian23 15
422_15 yuechaotian15 24
422_24
yuechaotian24 16
422_16 yuechaotian16 25
422_25
yuechaotian25 17
422_17 yuechaotian17 26
422_26
yuechaotian26 18
422_18 yuechaotian18 27
422_27
yuechaotian27 19
422_19 yuechaotian19 28
422_28
yuechaotian28 20
422_20 yuechaotian20 21
422_21 yuechaotian21 已选择15行。 |
chinaunix网友2008-07-01 15:49:26
如果某张表中有100条记录,第一栏显示88条数据,第二栏显示12条记录,空缺的部分用0补齐,应该怎么写,请赐教,万分感谢!!