0% found this document useful (0 votes)
51 views4 pages

Logger Log - Time: Create PL/SQL Package Procedure and Function: - Table To Wok With Procedure

This document describes how to create a PL/SQL package with a procedure and function, generate a Java class from an ADM application module, and expose the procedure and function for use in a Java Server Faces (JSF) page. Key steps include: 1. Creating a logger table and insert_into_logger procedure. 2. Creating a get_emp_fullname function to return a concatenated employee name. 3. Generating a Java class from the ADM and adding code to call stored procedures/functions. 4. Exposing the procedure and function on the ADM client interface. 5. Dragging the procedure as a button and function as a parameter form onto a

Uploaded by

Sarfaraz Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Logger Log - Time: Create PL/SQL Package Procedure and Function: - Table To Wok With Procedure

This document describes how to create a PL/SQL package with a procedure and function, generate a Java class from an ADM application module, and expose the procedure and function for use in a Java Server Faces (JSF) page. Key steps include: 1. Creating a logger table and insert_into_logger procedure. 2. Creating a get_emp_fullname function to return a concatenated employee name. 3. Generating a Java class from the ADM and adding code to call stored procedures/functions. 4. Exposing the procedure and function on the ADM client interface. 5. Dragging the procedure as a button and function as a parameter form onto a

Uploaded by

Sarfaraz Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Create PL/SQL Package Procedure and function:

Note: for sake of understanding i am keeping things simple


--Table to wok with Procedure.
createtablelogger
(log_timetimestamp)
tablespaceusers;
-- Procedure
createorreplaceprocedureinsert_into_loggeras
pragmaautonomous_transaction;
begin
insertintologger
values(systimestamp);
commit;
endinsert_into_logger;

-- Function

createorreplacefunctionget_emp_fullname(empidinnumber)returnvarchar2
as
v_full_namevarchar2(120);
begin
selectfirst_name||''||last_name
intov_full_name
fromemployees
whereemployee_id=empid;

returnv_full_name;
exception
whenno_data_foundthen
returnnull;
endget_emp_fullname;

Go to Model and Generate the java class of the Application Module.

Now open the Application Module.java file and paste the below code.

private static int VARCHAR2 = Types.VARCHAR;


protected Object callStoredFunction(int sqlReturnType, String stmt,
Object[] bindVars) {
CallableStatement st = null;
try {
// 1. Create a JDBC CallabledStatement
st =
getDBTransaction().createCallableStatement("begin ? := " + stmt + ";end;",
0);
// 2. Register the first bind variable for the return value
st.registerOutParameter(1, sqlReturnType);
if (bindVars != null) {
// 3. Loop over values for the bind variables passed in, if any
for (int z = 0; z < bindVars.length; z++) {
// 4. Set the value of user-supplied bind vars in the stmt
st.setObject(z + 2, bindVars[z]);
}
}
// 5. Set the value of user-supplied bind vars in the stmt
st.executeUpdate();
// 6. Return the value of the first bind variable

return st.getObject(1);
} catch (SQLException e) {
throw new JboException(e);
} finally {
if (st != null) {
try {
// 7. Close the statement
st.close();
} catch (SQLException e) {
Number a ;
}
}
}
}

Put below methods also in the java file

public String getEmpFullName(Number n) {


return (String)callStoredFunction(VARCHAR2, "get_emp_fullname(?)",
new Object[] { n });
}

public void logProcedure() {


getDBTransaction().executeCommand("begin insert_into_logger; end;");
}

Go to again Application Module and below Java class and click Client Interface
to Expose methods on Client interface. Shuttle the methods to selected area
and Click OK

Now create a JSF page and drag and drop the Logprocedure as a ADF Button
and test it.

Drag the getEmpFullname function to the page and choose ADF parameter form (it is a function
so we have to bind the input and return values)

Drag and drop the String (output parameter) as Output Text

Output

The page on design time look like this

You might also like