I want to ask you something. I am inserting data from multiple values from checkbox group to Table. It is inserting like value1:value2 but I want to insert single row per one value. Like Insert INTO table(column) values(value1); Insert INTO table(column) values(value2); but it would be 5 piece value, it would be 0 piece value so it is need to be dynamic and insert one by one for each value. How can i do that can you help me about it ?
DECLARE -- Assume that :P1_CHECKBOX is the page item holding the checkbox group values. l_checkbox_values apex_t_varchar2; -- Table to store split values BEGIN -- Split the checkbox group values (stored as colon-separated string) l_checkbox_values := apex_string.split(:P1_CHECKBOX, ':'); -- Loop through each value in the split array FOR i IN 1..l_checkbox_values.count LOOP -- Insert each value into the table INSERT INTO your_table (column_name) VALUES (l_checkbox_values(i)); END LOOP; -- Optionally commit if not handled by Oracle APEX automatically COMMIT; END; Explanation: 1) apex_string.split(:P1_CHECKBOX, ':'): Splits the checkbox values stored in :P1_CHECKBOX into an array based on the colon delimiter : that separates multiple values. 2) FOR i IN 1..l_checkbox_values.count LOOP: Loops through each value in the split array. 3) INSERT INTO your_table (column_name) VALUES (l_checkbox_values(i));: Inserts each value into the table, creating a new row for each value.
First of all thanks for answer to me. I check your code and it is not worked in my project. I want to share to my code. This code is working when they selected only 1 value from checkbox group. But I want to configure that for multiple checkbox values. I want to explain correctly my issue. More than 1 value can be inserted into the P4_CHEESE, P4_SEBZE, P4_ET, P4_TATLI, P4_MEYVE checkbox group, that is, the MATERIAL column in this code. For example, while there is only kashar insert; Kashar:cream:old data can also be inserted into this column. If a multiple insert comes first, these data must be separated from the : sign and inserted separately with v_price_malzeme, v_malzeme_dv and v_tip variables for each separated material. In other words, I want x material to be inserted into x number of rows, not into a single row. CODE: BEGIN -- Değişkenleri tanımlayın DECLARE v_fiyat_malzeme T_MALZEME.FIYAT_MALZEME%TYPE; v_malzeme_dv T_MALZEME.MALZEME%TYPE; v_tip_malzeme T_MALZEME.TIP_MALZEME%TYPE; BEGIN -- Ekmek için veri seç IF :P4_EKMEK IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_EKMEK; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Peynir için veri seç IF :P4_PEYNIR IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_PEYNIR; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Sebze için veri seç IF :P4_SEBZE IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_SEBZE; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Et için veri seç IF :P4_ET IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_ET; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Tatlı için veri seç IF :P4_TATLI IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_TATLI; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Meyve için veri seç IF :P4_MEYVE IS NOT NULL THEN SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = :P4_MEYVE; INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END IF; -- Değişiklikleri onayla COMMIT; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('Veri bulunamadı.'); WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Bir hata oluştu: ' || SQLERRM); ROLLBACK; -- Hatada değişiklikleri geri al END; END;
try this one DECLARE -- Declare necessary variables v_fiyat_malzeme T_MALZEME.FIYAT_MALZEME%TYPE; v_malzeme_dv T_MALZEME.MALZEME%TYPE; v_tip_malzeme T_MALZEME.TIP_MALZEME%TYPE; v_malzeme_list APEX_APPLICATION_GLOBAL.VC_ARR2; v_malzeme_item VARCHAR2(4000); -- Local procedure definition PROCEDURE process_material(p_material IN VARCHAR2) IS BEGIN -- Split the selected values by ':' delimiter into an array v_malzeme_list := APEX_STRING.SPLIT(p_material, ':'); -- Loop through each item in the list and insert it separately FOR i IN 1..v_malzeme_list.COUNT LOOP v_malzeme_item := v_malzeme_list(i); -- Select the corresponding details for each material SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme FROM PBA_SND.T_MALZEME WHERE ID_MALZEME = v_malzeme_item; -- Insert the data into the T_SEPET table INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET) VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET); END LOOP; END process_material; -- End of local procedure BEGIN -- Now call the procedure wherever required IF :P4_EKMEK IS NOT NULL THEN process_material(:P4_EKMEK); -- Call the procedure END IF; IF :P4_PEYNIR IS NOT NULL THEN process_material(:P4_PEYNIR); -- Call the procedure END IF; -- Other checkbox groups IF :P4_SEBZE IS NOT NULL THEN process_material(:P4_SEBZE); -- Call the procedure END IF; IF :P4_ET IS NOT NULL THEN process_material(:P4_ET); -- Call the procedure END IF; IF :P4_TATLI IS NOT NULL THEN process_material(:P4_TATLI); -- Call the procedure END IF; IF :P4_MEYVE IS NOT NULL THEN process_material(:P4_MEYVE); -- Call the procedure END IF; -- Commit transaction COMMIT; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM); ROLLBACK; END;
I want to ask you something. I am inserting data from multiple values from checkbox group to Table. It is inserting like value1:value2 but I want to insert single row per one value. Like Insert INTO table(column) values(value1); Insert INTO table(column) values(value2); but it would be 5 piece value, it would be 0 piece value so it is need to be dynamic and insert one by one for each value. How can i do that can you help me about it ?
DECLARE
-- Assume that :P1_CHECKBOX is the page item holding the checkbox group values.
l_checkbox_values apex_t_varchar2; -- Table to store split values
BEGIN
-- Split the checkbox group values (stored as colon-separated string)
l_checkbox_values := apex_string.split(:P1_CHECKBOX, ':');
-- Loop through each value in the split array
FOR i IN 1..l_checkbox_values.count LOOP
-- Insert each value into the table
INSERT INTO your_table (column_name)
VALUES (l_checkbox_values(i));
END LOOP;
-- Optionally commit if not handled by Oracle APEX automatically
COMMIT;
END;
Explanation:
1) apex_string.split(:P1_CHECKBOX, ':'): Splits the checkbox values stored in :P1_CHECKBOX into an array based on the colon delimiter : that separates multiple values.
2) FOR i IN 1..l_checkbox_values.count LOOP: Loops through each value in the split array.
3) INSERT INTO your_table (column_name) VALUES (l_checkbox_values(i));: Inserts each value into the table, creating a new row for each value.
@@TechProbie I solved then problem
First of all thanks for answer to me. I check your code and it is not worked in my project.
I want to share to my code. This code is working when they selected only 1 value from checkbox
group. But I want to configure that for multiple checkbox values. I want to explain correctly
my issue. More than 1 value can be inserted into the P4_CHEESE, P4_SEBZE, P4_ET, P4_TATLI,
P4_MEYVE checkbox group, that is, the MATERIAL column in this code. For example, while there
is only kashar insert; Kashar:cream:old data can also be inserted into this column. If a multiple
insert comes first, these data must be separated from the : sign and inserted separately with
v_price_malzeme, v_malzeme_dv and v_tip variables for each separated material. In other words,
I want x material to be inserted into x number of rows, not into a single row.
CODE:
BEGIN
-- Değişkenleri tanımlayın
DECLARE
v_fiyat_malzeme T_MALZEME.FIYAT_MALZEME%TYPE;
v_malzeme_dv T_MALZEME.MALZEME%TYPE;
v_tip_malzeme T_MALZEME.TIP_MALZEME%TYPE;
BEGIN
-- Ekmek için veri seç
IF :P4_EKMEK IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_EKMEK;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Peynir için veri seç
IF :P4_PEYNIR IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_PEYNIR;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Sebze için veri seç
IF :P4_SEBZE IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_SEBZE;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Et için veri seç
IF :P4_ET IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_ET;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Tatlı için veri seç
IF :P4_TATLI IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_TATLI;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Meyve için veri seç
IF :P4_MEYVE IS NOT NULL THEN
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = :P4_MEYVE;
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END IF;
-- Değişiklikleri onayla
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Veri bulunamadı.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Bir hata oluştu: ' || SQLERRM);
ROLLBACK; -- Hatada değişiklikleri geri al
END;
END;
try this one
DECLARE
-- Declare necessary variables
v_fiyat_malzeme T_MALZEME.FIYAT_MALZEME%TYPE;
v_malzeme_dv T_MALZEME.MALZEME%TYPE;
v_tip_malzeme T_MALZEME.TIP_MALZEME%TYPE;
v_malzeme_list APEX_APPLICATION_GLOBAL.VC_ARR2;
v_malzeme_item VARCHAR2(4000);
-- Local procedure definition
PROCEDURE process_material(p_material IN VARCHAR2) IS
BEGIN
-- Split the selected values by ':' delimiter into an array
v_malzeme_list := APEX_STRING.SPLIT(p_material, ':');
-- Loop through each item in the list and insert it separately
FOR i IN 1..v_malzeme_list.COUNT LOOP
v_malzeme_item := v_malzeme_list(i);
-- Select the corresponding details for each material
SELECT FIYAT_MALZEME, MALZEME, TIP_MALZEME
INTO v_fiyat_malzeme, v_malzeme_dv, v_tip_malzeme
FROM PBA_SND.T_MALZEME
WHERE ID_MALZEME = v_malzeme_item;
-- Insert the data into the T_SEPET table
INSERT INTO PBA_SND.T_SEPET (TIP_MALZEME, MALZEME, FIYAT_MALZEME, SECIM_MUSTERI, ADET)
VALUES(v_tip_malzeme, v_malzeme_dv, v_fiyat_malzeme, 'Kendi Seçimin', :P4_ADET);
END LOOP;
END process_material; -- End of local procedure
BEGIN
-- Now call the procedure wherever required
IF :P4_EKMEK IS NOT NULL THEN
process_material(:P4_EKMEK); -- Call the procedure
END IF;
IF :P4_PEYNIR IS NOT NULL THEN
process_material(:P4_PEYNIR); -- Call the procedure
END IF;
-- Other checkbox groups
IF :P4_SEBZE IS NOT NULL THEN
process_material(:P4_SEBZE); -- Call the procedure
END IF;
IF :P4_ET IS NOT NULL THEN
process_material(:P4_ET); -- Call the procedure
END IF;
IF :P4_TATLI IS NOT NULL THEN
process_material(:P4_TATLI); -- Call the procedure
END IF;
IF :P4_MEYVE IS NOT NULL THEN
process_material(:P4_MEYVE); -- Call the procedure
END IF;
-- Commit transaction
COMMIT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);
ROLLBACK;
END;