前面分享了mysql的写法,这里分享Hana内存数据库和Oracle数据库的写法.原理都是一样的。
HANA内存数据库写法:
CREATE PROCEDURE SPLIT_TEST(IN V_ROID DECIMAL,
TEXT NVARCHAR(1000))
AS
BEGIN
BEGIN
DELETE FROM ROLE_FUNCLIST WHERE ROLE_ID=:V_ROID;
END;
BEGIN
DECLARE _ITEMS NVARCHAR(1000) ARRAY;
DECLARE _TEXT NVARCHAR(1000);
DECLARE _INDEX INTEGER;
_TEXT := :TEXT;
_INDEX := 1;
WHILE LOCATE(:_TEXT,',') > 0 DO
_ITEMS[:_INDEX] := SUBSTR_BEFORE(:_TEXT,',');
INSERT INTO ROLE_FUNCLIST VALUES(:V_ROID,:_ITEMS[:_INDEX]);
_TEXT := SUBSTR_AFTER(:_TEXT,',');
_INDEX := :_INDEX + 1;
END WHILE;
INSERT INTO ROLE_FUNCLIST VALUES(:V_ROID,:_TEXT);
_ITEMS[:_INDEX] := :_TEXT;
RST = UNNEST(:_ITEMS) AS ("ITEMS");
SELECT * FROM :RST;
END;
END;
CREATE OR REPLACE PROCEDURE SP_STR(V_STR_1 IN VARCHAR2)
AS
V_START NUMBER :=1;
V_LOCATE NUMBER;
V_STR_BEFORE VARCHAR2(4000);
V_STR VARCHAR2(100):=V_STR_1;
BEGIN
WHILE INSTR(V_STR,',')>0 LOOP
V_LOCATE :=INSTR(V_STR,',');
V_STR_BEFORE :=SUBSTR(V_STR,V_START,V_LOCATE-V_START);
INSERT INTO T(NAME) VALUES(V_STR_BEFORE);
V_STR :=SUBSTR(V_STR,V_LOCATE+1);
END LOOP;
INSERT INTO T(NAME) VALUES(V_STR);
commit;
END;