Sunday, September 5, 2021

Return table on function + object types + Oracle

Sometimes we need to function on oracle, return of table because propably you need to send dinamic parameters of query, you can resolve the problem with materialized view or view but both your parameters is define, then when you want change the params you can replace or create again. but with objetc types not is necessary.

I suggest you, to read to concept object types. because i only share the example but not concept.

Step 1. i create my real or exist table and insert. for this example.

CREATE TABLE my_real_table
     username VARCHAR2(25),
     age      NUMBER

INTO my_real_table (username, ageVALUES ('User1', 25)
INTO my_real_table (username, ageVALUES ('User2', 25)
INTO my_real_table (username, ageVALUES ('User3', 33)
INTO my_real_table (username, ageVALUES ('User4', 30)
INTO my_real_table (username, ageVALUES ('User5', 40)
FROM   dual; 

Step 2.

Create a object of your table.

CREATE OR replace TYPE obj_test AS object (
  username VARCHAR2(25),
  age      NUMBER ); 

Step 3.

Create a type of your object.

CREATE OR replace TYPE t_test

Step 4. Create of function with parameters and return the table depends on parameters.

CREATE OR replace FUNCTION Fu_test (v_age IN NUMBER)
  return_value T_TEST;
    SELECT Obj_test(username, age)
    bulk   collect INTO return_value
    FROM   (SELECT username,
            FROM   my_real_table
            WHERE  age > = v_age);

    RETURN return_value;

Step 4. you can send diferent parameters the function and return table. 

FROM   TABLE(Fu_test(30)); 

That it is.

Multiple Data Sources in Spring Boot 3 with Java 21

  In this blog post, we'll explore the configuration and setup for a Spring Boot 3 application with Java 21 that uses multiple data sour...