INBOUND AND OUTBOUND INTERFACE
Inbound and outbound interfaces in an Oracle database refer to the processes of receiving data from
and sending data to external systems, respectively. Inbound interfaces bring data into the database,
often from legacy systems or other applications, while outbound interfaces extract data from the
database and send it to external systems or applications.
Inbound Interfaces:
Purpose: Import data into Oracle database tables from external sources.
Process: Typically involves reading data from flat files (e.g., CSV, XML) or other formats,
validating the data, and then loading it into staging tables or directly into Oracle base tables
using techniques like SQL*Loader, PL/SQL procedures, or Oracle APIs.
Examples:
o Loading customer data from a legacy system into an Oracle EBS Customer interface
tables.
o Importing sales order data from an external system into Oracle Applications tables.
o Migrating data from a non-Oracle database to an Oracle database.
Outbound Interfaces:
Purpose: Extract data from Oracle database tables and send it to external systems.
Process: Involves querying data from Oracle tables, formatting the data into a suitable
format (e.g., flat file, XML), and then transferring it to the external system using tools
like UTL_FILE, FTP, or APIs.
Examples:
o Generating a report of customer information from Oracle EBS and sending it to a
third-party reporting tool.
o Extracting inventory data from Oracle and sending it to a warehouse management
system.
o Sending order information from Oracle to a shipping provider.
Key Components and Technologies:
SQLLoader:*: A utility for loading data from flat files into Oracle tables.
PL/SQL: Oracle's procedural language for developing stored procedures, functions, and
triggers used in interface processing.
UTL_FILE: An Oracle package for reading and writing files.
APIs: Application Programming Interfaces (APIs) are used for interacting with Oracle
applications and modules.
Staging Tables: Temporary tables used to store data during the interface process, allowing
for validation and transformation before loading into base tables.
Interface Tables: Oracle tables designed to hold data specifically for the interface process,
often with validation rules.
Concurrent Programs: Oracle programs that can be scheduled to run automatically and
handle interface processing.
Adapters: Oracle technology that facilitates communication between different systems,
including inbound and outbound adapter services.
Inbound vs. Outbound:
The main difference lies in the direction of data flow:
Inbound: Data moves into the Oracle database.
Outbound: Data moves out of the Oracle database.
Both inbound and outbound interfaces are crucial for integrating Oracle databases with other
systems, enabling seamless data exchange and business process automation.
Example code: inbound and outbound interfaces in Oracle
1. Inbound interface (using SQL*Loader)
SQL*Loader is a popular utility for loading data from external files into Oracle database tables.
Scenario: Loading customer data from a CSV file into a staging table, and then into the main
customer table after validation.
Step 1: Create a staging table
sql
CREATE TABLE XX_CUSTOMER_STG (
CUSTOMER_ID VARCHAR2(10),
CUSTOMER_NAME VARCHAR2(50),
EMAIL VARCHAR2(100),
PHONE VARCHAR2(20),
STATUS VARCHAR2(10) DEFAULT 'NEW',
ERROR_MESSAGE VARCHAR2(4000)
);
Use code with caution.
Step 2: Create a data file (e.g., customer_data.csv)
C101,John Doe,[email protected],123-456-7890
C102,Jane Smith,[email protected],987-654-3210
C103,Peter Jones,,555-123-4567
Step 3: Create a SQL*Loader control file (e.g., customer_load.ctl)
LOAD DATA
INFILE 'customer_data.csv'
INSERT INTO TABLE XX_CUSTOMER_STG
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
CUSTOMER_ID,
CUSTOMER_NAME,
EMAIL,
PHONE
)
Step 4: Execute SQL*Loader from the command line
bash
sqlldr userid=username/password control=customer_load.ctl log=customer_load.log
Use code with caution.
Step 5: Process the staged data (PL/SQL procedure for validation and insertion)
sql
CREATE OR REPLACE PROCEDURE XX_PROCESS_CUSTOMER_STG AS
BEGIN
-- Update status and error messages for invalid records
UPDATE XX_CUSTOMER_STG
SET STATUS = 'ERROR',
ERROR_MESSAGE = 'Email is missing'
WHERE EMAIL IS NULL
AND STATUS = 'NEW';
-- Insert valid records into the main customer table
-- (Assuming a main customer table named 'CUSTOMERS' exists)
INSERT INTO CUSTOMERS (CUSTOMER_ID, CUSTOMER_NAME, EMAIL, PHONE)
SELECT CUSTOMER_ID, CUSTOMER_NAME, EMAIL, PHONE
FROM XX_CUSTOMER_STG
WHERE STATUS = 'NEW';
-- Update status for successfully processed records
UPDATE XX_CUSTOMER_STG
SET STATUS = 'PROCESSED'
WHERE STATUS = 'NEW';
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
-- Log the error
DBMS_OUTPUT.PUT_LINE('Error processing customer staging data: ' || SQLERRM);
END XX_PROCESS_CUSTOMER_STG;
-- Execute the PL/SQL procedure
BEGIN
XX_PROCESS_CUSTOMER_STG;
END;
Use code with caution.
This example outlines the basic steps involved in setting up an inbound interface using SQL*Loader
and a PL/SQL procedure for validation and data transfer.
2. Outbound interface (using UTL_FILE)
The UTL_FILE package allows writing data from Oracle tables to files on the server's operating
system, .
Scenario: Exporting employee details to a CSV file.
Step 1: Create a directory object in Oracle
sql
CREATE OR REPLACE DIRECTORY DATA_EXPORT_DIR AS '/u01/app/oracle/data_exports';
Use code with caution.
Ensure the Oracle database process has write permissions to
the /u01/app/oracle/data_exports directory on the database server.
Step 2: Grant necessary privileges
sql
GRANT READ, WRITE ON DIRECTORY DATA_EXPORT_DIR TO your_user;
Use code with caution.
Replace your_user with the actual database user who will execute the PL/SQL procedure.
Step 3: Create a PL/SQL procedure to generate the CSV file
sql
CREATE OR REPLACE PROCEDURE XX_GENERATE_EMPLOYEE_CSV AS
l_file_handle UTL_FILE.FILE_TYPE;
l_file_name VARCHAR2(100) := 'employee_data_' || TO_CHAR(SYSDATE, 'YYYYMMDD_HH24MISS')
|| '.csv';
l_dir_alias VARCHAR2(30) := 'DATA_EXPORT_DIR';
BEGIN
-- Open the file in write mode
l_file_handle := UTL_FILE.FOPEN(l_dir_alias, l_file_name, 'W');
-- Write the header row
UTL_FILE.PUT_LINE(l_file_handle, 'Employee ID,First Name,Last Name,Email,Hire Date,Salary');
-- Loop through employee data and write to the file
FOR emp_rec IN (SELECT employee_id, first_name, last_name, email, hire_date, salary FROM
employees ORDER BY employee_id) LOOP
UTL_FILE.PUT_LINE(l_file_handle,
emp_rec.employee_id || ',' ||
emp_rec.first_name || ',' ||
emp_rec.last_name || ',' ||
emp_rec.email || ',' ||
TO_CHAR(emp_rec.hire_date, 'YYYY-MM-DD') || ',' ||
emp_rec.salary
);
END LOOP;
-- Close the file
UTL_FILE.FCLOSE(l_file_handle);
DBMS_OUTPUT.PUT_LINE('Employee data exported to ' || l_dir_alias || '/' || l_file_name);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH THEN
DBMS_OUTPUT.PUT_LINE('Error: Invalid directory path.');
WHEN UTL_FILE.WRITE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('Error: Unable to write to file.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An unexpected error occurred: ' || SQLERRM);
END XX_GENERATE_EMPLOYEE_CSV;
-- Execute the PL/SQL procedure
BEGIN
XX_GENERATE_EMPLOYEE_CSV;
END;
Use code with caution.
In this example, the UTL_FILE.FOPEN function opens a file in the specified
directory, UTL_FILE.PUT_LINE writes data to the file, and UTL_FILE.FCLOSE closes it.
By using these examples as a starting point, you can adapt and expand them to implement more
sophisticated inbound and outbound interfaces based on your specific requirements and data
formats.