Skip to main content
ubuntuask.com

Back to all posts

How to Return Two Types In Pl/Sql Oracle?

Published on
3 min read
How to Return Two Types In Pl/Sql Oracle? image

Best PL/SQL Oracle Guides to Buy in October 2025

1 Murach's Oracle SQL and PL/SQL for Developers

Murach's Oracle SQL and PL/SQL for Developers

BUY & SAVE
$42.27 $54.50
Save 22%
Murach's Oracle SQL and PL/SQL for Developers
2 Oracle PL / SQL For Dummies

Oracle PL / SQL For Dummies

  • AFFORDABLE PRICES FOR QUALITY READS-GREAT FOR BUDGET SHOPPERS!
  • ECO-FRIENDLY CHOICE: REDUCE WASTE BY BUYING USED BOOKS!
  • UNIQUE FINDS: DISCOVER RARE TITLES AND HIDDEN LITERARY GEMS!
BUY & SAVE
$13.96 $31.99
Save 56%
Oracle PL / SQL For Dummies
3 Oracle PL/SQL by Example (The Oracle Press Database and Data Science)

Oracle PL/SQL by Example (The Oracle Press Database and Data Science)

BUY & SAVE
$55.91 $69.99
Save 20%
Oracle PL/SQL by Example (The Oracle Press Database and Data Science)
4 Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life

Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life

  • QUALITY ASSURANCE: CAREFULLY INSPECTED FOR GOOD CONDITION AND READABILITY.
  • ECO-FRIENDLY CHOICE: PROMOTE SUSTAINABILITY BY BUYING USED BOOKS.
  • COST-EFFECTIVE: SAVE MONEY WHILE ENJOYING YOUR FAVORITE READS!
BUY & SAVE
$14.27 $29.99
Save 52%
Oracle PL/SQL Best Practices: Write the Best PL/SQL Code of Your Life
5 Oracle PL/SQL Programming: Covers Versions Through Oracle Database 12c

Oracle PL/SQL Programming: Covers Versions Through Oracle Database 12c

BUY & SAVE
$45.02 $79.99
Save 44%
Oracle PL/SQL Programming: Covers Versions Through Oracle Database 12c
6 Murach's Oracle SQL and PL/SQL (3rd Edition): Training and Reference

Murach's Oracle SQL and PL/SQL (3rd Edition): Training and Reference

BUY & SAVE
$49.47
Murach's Oracle SQL and PL/SQL (3rd Edition): Training and Reference
7 Oracle PL/SQL Language Pocket Reference: A Guide to Oracle's PL/SQL Language Fundamentals

Oracle PL/SQL Language Pocket Reference: A Guide to Oracle's PL/SQL Language Fundamentals

BUY & SAVE
$8.32 $19.99
Save 58%
Oracle PL/SQL Language Pocket Reference: A Guide to Oracle's PL/SQL Language Fundamentals
8 Oracle APEX 20 Full Stack Set For Beginners: Oracle APEX 20, SQL and PL/SQL Beginners Guides To Develop Stunning, Low-Code Web Applications Fast

Oracle APEX 20 Full Stack Set For Beginners: Oracle APEX 20, SQL and PL/SQL Beginners Guides To Develop Stunning, Low-Code Web Applications Fast

BUY & SAVE
$40.00
Oracle APEX 20 Full Stack Set For Beginners: Oracle APEX 20, SQL and PL/SQL Beginners Guides To Develop Stunning, Low-Code Web Applications Fast
9 Oracle Database 12c PL/SQL Programming

Oracle Database 12c PL/SQL Programming

BUY & SAVE
$37.20 $83.00
Save 55%
Oracle Database 12c PL/SQL Programming
+
ONE MORE?

In PL/SQL Oracle, it is not possible to return multiple values of different types from a function or procedure. However, you can achieve this by using a user-defined datatype, a record type, or by returning a collection (such as a nested table or a varray) that contains multiple values of different types.

For example, you can create a record type that contains fields for each of the values you want to return, and then return an instance of this record type from your function or procedure. Alternatively, you can use a nested table or varray to store the multiple values of different types and return it from your function or procedure.

Overall, returning multiple values of different types in PL/SQL Oracle requires some creativity and the use of complex data structures.

How to return two types in PL/SQL Oracle using a procedure?

In PL/SQL Oracle, you can return multiple types using a record type or by creating a custom type to hold the values you want to return. Here is an example using a procedure:

  1. Create a custom type to hold the values you want to return:

CREATE OR REPLACE TYPE return_values AS OBJECT ( result1 VARCHAR2(50), result2 NUMBER );

  1. Create a procedure that uses the custom type to return the values:

CREATE OR REPLACE PROCEDURE get_values (p_input VARCHAR2, p_output OUT return_values) AS BEGIN -- Perform some operations to get the values p_output := return_values('Value1', 100); END;

  1. Call the procedure and retrieve the values:

DECLARE v_result return_values; BEGIN get_values('input_value', v_result);

-- Output the values
dbms\_output.put\_line('Result 1: ' || v\_result.result1);
dbms\_output.put\_line('Result 2: ' || v\_result.result2);

END;

In this example, the get_values procedure accepts an input parameter and returns two values using the custom type return_values. The procedure sets the values of result1 and result2 before returning them. In the calling block, you can access and display the returned values.

How to return a Boolean value in PL/SQL Oracle?

In PL/SQL Oracle, you can return a Boolean value by defining a function that returns a Boolean data type. Here is an example of how to create a function that returns a Boolean value:

CREATE OR REPLACE FUNCTION is_even(num IN NUMBER) RETURN BOOLEAN IS BEGIN IF MOD(num, 2) = 0 THEN RETURN TRUE; ELSE RETURN FALSE; END IF; END; /

In this example, the function is_even takes a numeric input num and checks if it is even by using the MOD function to calculate the remainder when dividing num by 2. If the remainder is 0, the function returns TRUE, indicating that the number is even. Otherwise, it returns FALSE.

You can call this function in a PL/SQL block or SQL query to get the Boolean result. For example:

DECLARE result BOOLEAN; BEGIN result := is_even(10); IF result THEN DBMS_OUTPUT.PUT_LINE('The number is even'); ELSE DBMS_OUTPUT.PUT_LINE('The number is odd'); END IF; END; /

In this code snippet, the is_even function is called with the argument 10, and the result is stored in the result variable. Depending on the value returned by the function, it will print out whether the number is even or odd.

How to return a JSON object in PL/SQL Oracle?

In PL/SQL Oracle, you can return a JSON object using the JSON_OBJECT function. Here is an example:

DECLARE json_obj JSON_OBJECT_T; BEGIN json_obj := JSON_OBJECT_T('{"name" : "John", "age" : 30}'); DBMS_OUTPUT.PUT_LINE(json_obj.TO_STRING); END; /

In this example, we are creating a JSON object with the properties "name" and "age" and then using the TO_STRING method to output the JSON object as a string. You can customize the properties and values of the JSON object based on your requirements.