Advertisement
Guest User

Untitled

a guest
Sep 7th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.51 KB | Source Code | 0 0
  1. DECLARE
  2.     --Type tableType is table of varchar2(500);
  3.     --fixed the error, so i made a custom type outside of the anonymous block.
  4.     roomsDescr ARRAY_VALUE;
  5.     roomsCode ARRAY_VALUE;
  6.     rooms VARCHAR2(4000) := 'room1;01|room2;02|room3;03|room4;04';
  7. BEGIN
  8.     DBMS_OUTPUT.ENABLE;
  9.     WITH regxRooms AS (
  10.         SELECT REGEXP_SUBSTR(rooms, '[^|]+', 1, LEVEL) AS room
  11.         FROM dual CONNECT BY REGEXP_SUBSTR(rooms, '[^|]+', 1, LEVEL) IS NOT NULL
  12.     )
  13.     SELECT
  14.         (REGEXP_SUBSTR(regxRooms.room, '[^;]+', 1, 1)) AS DESCR ,
  15.         (REGEXP_SUBSTR(regxRooms.room, '[^;]+', 1, 2)) AS CODE
  16.         BULK COLLECT INTO roomsDescr, roomsCode
  17.     FROM regxRooms;
  18.     DBMS_OUTPUT.PUT_LINE(roomsDescr.FIRST); --somehow the output line doesn't print anything?? but it says that the block was completed successfully...
  19.     FOR idx IN roomsDescr.FIRST..roomsDescr.LAST
  20.     LOOP
  21.         /*Here i would insert them, each insert will have to return me the row ID.*/
  22.         DBMS_OUTPUT.PUT_LINE(roomsDescr(idx));
  23.         DBMS_OUTPUT.PUT_LINE(roomsCode(idx));
  24.         --insert into rooms returning rooms.id into roomId;
  25.         --with the roomId, i'll need to do something like i did for the rooms and cycle through a "bed" "object"
  26.         --made the same way as the rooms one (string separated by ; and |).
  27.         /* Example, after inserting the room and inside this LOOP.
  28.             for bedsIdx in bedDescr.first...bedDescr.last -> insert into beds bedDescr(idx), bedCode(idx),roomId
  29.         */
  30.     END LOOP;
  31. END;
Tags: PL/SQL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement