紀錄一下使用informix要以hardcode的方式產生虛擬資料的方式:
方法1:
select a,b
from TABLE (MULTISET(
select 1 as a, 1 as b from systables where tabid = 1 union all
select 2 as a, 1 as b from systables where tabid = 1 union all
select 3 as a, 2 as b from systables where tabid = 1 union all
select 4 as a, 2 as b from systables where tabid = 1
)) t;
方法2:
--多欄位
SELECT a, b
FROM TABLE (MULTISET {row(1, 1), row(2, 1), row(3, 2), row(4, 2)}) AS t(a, b);
--單欄位
SELECT a
FROM TABLE (MULTISET {1, 2, 3, 4}) AS t(a);
===============================================
這二種方法中,方法1是比較直覺,與其他家的資料庫系統比較類似,但要寫比較多code,比較繁雜,方法2比較簡潔一點。
可以參考 stackoverflow 的討論串
該討論串中也有提到對於批次新資料的方法,這個我還沒試,但先紀錄下來
INSERT INTO cccmte_pp ( cmte, pref, nro, eje, id_tri, id_cuo, fecha, vto1, vto2, id_tit, id_suj, id_bie, id_gru )
SELECT *
FROM TABLE (MULTISET {
row('RC', 4, 10, 2020, 1, 5, MDY(05,20,2020), MDY(05,20,2020),MDY(05,27,2020),101, 1, 96, 1 ),
row('RC', 4, 11, 2020, 1, 5, MDY(05,20,2020), MDY(05,20,2020),MDY(05,27,2020),101, 1, 96, 1 )
})
AS t( cmte, pref, nro, eje, id_tri, id_cuo, fecha, vto1, vto2, id_tit, id_suj, id_bie, id_gru )
另外也有人提到 Multiset不保證結果資料集會依順序呈現,如果要確保輸出依hardcode的資料順序的話可使用LIST
例如:
SELECT a
FROM TABLE(SET{1, 2, 3}) AS t(a)