How to call procedure with package type param in oracle?

by herminia_bruen , in category: MySQL , 6 months ago

How to call procedure with package type param in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 6 months ago

@herminia_bruen 

To call a procedure with a package type parameter in Oracle, you can follow these steps:

  1. Create a package that contains the type definition and the procedure you want to call. Here is an example:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
CREATE OR REPLACE PACKAGE package_name AS
    TYPE type_name IS RECORD (
        field1 NUMBER,
        field2 VARCHAR2(50)
    );

    PROCEDURE procedure_name(param IN type_name);
END package_name;
/

CREATE OR REPLACE PACKAGE BODY package_name AS
    PROCEDURE procedure_name(param IN type_name) IS
    BEGIN
        -- Your procedure logic here
        NULL;
    END procedure_name;
END package_name;
/


  1. Once you have created the package, you can call the procedure in the following way:
1
2
3
4
5
6
7
8
DECLARE
    p type_name;
BEGIN
    p.field1 := 1;
    p.field2 := 'example';
    
    package_name.procedure_name(p);
END;


Make sure to replace package_name, type_name, and procedure_name with the actual names you have defined in your package. This way, you can call a procedure with a package type parameter in Oracle.