目次に戻る
APEXでのCHECKBOX(チェックボックス)の取扱
1.他のテーブル(名称マスター)とのマッチングのやりかた
(1列文字列から1行テーブルへ変換、その後マッチングしてまた1行文字列に戻す)
Goal ‐ 以下のように、チェックボックスの返り値とマスターをマッチングをする
#SQLサンプル
COLUMN FOODS を FUNCTION T_GET_NAME に渡して、名称リストを取得
#FUNCTION T_GET_NAME のSQL
#解説 - コロン(:)区切りのテキストを1行テーブルへ変換するSQL
(1列文字列から1行テーブルへ変換、その後マッチングしてまた1行文字列に戻す)
Goal ‐ 以下のように、チェックボックスの返り値とマスターをマッチングをする
#SQLサンプル
COLUMN FOODS を FUNCTION T_GET_NAME に渡して、名称リストを取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select ID | |
, USERNAME | |
, FOODS | |
, T_GET_NAME(FOODS) FOODS_NAME | |
from T_QA_SAMPLE; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID USERNAME FOODS FOODS_NAME | |
-------------------------------------------------------------------------- | |
41 APEX 1:2:4:5:6 Fried Rice, Hamburger, Ramen, Steak, Sushi | |
1 Toshi 1:2:5:6 Fried Rice, Ramen, Steak, Sushi | |
21 TEST 1:3:4 Hamburger, Pasta, Sushi | |
22 TEST2 5:6 Fried Rice, Steak |
#FUNCTION T_GET_NAME のSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function "T_GET_NAME" | |
(p_text in VARCHAR2) | |
return VARCHAR2 | |
is | |
l_codetext varchar2(2000); | |
BEGIN | |
SELECT LISTAGG(L.LOOKUP_NAME,', ') WITHIN GROUP (order by null) codetext | |
INTO l_codetext | |
FROM | |
--- INPUT された p_text を1列テーブルに変換し、テーブルSとする | |
(WITH TEMP AS (SELECT p_text IN_TEXT FROM dual) | |
SELECT trim(regexp_substr(IN_TEXT, '[^:]+', 1, LEVEL)) ID_LIST | |
FROM TEMP | |
CONNECT BY instr(IN_TEXT, ':', 1, LEVEL - 1) > 0) S | |
--- 名称マスタ を テーブルL とする | |
, T_LOOKUPS L | |
WHERE S.ID_LIST = L.G_SEQ; | |
return l_codetext; | |
END; |
#解説 - コロン(:)区切りのテキストを1行テーブルへ変換するSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT trim(regexp_substr(<文字列>, '[^<区切文字>]+', 1, LEVEL)) ID_LIST | |
FROM DUAL | |
CONNECT BY instr(<文字列>, <区切文字>, 1, LEVEL - 1) > 0; | |
-- この場合は、文字列が 1:2:5 で、区切り文字が: | |
SELECT trim(regexp_substr('1:2:5', '[^:]+', 1, LEVEL)) ID_LIST | |
FROM DUAL | |
CONNECT BY instr('1:2:5', ':', 1, LEVEL - 1) > 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID_LIST | |
-------- | |
1 | |
2 | |
5 |