< Prev - Examples - Next >

Simple Scalar Types

Use Case

Update data of a single row.

Example Description

PL/SQL Package Specification : SCALAR_TYPES
create or replace package scalar_types
as

-- add two numbers and returns the result
function add_num(i_n1 in number, i_n2 in number) return number;

-- concat two strings and returns the result
function concat_char(i_s1 in varchar2, i_s2 in varchar2) return varchar2;
 
end scalar_types;
PL/SQL Package Body : SCALAR_TYPES
create or replace package body scalar_types
as

-- add two numbers and returns the result
function add_num(i_n1 in number, i_n2 in number) return number
is
begin
  return i_n1 + i_n2;
end add_num;

-- concat two strings and returns the result
function concat_char(i_s1 in varchar2, i_s2 in varchar2) return varchar2
is
begin
  return i_s1 || i_s2;
end concat_char;

end scalar_types;
Java Calling Class : ScalarTypes.java
package plsql_workbench_examples;

import factory.ExamplesRPCFactory;
import service.ScalarTypesService;

public class ScalarTypes {
  public static void main(String[] args) {
    try {
      // get the service
      ScalarTypesService service = ExamplesRPCFactory.getScalarTypesService();

      // call the stored procedure and prints the result
      int sum = service.addNum(1, 2);
      System.out.println("sum:" + sum);

      // call the stored procedure and prints the result
      String concat = service.concatChar("A", "B");
      System.out.println("concat:" + concat);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}