What is SYS.ODCI (SYS.ODCINumberList or SYS.ODCIVarchar2List) and How Can Use it in APEX ?
⍰ What is SYS.ODCI...?
Oracle database provides predefined collection types, such as SYS.ODCINUMBERLIST and SYS.ODCIVARCHAR2LIST, which simplifies operations involving lists of numbers or strings.
SYS.ODCI designed for bulk operations and they are nested table types that store lists of numbers and strings, respectively.
⍰ Can we use SYS.ODCI instead of TABLE OF Types?
In some cases, you can use SYS.ODCI types like instead of defining your own nested table types. For example, if you need a collection of numbers or strings, you can use these system types instead of defining something like this yourself because User-defined types require explicit definitions. In contrast, SYS.ODCINUMBERLIST and similar predefined types are readily available and can be used both in PL/SQL and SQL contexts without additional definitions. But In general, For more complex structures (like objects with multiple attributes), you must use user-defined types instead of SYS.ODCI types.
These types facilitate the handling of collections without the need for user-defined types.๐๐
๐Let me say some usage and TIPS about it before looking at some examples :
You can use these types for Collecting values using
BULK COLLECTYou can use these types for batch inserts or deletes with
FORALL-
You can use these types of Direct usage in SQL statements with
TABLE() You can Pass lists as these parameters to procedures or functions
⍰ How we can Declare and Use SYS.ODCI...?
YES, When you need to retrieve multiple rows from a table into collections, BULK COLLECT can be utilized with these predefined types. For example, in below example, I am saying where department_id is 30, store employee_id, first_name into l_ids and l_names collections
⍰ Can we use FORALL for SYS.ODCI...?
FORALL allows for efficient bulk DML operations. For instance, in the below example, you can see deleting employees with IDs 101, 102, and 103 in a single operation.
⍰ How can we select from this collection types?
You can directly use them in SQL with TABLE()
⍰ How can we Use SYS.ODCI as Predefined Types in Stored Procedures?
Just simply Passing lists as parameters to stored procedures is straightforward with predefined types. The advantage of Using Predefined Types Over User-Defined Types is that predefined types are ready to use without the need for explicit creation. For example, below you can see a procedure that accepts a list of employee IDs and deletes the corresponding records efficiently using FORALL.
๐Now let's focus on ORACLE APEX๐
⍰ Use SYS.ODCI or APEX_STRING.SPLIT in ORACLE APEX ?
APEX_STRING.SPLIT for here is perfect, but Suppose you have a very large volume of data.
In summary For high-volume data, using SYS.ODCINumberList with FORALL outperforms APEX_STRING.SPLIT for bulk DML operations like updating salaries.
for example Imagine you're building an Oracle APEX application for searching articles or products or something like this and you have a large volume of data. Users can enter a list of keywords in a text field for example :P2_KEYWORDS, and you want to find articles that contain at least one of these keywords in their title or content.
PIPE ROW(v_keyword); v_remaining := SUBSTR(v_remaining, INSTR(v_remaining, v_delimiter) + 1); END LOOP; RETURN;END;
Then Create an Interactive report or Grid with below source code
SELECT ARTICLE_ID, TITLE, CONTENT
FROM ARTICLES
WHERE TITLE LIKE '%' || (SELECT COLUMN_VALUE FROM TABLE(split(:P2_KEYWORDS))) || '%'
OR CONTENT LIKE '%' || (SELECT COLUMN_VALUE FROM TABLE(split(:P2_KEYWORDS))) || '%';
Comments
Post a Comment