Sunday, November 4, 2012

Master Note for Enterprise Manager Configuration Assistant (EMCA) in Single Instance Database Environment [ID1099271.1]


In this Document
Purpose
Scope
Details
All About EMCA
1. EMCA Concepts
2. EMCA Syntax
3. Pre-requisites for running EMCA command
How to Perform EMCA Operations
1. How to create DBConsole using EMCA ?
2. How to drop DBConsole using EMCA or manually (with and without repository)
3. How to re-create DBConsole using EMCA?
4. How to change ports for DBConsole using EMCA commands?
Diagnostic Tools
Troubleshooting EMCA Failures
1. EMCA failing while connecting to Database
2. EMCA failing due to Oracle Home software related issues
3. EMCA failing due to Hostname and Port related issues
4. EMCA failing due to Database or OS configuration
5. EMCA failing due to SYSMAN and other existing objects during re-configuration
References
Applies to:
Enterprise Manager for Oracle Database - Version 10.2.0.1 to 11.2.0.3 [Release 10.2 to 11.2]
Information in this document applies to any platform.
Purpose
This Master Note helps to understand EMCA utility used to perform DBConsole configurations and provides assistance in using diagnostics effectively to
debug/troubleshoot and resolve issues encountered.
Attention: In Enterprise Manager Database Control with Oracle Database 10.2.0.4 and 10.2.0.5, the root certificate used to secure communications
via the Secure Socket Layer (SSL) protocol expired on 31-Dec-2010 00:00:00. The certificate expiration will cause errors if you attempt to configure
Database Control on or after 31-Dec-2010.
Existing Database Control configurations are not affected by this issue. If you are in the following situations:
* Have an existing Oracle Database 10.2.0.4 or 10.2.0.5 installation and plan to configure or re-configure Database Control on or after 31-Dec-2010.
Database Control is configured when using one of the following tools:
• Database Configuration Assistant (DBCA)
• Database Upgrade Assistant (DBUA)
• Enterprise Manager Configuration Assistant (EMCA)
* Plan to install Oracle Database 10.2.0.4 or 10.2.0.5 on or after 31-Dec-2010 and intend to configure Database Control
then refer to Note: 1217493.1
Scope
This document is intended to assist Database Administrators to effectively troubleshoot EMCA failures in different scenarios. This document covers the
following topics:
About EMCA
How to Perform EMCA Operations
Diagnostic Tools
Troubleshooting EMCA Failures
Details
All About EMCA
1. EMCA Concepts11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 2/ 12
Oracle Database can be monitored using Enterprise Manager Database Control or Enterprise Manager Grid Control. Enterprise Manager
Grid Control is a central monitoring and administration console to monitor number of Oracle Databases along with other Oracle and non Oracle
products. Enterprise Manager Database Control is standalone management console which can monitor and administer a single-instance /
clustered Oracle Database. The Database control is installed as part of Oracle Database (RDBMS) software. The Enterprise Manager Database
Control is popularly referred to as Database Control or DBControl or DBConsole. The terms are interchangeably used in rest of the associated
documents.
When Database Configuration Assistant (DBCA) is used for creating a database, it provides an option for the user to choose whether the
Enterprise Manager Database Control should be configured for the database. If the Database is created manually or if the appropriate
option was not chosen in the DBCA, then the Database Control can be configured from the command line using the Enterprise Manager
Configuration Assistant (EMCA) utility.
EMCA is a command line utility that provides simple and standardized options to create / drop/ re-configure the Database Control.
The EMCA is also referred to as EMCP (Enterprise Manager Configuration Plug-in).
Major difference between DBCA and EMCA is that DBCA does not provide any options to re-configure the DBControl where as EMCA can
perform all possible customizations for existing DBControl.
Note: The scope of this document does not include usage of DBCA for DBControl configuration but will cover only the EMCA.
How to Execute EMCA
The EMCA utility can be launched by running emca command from /bin. The EMCA command invokes the
$ORACLE_HOME/bin/emca script on Unix and %ORACLE_HOME%\bin\emca.bat on windows
On Unix host to launch the utility:
prompt > cd /bin
prompt > ./emca
On Windows host to launch the utility:
CMD> cd %ORACLE_HOME%\bin
CMD> emca
2. EMCA Syntax
The syntax can be obtained by executing emca –help or emca –h option. In addition, executing EMCA without any parameters also lists the
syntax.
Below diagram explains about the EMCA command line syntax.
EMCA command line options can be of following category.
- Operation: EMCA Command-Line Operation to be performed. For more details about each operation refer “EMCA Command-Line
Operations”
- Mode: The mode of the command, like dbcontrol, centralAgent, all, or ports. For more details about each mode refer “EMCA CommandLine Operations"
- Flags: EMCA Command-Line Flags. For more details about each flag refer “EMCA Command-Line Flags”
- Parameters: Optional Parameters if required. For more details about each parameter refer “EMCA Command-Line
Parameters”11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 3/ 12
Important Configuration Files
Following important configuration files are read by EMCA command for its operations. These files are used as templates for DBConsole
configuration and creation.
/sysman/config/emca.properties
/sysman/config/emcalog.properties
/sysman/config/emoms.properties.emca
/sysman/config/emd.properties.emca
Where to find EMCA log files?
Every execution of EMCA command generates EMCA log files. These log files are located at:
For 10.2 Database: /cfgtoollogs/emca/
For 11.1 and 11.2 Database: /cfgtoollogs/emca/
If DBConsole is configured using DBCA, all the logging messages are written to the emConfig.log file.
For a 10g Database the emConfig.log is generated under /cfgtoollogs/dbca/
For a 11g Database the emConfig.log is generated under /cfgtoollogs/dbca/
When Database is upgraded using DBUA, the DBConsole configuration is upgraded by default as part of Database upgrade process. All the
DBConsole upgrade logging messages are written to the emConfig.log file.
For a 10g Database the emConfig.log is generated under /cfgtoollogs/dbua/
For a 11g Database the emConfig.log is generated under /cfgtoollogs/dbua/
The EMCA log file is in the format emca_.log where timestamp is in the format: YYYY_MM_DD_HH24_MI_SS.log
For Example: emca_2010_05_17_20_56_33.log
When EMCA is used to create / drop repository, the repository specific actions are logged in emca_repos_create_.log or
emca_repos_drop_.log while the normal EMCA logging is written to emca_.log
For example : emca -deconfig dbcontrol db -repos drop
command will generate emca_repos_drop_2010_05_17_20_57_00.log under ../cfgtoollogs/emca/
and
emca -config dbcontrol db -repos create
command will generate emca_repos_create_2010_05_17_21_50_31.log under ../cfgtoollogs/emca/
3. Pre-requisites for running EMCA command
Mandatory pre-requisite checks are:
1. The following environment variables must be set:
On Unix
prompt > export ORACLE_HOME=
prompt > export ORACLE_SID=
On Windows
CMD> set ORACLE_HOME=
CMD> set ORACLE_SID=
2. The database and its listener should be up and running while running EMCA commands as the utility makes connection to the database
as "SYS as SYSDBA" or SYSMAN user. This connection is established via the listener for few operations where as bequeath connection is
used for others.
Complete list of pre-requisite checks is documented in Note 1113343.1 Pre-requisites for Successful Execution of EMCA Commands in
Single Instance Database Environment.
Flow of EMCA Command
Below diagram illustrates the flow of EMCA command for DBConsole create and drop operations.
EMCA Create DBConsole Flow EMCA Drop DBConsole Flow11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 4/ 12
Impact of EMCA drop or recreate operation on Database
IMPORTANT: When EMCA utility is used to drop or recreate the repository, it would put the database in quiesce mode without any warning
or taking confirmation from user. This behavior is seen in release 10.2.0.1 to 10.2.0.4 and 11.1.0.6 to 11.1.0.7. However, in release 10.2.0.5
this has been modified and EMCA utility displays warning and seeks confirmation for the database to be put in Quiesce mode.
Starting from 11.2.0.1.0 release, the database is NOT put into quiesce mode anymore for repository drop and recreate operation.
This means that EMCA "drop" and "recreate" commands can be executed for 11.2.x.x database without impacting normal database
operations.
Back to Top
=================================================================================================
How to Perform EMCA Operations
The most common operations performed using EMCA utility are
1. Create DBConsole
2. Drop DBConsole
3. Configure DBConsole with an existing repository
4. Reconfigure DBConsole without dropping the repository
5. Reconfiguration of DBConsole ports.11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 5/ 12
Before running any of the EMCA commands ensure all the pre-requisites are met as per Note 1113343.1 Pre-requisites for Successful Execution of EMCA
Commands in Single Instance Database Environment
1. How to create DBConsole using EMCA ?
How to configure/create DBConsole along with the repository?
For a database, if there is no DBConsole configured, run following command to configure DBConsole along with the repository.
To verify if the DBConsole is configured for the Database, refer to Note 740157.1 How To Verify Database Console Software is Installed and
Database Console is Configured For a Database in an ORACLE_HOME ?
/bin/emca -config dbcontrol db -repos create
Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYS user:
Password for DBSNMP user: < Enter the DBSNMP user password here>
Password for SYSMAN user: < Set new password for SYSMAN user>
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
-----------------------------------------------------------------
You have specified the following settings
Database ORACLE_HOME ................ /home/oracle/app/oracle/product/11.1.0/db_1
Local hostname ................ acme.oracle.com
Listener port number ................ 1521
Database SID ................ orcl
Email address for notifications ...............
Outgoing Mail (SMTP) server for notifications ...............
-----------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: y
How to create DBConsole configuration files?
For a database if DBConsole repository already exists, then run below EMCA command to create DBConsole configuration files and upload
configuration data to repository.
If the configuration files already exists under
/ and
/oc4j/j2ee/OC4J_DBConsole__
then above command drops the existing configuration files and re-creates them. A warning is displayed seeking for a confirmation to reconfigure
the DBConsole as shown below.
/bin/emca -config dbcontrol db
Enter the following information:
Database SID: orcl
Database Control is already configured for the database orcl
You have chosen to configure Database Control for managing the database orcl
This will remove the existing configuration and the default settings and perform a fresh configuration
Do you wish to continue? [yes(Y)/no(N)]: Y
Listener port number: 1521
Password for SYSMAN user: Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
2. How to drop DBConsole using EMCA or manually (with and without repository)
How to drop DBConsole configuration along with the repository using EMCA?
To completely remove the DBConsole configuration files and repository run below command.
/bin/emca -deconfig dbcontrol db -repos drop
Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for SYSMAN user:
Do you wish to continue? [yes(Y)/no(N)]: Y
This command will remove the DBConsole configuration files under /,
/oc4j/j2ee/OC4J_DBConsole__
as well as DBConsole repository from the Database.
How to drop DBConsole configuration files using EMCA (leave repository intact) ?
To remove DBConsole configuration files (leaving repository intact) run following EMCA command.
/bin/emca -deconfig dbcontrol db11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 6/ 12
/bin/emca -deconfig dbcontrol db
Enter the following information:
Database SID: orcl
Do you wish to continue? [yes(Y)/no(N)]:
This command will remove only the DBConsole configuration files which are under / and
/oc4j/j2ee/OC4J_DBConsole__
How to drop DBConsole repository objects manually ?
DBConsole repository can be dropped manually by executing following SQL statements.
Step 1: Drop AQ related objects in the SYSMAN schema
Logon SQLPLUS as user SYS
SQL> exec
DBMS_AQADM.DROP_QUEUE_TABLE(queue_table=>'SYSMAN.MGMT_NOTIFY_QTABLE',force=>TRUE);
Step 2: Drop the DB Control Repository Objects
Logon SQLPLUS as user SYS or SYSTEM, and drop the sysman account and management
objects:
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP RESTRICT;
SQL> EXEC sysman.emd_maintenance.remove_em_dbms_jobs;
SQL> EXEC sysman.setEMUserContext('',5);
SQL> REVOKE dba FROM sysman;
SQL> DECLARE
CURSOR c1 IS
SELECT owner, synonym_name name
FROM dba_synonyms
WHERE table_owner = 'SYSMAN';
BEGIN
FOR r1 IN c1 LOOP
IF r1.owner = 'PUBLIC' THEN
EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM '||r1.name;
ELSE
EXECUTE IMMEDIATE 'DROP SYNONYM '||r1.owner||'.'||r1.name;
END IF;
END LOOP;
END;
/
SQL> DROP USER mgmt_view CASCADE;
SQL> DROP ROLE mgmt_user;
SQL> DROP USER sysman CASCADE;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;
How to delete DBConsole configuration files manually?
To manually delete DBConsole configuration files, remove the following directories from the filesystem:
/
/oc4j/j2ee/OC4J_DBConsole__
If the dbcontrol is upgraded from lower version, for example, from 10.2.0.3 to 10.2.0.4, then the following directory also needs to be removed
from the file system.
/.upgrade
/oc4j/j2ee/OC4J_DBConsole__.upgrade
NOTE : Be careful while removing these directories as one should NOT remove OC4J_DBConsole or any other directory by mistake, they are
very important. You need to delete only those directories with _ where hostname is the hostname of the server and SID
should be the database SID.
On Windows you also need to delete the DB Console service:
Using regedit
- run regedit
- navigate to HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services
- locate the OracleDBConsole entry and delete it
Or
On Windows XP and Windows Server 2003 you can run the following from the command line:
CMD> sc delete
- where is the DB Control service name (typically: OracleDBConsole)
Or
CMD> nmesrvops delete 11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 7/ 12
- where is the DB Control service name (typically: OracleDBConsole)
3. How to re-create DBConsole using EMCA?
To drop and recreate DBConsole configuration files and repository using a single command, run below EMCA command. This command will
recreate the DBConsole configuration files and DBConsole repository for the Database.
/bin/emca -config dbcontrol db -repos recreate
Enter the following information:
Database SID: orcl
Database Control is already configured for the database oradb10g
You have chosen to configure Database Control for managing the database oradb10g
This will remove the existing configuration and the default settings and perform a fresh configuration
----------------------------------------------------------------------
WARNING : While repository is dropped the database will be put in quiesce mode.
----------------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: Y
Listener port number: 1521
Password for SYS user:
Password for DBSNMP user:
Password for SYSMAN user:
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
-----------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]:Y
4. How to change ports for DBConsole using EMCA commands?
When the DB Control is initially configured, it uses a default set of ports defined in respective range for each of the process as listed below.
- JMS [5540-5559], Default port 5540
- RMI [5520-5539], Default port 5520
- Database Control [1158, 5500-5519], Default port 1158
- EM Agent [3938] | [1830-1849], Default port 3938
For subsequent DBConsole configurations in the same machine, the above port numbers will be incremented by 1 in their respective ranges and a
free port in this range is allocated for the corresponding process.
To change or customize the port for any of the above processes run the following EMCA command.
/bin/emca -reconfig ports [-DBCONTROL_HTTP_PORT ] [-RMI_PORT ] [-JMS_PORT
] [-AGENT_PORT ]
For example : To change DBCONTROL_HTTP_PORT the command should be
/bin/emca -reconfig ports -DBCONTROL_HTTP_PORT 1160
To change RMI_PORT the command should be
/bin/emca -reconfig ports -RMI_PORT 5523
For more details about emca -reconfig ports, refer to Note 395755.1 How to Change Ports for DBControl
How to run EMCA commands in silent mode?
EMCA commands can be executed in silent mode without any manual intervention. All the input parameters can be populated using response file.
For example, to configure DBConsole in silent mode the EMCA command is:
/bin/emca -config dbcontrol db -silent -respFile
For more details refer to Note 344502.1 How To Run EMCA In Silent Mode By Using the -Silent and -RespFile Options
How to upgrade DBConsole configuration when the database has been upgraded?
When database is upgraded, for example from 10.1.0.4 to 10.2.0.1, the DBConsole configuration is upgraded by default as part of Database
upgrade process. In case of any failures, EMCA utility can be used to manually upgrade the DBConsole configuration. The EMCA command to
upgrade DBConsole configuration is:
/bin/emca -upgrade db
For more details on -upgrade db command refer to Note 465518.1 How to Upgrade Database Control Configuration Using EMCA
Back to Top
=================================================================================================
Diagnostic Tools
Remote Diagnostic Agent (RDA)
Remote Diagnostic Agent (RDA) is a command-line diagnostic tool that is executed by an engine written in the Perl programming language. RDA11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 8/ 12
Remote Diagnostic Agent (RDA) is a command-line diagnostic tool that is executed by an engine written in the Perl programming language. RDA
provides a unified package of support diagnostics tools and preventive solutions . The data captured provides Oracle Support with a
comprehensive picture of the customer's environment which aids in problem diagnosis.
For More information on RDA Refer Note 314422.1 Remote Diagnostic Agent (RDA) 4 - Getting Started
The Remote Diagnostic Agent (RDA) can be executed specifically with the Database Control profile name: DBC in order to reduce the number of
questions that need to be answered and also to collect all details of the Database control home correctly.
The steps to execute the RDA with DBC profile is explained in:
Note 1090648.1 How to Run the RDA against a Single DB Control Installation
Note: Before running the RDA with DBC profile, ensure that an attempt has been made to execute the EMCA command with any desired
options. This will allow the RDA to pick up the necessary EMCA logs.
Back to Top
=================================================================================================
Troubleshooting EMCA Failures
Ensure all the pre-requisites mentioned in Note 1113343.1 Pre-requisites for Successful Execution of EMCA Commands in Single Instance Database
Environment are met before executing any EMCA command.
To understand the break-point where the failure has occurred for EMCA execution, refer to Note 422556.1 EMCA Log File Example and Flow of EMCA
Command explained in "About EMCA" section.
Locating, Managing and Reading EMCA Log Files
How to find corresponding log file for EMCA execution?
Execution of EMCA command displays an INFO message on standard output with the log file name and location to which all these
information is logged.
For example:
/bin/./emca -deconfig dbcontrol db -repos drop
STARTED EMCA at May 17, 2010 8:56:33 PM...
INFO: This operation is being logged at /home/oracle/app/oracle/cfgtoollogs/emca/orcl/emca_2010_05_17_20_56_33.log.
If the access to session prompt where the EMCA command was executed is no longer available, then corresponding EMCA log file can be
identified based on the date and time of command execution.
How to get additional information in emca_.log file for debugging or troubleshooting ? Or How to enable
trace for EMCA operations?
By default the EMCA log trace level is set to CONFIG. With this trace level the log file is populated with INFO, CONFIG, and ERROR
messages. This trace level can be modified by changing the value of the parameter oracle.sysman.emcp.level to "FINER" as explained
below to get additional information for debugging.
1. Backup the file emcalog.properties located in /sysman/config (%ORACLE_HOME%\sysman\config\ in case of
windows)
2. Edit the file emcalog.properties and change the value of the parameter
oracle.sysman.emcp.level = CONFIG
To
oracle.sysman.emcp.level = FINER
How to read and analyze the information in emca_.log file?
The entries in the emca_.log file can be classified into following categories: INFO, CONFIG, WARNING and FINE.
The entire information of EMCA operation is logged in the emca_.log file that also includes the internal commands used by it.
These entries in emca_.log file are prefixed with following strings based on the type of information being logged.
INFO: The entry in this file starting with INFO: shows the informational message about the progress of EMCA command. These
INFO messages are also displayed on standard output as output of EMCA command.
For Example :
INFO: This operation is being logged at /home/oracle/app/oracle/cfgtoollogs/emca/orcl/emca_2010_05_17_20_56_33.log.
INFO: Stopping Database Control (this may take a while) ...
INFO: Dropping the EM repository (this may take a while) ...
INFO: Repository successfully dropped
CONFIG: The entry in EMCA log file starting with CONFIG: shows individual command that EMCA is performing.
For example :
CONFIG: Deleting state directories
CONFIG: No value was set for the parameter ORACLE_HOSTNAME.
CONFIG: isLocalNodeDone: true localNode: null
CONFIG: Removing entry from portlist.ini for Enterprise Manager Console HTTP Port (orcl)11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 9/ 12
WARNING: The entry in EMCA log file starting with WARNING: shows warning messages while performing internal commands.
These warning messages are also displayed on standard output as output of EMCA command.
For example:
WARNING: Encrypted data in Enterprise Manager will become unusable if the emkey.ora file is lost or corrupted.
FINE: The entry in EMCA log file starting with FINE: shows debug messages while performing internal commands. These messages
are logged only when Debug is enabled in emcalog.properties
The EMCA command may fail due to following common causes:
1. EMCA failing while connecting to Database
When EMCA is executed, the tool takes input values for Database SID, Listener port servicing the database, passwords for SYS, SYSMAN,
DBSNMP users. With these input values EMCA utility makes connection to database as SYS, SYSMAN or DBSNMP user to perform
respective action. EMCA tool either makes bequeath connection to the database or connects via the listener. For this connection to succeed
both the database and listener need to be up and running. In addition to this, the password file should be correctly configured so that SYS
user is able to connect remotely.
The connection is verified at the session prompt as soon as the password is provided. If there is a problem verifying the password for any
of the users, below error is reported after entering the password.
Enter the following information:
Database SID: orcl
Listener port number: 1521
Password for DBSNMP user: Invalid username/password.
If the database listener is down or unresponsive, the EMCA command fails with the error
SEVERE: Listener is not up. Start the Listener and run EM Configuration Assistant again .
Most common errors that can be found in emca_.log file due to database connectivity are
ORA-01017: Invalid username/password.
ORA-01031: insufficient privileges
ORA-01034: ORACLE not available
ORA-12541: TNS:no listener
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
or any other TNS error
For Troubleshooting steps and list of known issues (including ones listed above), refer to Note 1106623.1 How to Troubleshoot EMCA
Failures Due to Connectivity Issue to Database
In 10.2.0.5 Database release, the connection checks and the error messages have been improved.
If the password for any of the user is incorrect, EMCA displays the "Invalid username/password" error with possible causes for the
same.
If listener is down or port is incorrect, a detailed error message is shown to the user with possible causes for the same.
To find documents related to EMCA failures due to database connectivity login to My Oracle Support portal and query the 'Knowledge' with
the following keywords:
EMCA Fails With Error ""
For Example :
EMCA Fails With Error "Invalid username/password."
EMCA Fails With Error "ORA-12541: TNS:no listener"
2. EMCA failing due to Oracle Home software related issues
When EMCA is executed to configure DBConsole, the configuration process depends on the Enterprise Manager Software installed under
the ORACLE_HOME and other configuration files. DBConsole configuration may fail because of incomplete DBConsole software present in
the ORACLE_HOME, missing configuration and sql files, corrupt java or jdk files, wrong data in configuration files or files being corrupt.
Most common errors encountered for EMCA failures due to software related issues are:
SEVERE: Error instantiating EM configuration files
Exception in thread "main" java.lang.NoClassDefFoundError:
java.lang.UnsatisfiedLinkError:
SEVERE: Error parsing XML file
Failed to load Main Class: oracle.sysman.emcp.EMConfigAssistant
SP2-0310: unable to open file
SEVERE: Error updating XML file
CONFIG: Failed to deploy state dirs
java.io.IOException11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 10/ 12
EM is not configured for this database. No EM-specific actions can be performed.
For Troubleshooting steps and list of known issues (including ones listed above), refer to Note 1107535.1 How to Troubleshoot EMCA
Failures Due to Oracle Home Software Related Issues
To find documents related to Oracle Home software related issues login to My Oracle Support portal and query the 'Knowledge' with the
following keywords:
EMCA Fails With Error ""
For Example :
EMCA Fails With Error "java.lang.UnsatisfiedLinkError:"
EMCA Fails With Error "SP2-0310: unable to open file"
3. EMCA failing due to Hostname and Port related issues
The DBConsole configuration is tightly coupled with the hostname of the server and respective ports for each DBConsole configurations. When
DBConsole is configured using EMCA, the hostname of the server and binding of DBConsole ports play an important role.
Document 235298.1 - Overview of Default Ports Used by EM 10g Grid Control, DB Control and AS Control
Most common errors that can be encountered due to hostname and port are:
EMCA fails while starting DBConsole due to presence of underscore '_' in the Hostname. As per the RFC952 naming convention underscore
character is not recommended for hostname.
EMCA fails for 10g database with below error if hostname exceeds 32 character.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
If there are any problems at the time of port allocation during DBConsole configuration, EMCA fails with generic error message:
Failed to allocate port(s) in the specified range(s) for the following process(es): JMS
[5540-5559], RMI [5520-5539], Database Control [5500-5519], EM Agent [3938] | [1830-1849]
For Troubleshooting steps and list of known issues (including ones listed above), refer to Note 1107743.1 How to Troubleshoot EMCA
Failures Due to Hostname and Port Related Issues
To find documents related to Hostname and Port related issue login to My Oracle Support portal and query the 'Knowledge' with the
following keywords:
EMCA Fails With Error ""
For Example :
EMCA Fails With Error "Failed to allocate port(s) in the specified range(s) for the following process(es)"
EMCA Fails With Error "ORA-06502: PL/SQL: numeric or value error: character string buffer too small"
4. EMCA failing due to Database or OS configuration
When EMCA is executed to create DBConsole configuration and repository, it executes many pl/sql and sql scripts in a pre-defined sequence. The
EMCA command execution may fail if there is a mismatch between the pre-requisites and Database / OS configuration or any initialization
parameter that affects repository creation.
Most common errors encountered due to Database Configuration are
ORA-28056: Writing audit records to Windows Event Log failed
ORA-01552: cannot use system rollback segment for non-system tablespace 'TEMP
ORA-01422: exact fetch returns more than requested number of rows
ORA-01722: invalid number
PLS-00302: When the DBMS_REGISTRY is Incomplete
ORA-01429: Index-Organized Table: no data segment to store overflow row-pieces
ORA-00376 When SYSAUX Datafile is Not Online
ORA-03113: end-of-file on communication channel
ORA-25153: Temporary Tablespace is Empty
ORA-00988: missing or invalid password
ORA-28007: the password cannot be reused
ORA-24170: SYSMAN.MGMT_NOTIFY_Q_N is created by AQ,cannot be dropped directly
ORA-00959: tablespace 'TEMP' does not exist
ORA-24344: Success with compilation error
PLS-201: Identifier 'IDENTIFIER_NAME' must be declared
ORA-04063: Package Body "Package Name" has errors
Most common errors encountered due to OS Configuration are11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 11/ 12
File Not Found Errors
Segmentation fault
libclntsh.so: cannot open shared object file
java.lang.UnsatisfiedLinkError: Can't find library or
Java.lang.Unsatisfiedlinkerror: Can't load library
For Troubleshooting steps and list of known issues (including ones listed above), refer to Note 1112254.1 How to Troubleshoot EMCA
Failures Due to Database or OS Configuration
To find documents related to Database or OS configuration issue login to My Oracle Support portal and query the 'Knowledge' with the
following keywords:
EMCA Fails With Error ""
For Example :
EMCA Fails With Error "ORA-00959: tablespace 'TEMP' does not exist"
EMCA Fails With Error "libclntsh.so: cannot open shared object file"
5. EMCA failing due to SYSMAN and other existing objects during re-configuration
The DBConsole repository objects are stored in the SYSMAN and MGMT_VIEW schema of the database. The DBConsole Re-configuration / Recreation will fail during user or object creation if any of them already exist in the Database. When EMCA command is executed with "repos
create" it creates the DBConsole configuration along with the repository. The EMCA tool will fail if either SYSMAN / MGMT_VIEW schema or their
objects already exist in the Database.
Most common errors encountered during reconfiguration due to existing objects are :
ORA-20001: SYSMAN already exists..
ORA-01422: exact fetch returns more than requested number of rows
ORA-00955: name is already used by an existing object
ORA-01920: user name 'MGMT_VIEW' conflicts with another user or role name
CONFIG: CreateService FAILED: The specified service already exists.
Service creation failed. Aborting..
For Troubleshooting steps and list of known issues (including ones listed above), refer to Note 1110043.1 How To Troubleshoot EMCA
Failures Due to SYSMAN and Other Existing Objects During Re-Configuration
In 10.2.0.5 Database release, if the DBConsole repository already exists in the database and -create is used, the command aborts with
appropriate error message.
If database is used for Grid Control repository and EMCA is invoked to drop or create DBConsole repository then it aborts with appropriate
error message.
To find documents related to EMCA failures due to SYSMAN and Other Existing Objects, login to My Oracle Support portal and query the
'Knowledge' with the following keywords:
EMCA Fails With Error ""
For Example :
EMCA Fails With Error "ORA-20001: SYSMAN already exists"
Back to Top
=================================================================================================
References
NOTE:1090648.1 - How to Run the RDA against a DB Control Installation
NOTE:1106623.1 - Troubleshooting EMCA Failures Due to Database Connectivity Issues
NOTE:1107535.1 - Trouleshooting DBConsole EMCA Failures Due to Oracle Home Software Related Issues
NOTE:1107743.1 - Troubleshooting Dbconsole EMCA Failures Due to Hostname and Port Related Issues
NOTE:1110043.1 - Troubleshooting EMCA Failures Due to SYSMAN and Other Existing Objects During Configuration
NOTE:1112254.1 - Troubleshooting DBConsole EMCA Failures Due to Database or OS Configuration
NOTE:1113343.1 - How To Check Pre-requisites for Successful Execution of EMCA Commands in Single Instance Database Environment
NOTE:1217493.1 - ATTENTION - Enterprise Manager Database Control 10.2.0.4 Or 10.2.0.5 - Patch Required from 31-Dec-2010 onwards
NOTE:278100.1 - How To Drop, Create And Recreate the Database Control (DB Control) Release 10g and 11g
NOTE:314422.1 - Remote Diagnostic Agent (RDA) 4 - Getting Started
NOTE:344502.1 - How To Run EMCA In Silent Mode By Using the -Silent and -RespFile Options
NOTE:375946.1 - EMCA Release 10.1 to 11.1 Puts the Database in Quiesce And No New Connections or Operations Can Be Performed During the DB
Control Repository Creation
NOTE:395755.1 - How to Change the Database Control (DB Control) Port Number
NOTE:422556.1 - An Example of What is Written to the EMCA Log Files after Successful Creation of DBConsole via EMCA
NOTE:465518.1 - How to Upgrade Database Control Configuration Using EMCA
NOTE:740157.1 - How To Verify if the EM Database Control Console Software is Installed and Database Console is Configured For a Database in an
ORACLE_HOME ?11/ 5/ 12 Docum ent Dsi pal y
ht t ps: / / suppor t . or acel . com / epm os/ f aces/ u/i km / Sear chDocDsi pal y. sj px?_adf . ct r -l st at e=5quudui 0q_147 12/ 12

Friday, October 19, 2012

A discussion of Dead Connection Detection, Resource Limits, V$SESSION, V$PROCESS and OS processes [ID 601605.1]

Applies to:
Oracle Server - Enterprise Edition - Version 8.0.3.0 and later

Goal:
Discuss what can be expected when implementing Dead Connection Detection (DCD) along with Database Resource Limits with user Profiles, inactive sessions and the effects on V$SESSION, V$PROCESS and OS Processes

Fix:
Dead Connection Detection (DCD)
These are previously valid connections with the database but the connection between the client and server processes has terminated abnormally. Examples of a dead connection:
- A user reboots/turn off their machine without logging off or disconnecting from the database.
- A network problem prevents communication between the client and the server.

In the cases, the shadow process running on the server and the session in the database may not terminate.
Implemented by
    * adding SQLNET.EXPIRE_TIME = to the sqlnet.ora file
with DCD is enabled, the server-side process sends a small 10-byte packet to the client process after the duration of the time interval specified in minutes by the SQLNET.EXPIRE_TIME parameter.

If the client side connection is still connected and responsive, the client sends a response packet back to the database server, resetting the timer.. and another packet will be sent when next interval expires.

If the client fails to respond to the DCD probe packet
  * The server-side process is marked as dead connection and
  * PMON performs the clean up of the database processes / resources\
  * The client OS processes are terminated.

Database Resource Limits (using user profiles) 

Implemented by 
     * Setting RESOURCE_LIMIT = TRUE in the database startup parameter file (spfile or pfile) 
     * Creating or modifying existing user profiles (DBA_PROFILES) to have one or more resource limit
     * Assigning a profile to a user whose resources are wished to be limited 

It could happen that if the idle_time has been set on the DEFAULT profile, this can lead to an MTS dispatchers being set to 'sniped' and then getting 'cleaned up' via the shell script. The removal of the dispatcher will result in other sessions 'dying' .In that case, If you are to implement resource limits, may be advisable to create new profiles
that be assigned to users and not to change the characteristics of DEFAULT.
Alternatively, if you do change DEFAULT, ensure that all the properties that you
have affected have been fully tested in a development environment.

When a resource limit is exceeded (for example IDLE_TIME) ... PMON does the following 
     * Mark the V$SESSION as SNIPED 
     * Clean up the database resources for the session
     * Remove the V$SESSION entry 

For this case we will see that :
     * PMON has cleaned up the V$SESSION entries .. but both the OS processes and the V$PROCESS entries will still exist 
     * SQLNET will continue to be able to send the 10 byte packet successfully until the session is logged off 

This condition can be a major problem as 
     * The database exhausts PROCESSES and gives ORA-20 maximum number of processes exceeded 
     * The OS can become exhausted due to the unneeded resources consumed by the abandoned processes 

The SYMPTOMS of this condition are 
     * The database view V$PROCESS will have no corresponding V$SESSION entry 
     * An OS process / thread still exists for the SNIPED session 

The solutions to this scenario can are to cleanup the OS processes ... after which the $PROCESS entries should be removed automatically 

Methods to cleanup OS processes:

     * UNIX : kill -x ... the OS process at the OS level (typically kill -9) 
     * UNIX:  if using a dedicated server, use the following shell script to kill the shadow process (script has been tested on Solaris, AIX, Tru64 and  HPUX):
#!/bin/sh
tmpfile=../tmp/tmp.$$
sqlplus -S ' / as sysdba' <
spool $tmpfile

set echo off;
set feed off;
select p.spid from v\$process p,v\$session s
where s.paddr=p.addr
and s.status='SNIPED';
spool off
EOF
for x in `cat $tmpfile | egrep "^[0123456789]+"`
do
kill -9 $x
done
rm $tmpfile

On occasions we see conditions where a database session has a V$SESSION.STATUS = SNIPED ... and the entry never goes away . This condition can be achieved by implementing Database Resource Limits + Profiles without DCD and allow the database session to exceed the limit in the profile 


Summary of what was discussed here:
1) DCD initiates clean up of OS and database processes  that have disconnected / terminated abnormally
2) DCD will not initiate clean up sessions that are still connected ... but are idle / abandoned / inactive 
3) Database Resource Limits + user Profiles clean up database resources for user sessions that exceed resource limits
4) Database Resource Limits + user Profiles will not clean up OS processes
5) If DCD and Database Resource Limits + user Profiles are used in combination .. Dead Connections OS and Database Resources will be cleaned up 
6) IDLE / ABANDONED / INACTIVE sessions OS processes will not be cleaned up even if DCD and Database Resource Limits + user Profiles are used in combination ... these must be cleaned up manually

Tuesday, August 14, 2012

SUDO SCRIPT


# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
# Failure to use 'visudo' may result in syntax or file permission errors
# that prevent sudo from running.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification
Cmnd_Alias      WEBADMIN        = /etc/init.d/ibm-http, /usr/bin/vi /opt/IBM/HTTPServer/conf/*, /opt/IBM/HTTPServer/bin/*
Cmnd_Alias      MONITOR         = /bin/cat, /bin/grep, /bin/more, /usr/bin/head, /usr/bin/tail, /usr/bin/less, /var/log/*
Cmnd_Alias      PASSWDROOT      = !/usr/bin/passwd root
Cmnd_Alias      SECURITY        = /bin/ls,/bin/more,/bin/cat,/usr/sbin/useradd,/usr/sbin/usermod,/usr/sbin/userdel,/usr/sbin/groupadd,/usr/sbin/groupmod,/usr/sbin/groupdel,/usr/bin/passwd,/bin/chown,/bin/chmod,/usr/bin/getfacl,/usr/bin/setfacl
Cmnd_Alias      SYSADMIN        = /bin/*, /sbin/*, /user/bin/*, /usr/sbin/*
Cmnd_Alias      OPERATION       = /sbin/shutdown
Cmnd_Alias      VISUDO          = /usr/sbin/visudo
Cmnd_Alias      SUROOT          =!/bin/su -, !/bin/su - root, !/bin/su root

# Defaults specification

# prevent environment variables from influencing programs in an
# unexpected or harmful way (CVE-2005-2959, CVE-2005-4158,
# CVE-2006-0151)
Defaults always_set_home
Defaults env_reset

# In the default (unconfigured) configuration, sudo asks for the root password.
# This allows use of an ordinary user account for administration of a freshly
# installed system. When configuring sudo, delete the two
# following lines:
#Defaults targetpw    # ask for the password of the target user i.e. root
#ALL ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!

# Runas alias specification

# User privilege specification
root    ALL=(ALL) ALL
%sysadmin       ALL=SYSADMIN,OPERATION,MONITOR,SECURITY,VISUDO,WEBADMIN, SUROOT

# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL) ALL

# Same thing without a password
# %wheel        ALL=(ALL) NOPASSWD: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

Monday, August 13, 2012

How to handle X11 Forwarding using SSH

How to handle X11 Forwarding using SSH

If you need to use X applications/GUI over a remote SSH connection via PuTTY, this tutorial is for you.

What you need
Xming : an X-Server that starts on top of your desktop. Download Xming and install it. PuTTY : an SSH client. Download PuTTY and save it on your hard disk. Configure Xming
  • Click on the Start button in Windows XP, select Xming → XLaunch
  • At the Display settings dialog box, select Multiple windows and set the Display number as 0. Click on Next.
  • Keep clicking on Next button till you reach the Finish configuration page, then click on the Finish button.
  • Configure PuTTY
  • Start PuTTY.
  • In the PuTTY Configuration section, on the left panel, select Connection → SSH → X11
  • On the right panel, click on the Enable X11 forwarding checkbox
  • Set the X display location as :0.0
  • Click on Session option on the left panel.
  • Enter the hostname or IP address in the Host Name textbox
  • Save the session.
  • Running the X applications from PuTTY
  • Double-click on your PuTTY session and login. After you login, a file named .Xauthority will be created.
  • Check if the DISPLAY variable has been set.
  • echo $DISPLAY
  • You should see a meaningful value for $DISPLAY
  • Start any X application, say xterm. xterm

    Running X apps as root This requires a little tweak. Suppose your regular user home directory is /var/home/arul and the root user home directory is /root
    If you were able to login as a normal user earlier, a file called .Xauthority would be created in the home directory. Chmod the .Xauthority to 555.
    chmod 555 ~/.Xauthority Login as root from your regular user account.
    su - root
    Copy the .Xauthority from the regular user's home directory to root user's home directory.
    cp /var/home/arul/.Xauthority /root
    Now try to open any X apps like xterm or emacs. It should work.
    Troubleshooting
    If you're not able to open any X apps from the session, you may need to enable X11 SSH Forwarding in the /etc/ssh/ssh_config file

    Compile mod_jk from source for IBM HTTP Server

    # compile mod_jk for IBM HTTP
    To create tomcat-connectors's autoconf script, you will need to install libraries below
    yast -i libtool automake autoconf perl gcc gcc-c++ libgcc glibc glibc-32bit glibc-devel glibc-devel-32bit  libtool automake autoconf 
    and then do steps below:
    1. download mod_jk source
    2. cd $tomcat-connectors'/native
    3. ./buildconf.sh
    4. LDFLAGS=-lc ./configure -with-apxs=/opt/IBM/HTTPServer/bin/apxs
    6. cd apache-2.0
    7. make
    8. copy ./apache-2.0/mod_jk.so to /opt/IBM/HTTPServer/modules

    Monday, July 16, 2012

    RISC VS CISC

    The simplest way to examine the advantages and disadvantages of RISC architecture is by contrasting it with it's predecessor: CISC (Complex Instruction Set Computers) architecture.

    Multiplying Two Numbers in Memory

    On the right is a diagram representing the storage scheme for a generic computer. The main memory is divided into locations numbered from (row) 1: (column) 1 to (row) 6: (column) 4. The execution unit is responsible for carrying out all computations. However, the execution unit can only operate on data that has been loaded into one of the six registers (A, B, C, D, E, or F). Let's say we want to find the product of two numbers - one stored in location 2:3 and another stored in location 5:2 - and then store the product back in the location 2:3.

    The CISC Approach

    The primary goal of CISC architecture is to complete a task in as few lines of assembly as possible. This is achieved by building processor hardware that is capable of understanding and executing a series of operations. For this particular task, a CISC processor would come prepared with a specific instruction (we'll call it "MULT"). When executed, this instruction loads the two values into separate registers, multiplies the operands in the execution unit, and then stores the product in the appropriate register. Thus, the entire task of multiplying two numbers can be completed with one instruction:

    MULT 2:3, 5:2

    MULT is what is known as a "complex instruction." It operates directly on the computer's memory banks and does not require the programmer to explicitly call any loading or storing functions. It closely resembles a command in a higher level language. For instance, if we let "a" represent the value of 2:3 and "b" represent the value of 5:2, then this command is identical to the C statement "a = a * b."

    One of the primary advantages of this system is that the compiler has to do very little work to translate a high-level language statement into assembly. Because the length of the code is relatively short, very little RAM is required to store instructions. The emphasis is put on building complex instructions directly into the hardware.

    The RISC Approach

    RISC processors only use simple instructions that can be executed within one clock cycle. Thus, the "MULT" command described above could be divided into three separate commands: "LOAD," which moves data from the memory bank to a register, "PROD," which finds the product of two operands located within the registers, and "STORE," which moves data from a register to the memory banks. In order to perform the exact series of steps described in the CISC approach, a programmer would need to code four lines of assembly:

    LOAD A, 2:3 LOAD B, 5:2 PROD A, B STORE 2:3, A

    At first, this may seem like a much less efficient way of completing the operation. Because there are more lines of code, more RAM is needed to store the assembly level instructions. The compiler must also perform more work to convert a high-level language statement into code of this form.

    CISC RISC
    Emphasis on hardware Emphasis on software
    Includes multi-clock, complex instructions Single-clock,reduced instruction only
    Memory-to-memory: "LOAD" and "STORE" incorporated in instructions Register to register: "LOAD" and "STORE" are independent instructions
    Small code sizes, high cycles per second Low cycles per second, large code sizes
    Transistors used for storing complex instructions Spends more transistors on memory registers
    However, the RISC strategy also brings some very important advantages. Because each instruction requires only one clock cycle to execute, the entire program will execute in approximately the same amount of time as the multi-cycle "MULT" command. These RISC "reduced instructions" require less transistors of hardware space than the complex instructions, leaving more room for general purpose registers. Because all of the instructions execute in a uniform amount of time (i.e. one clock), pipelining is possible.

    Separating the "LOAD" and "STORE" instructions actually reduces the amount of work that the computer must perform. After a CISC-style "MULT" command is executed, the processor automatically erases the registers. If one of the operands needs to be used for another computation, the processor must re-load the data from the memory bank into a register. In RISC, the operand will remain in the register until another value is loaded in its place.

    The Performance Equation

    The following equation is commonly used for expressing a computer's performance ability:

    The CISC approach attempts to minimize the number of instructions per program, sacrificing the number of cycles per instruction. RISC does the opposite, reducing the cycles per instruction at the cost of the number of instructions per program.

    RISC Roadblocks Despite the advantages of RISC based processing, RISC chips took over a decade to gain a foothold in the commercial world. This was largely due to a lack of software support.

    Although Apple's Power Macintosh line featured RISC-based chips and Windows NT was RISC compatible, Windows 3.1 and Windows 95 were designed with CISC processors in mind. Many companies were unwilling to take a chance with the emerging RISC technology. Without commercial interest, processor developers were unable to manufacture RISC chips in large enough volumes to make their price competitive.

    Another major setback was the presence of Intel. Although their CISC chips were becoming increasingly unwieldy and difficult to develop, Intel had the resources to plow through development and produce powerful processors. Although RISC chips might surpass Intel's efforts in specific areas, the differences were not great enough to persuade buyers to change technologies.

    The Overall RISC Advantage

    Today, the Intel x86 is arguable the only chip which retains CISC architecture. This is primarily due to advancements in other areas of computer technology. The price of RAM has decreased dramatically. In 1977, 1MB of DRAM cost about $5,000. By 1994, the same amount of memory cost only $6 (when adjusted for inflation). Compiler technology has also become more sophisticated, so that the RISC use of RAM and emphasis on software has become ideal.

    Reference http://www-cs-faculty.stanford.edu/~eroberts/courses/soco/projects/2000-01/risc/risccisc/

    Wednesday, March 28, 2012

    How to encrypt database passwords using SecureIdentityLoginModule

    1. Encrypt password

    For JBoss EAP 4.3, using the script below below:
            
    JBOSSHOME=/apps/jboss-epp-5.1/jboss-as
    PROFILE=production
    echo "Please enter the password to be encrypted"
    read password
    java -cp $JBOSSHOME/lib/jboss-common.jar:$JBOSSHOME/lib/jboss-jmx.jar:$JBOSSHOME/server/$PROFILE/lib/jbosssx.jar:$JBOSSHOME/server/$PROFILE/lib/jboss-jca.jar org.jboss.resource.security.SecureIdentityLoginModule $password
    
    
    For JBoss EAP 5.1, using the script below below:
            
    JBOSSHOME=/apps/jboss-epp-5.1/jboss-as
    PROFILE=production
    echo "Please enter the password to be encrypted"
    read password
    java -cp $JBOSSHOME/client/jboss-logging-spi.jar:$JBOSSHOME/lib/jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule $password
    
    
    2. Set the username and encrypted password (generated in the previous step) and the managedConnectionFactoryName for your datasource

    <policy>
        <!-- Example usage of the SecureIdentityLoginModule -->
        <application-policy name="EncryptDBPassword">
            <authentication>
                <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required">
                    <module-option name="username">admin</module-option>
                    <module-option name="password">5dfc52b51bd35553df8592078de921bc</module-option>
                    <!-- Use this managedConnectionFactoryName for non-XA datasource -->
                    <module-option name="managedConnectionFactoryName">jboss.jca:name=PostgresDS,service=LocalTxCM</module-option>                <!-- Use this managedConnectionFactoryName for XA datasource --> 
    
                    <!-- <module-option name="managedConnectionFactoryName">jboss.jca:name=PostgresDS,service=XATxCM</module-option> --&gt; 
    
                </login-module>
            </authentication>
        </application-policy>
    </policy>
    
    3. Edit  your datasource, removing the username and password properties and  adding the security-domain you created in the previous step
    
    
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
        <local-tx-datasource>
            <jndi-name>PostgresDS</jndi-name>
            <connection-url>jdbc:postgresql://127.0.0.1:5432/test?protocolVersion=2</connection-url>
            <driver-class>org.postgresql.Driver</driver-class>
            <min-pool-size>1</min-pool-size>
            <max-pool-size>20</max-pool-size>
            <security-domain>EncryptDBPassword</security-domain>
            <metadata>
                <type-mapping>PostgreSQL 8.0</type-mapping>
            </metadata>
        </local-tx-datasource>
    </datasources>
    
    
    
    4. The login-config.xml entry for the EncryptDBPassword would look like:
    <policy>
        <!-- Example usage of the SecureIdentityLoginModule -->
        <application-policy name="EncryptDBPassword">
            <authentication>
                <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required">
                    <module-option name="username">admin</module-option>
                    <module-option name="password">5dfc52b51bd35553df8592078de921bc</module-option>
                    <module-option name="managedConnectionFactoryName">jboss.jca:name=PostgresDS,service=LocalTxCM</module-option>
                </login-module>
            </authentication>
        </application-policy>
    </policy>
    
    
    Reference to https://community.jboss.org/wiki/EncryptingDataSourcePasswords

    Wednesday, February 29, 2012

    Convert Font


    CREATE OR REPLACE PACKAGE   CONVERTOR AS
       /*
       *  VNI-to-Unicode conversion
       *
       *  The process consists of 3 parts:
       *
       *  1) converts single-byte (ASCII) characters except O+ and U+ because they are also
       *     used as base in some VNI double-byte characters
       *  2) converts VNI double-byte characters
       *  3) converts O+ and U+
       *
       * @author     Quan Nguyen
       * @version    1.2, 23 October 05
       */
      FUNCTION  VNI_TO_UNI (p_vni_string varchar2) RETURN VARCHAR2;
      FUNCTION  OLAS_TO_UNI (p_olas_string varchar2) RETURN VARCHAR2;
      FUNCTION  OLAS1258_TO_UNI (p_olas1258_string varchar2) RETURN VARCHAR2;
      FUNCTION  UNI_TO_VNI (p_uni_string varchar2) RETURN VARCHAR2;
    END CONVERTOR;

    ==============================================================
    CREATE OR REPLACE PACKAGE BODY  CONVERTOR AS

      TYPE MAPPING_T IS TABLE OF VARCHAR2(10) INDEX BY VARCHAR2(10);
      --VNI_TO_UNI
      FUNCTION  VNI_TO_UNI (p_vni_string varchar2) RETURN VARCHAR2 AS
    /*
     *  VNI-to-Unicode conversion
     *
     *  The process consists of 3 parts:
     *
     *  1) converts single-byte (ASCII) characters except O+ and U+ because they are also
     *     used as base in some VNI double-byte characters
     *  2) converts VNI double-byte characters
     *  3) converts O+ and U+
     *
     * @author     Quan Nguyen
     * @Modifier   Nguyen Tich Thanh
     * @version    1.2, 16/05/2011
     */
      vni_mapping MAPPING_T;
      --v_count PLS_INTEGER := 0;
      v_result VARCHAR2(512);
      v_pattern VARCHAR2(10);
      v_str  VARCHAR2(512);
      v_startIndex PLS_INTEGER;
      v_foundIndex PLS_INTEGER;
     
    BEGIN
      -- Initialization for vni_mapping
      vni_mapping('O\00C2') := '\00C6';
      vni_mapping('o\00E2') := '\00E6';
      vni_mapping('y\00F5') := '\1EF9';
      vni_mapping('Y\00D5') := '\1EF8';
      vni_mapping('y\00FB') := '\1EF7';
      vni_mapping('Y\00DB') := '\1EF6';
      vni_mapping('y\00F8') := '\1EF3';
      vni_mapping('Y\00D8') := '\1EF2';
      vni_mapping('\00F6\00EF') := '\1EF1';
      vni_mapping('\00D6\00CF') := '\1EF0';
      vni_mapping('\00F6\00F5') := '\1EEF';
      vni_mapping('\00D6\00D5') := '\1EEE';
      vni_mapping('\00F6\00FB') := '\1EED';
      vni_mapping('\00D6\00DB') := '\1EEC';
      vni_mapping('\00F6\00F8') := '\1EEB';
      vni_mapping('\00D6\00D8') := '\1EEA';
      vni_mapping('\00F6\00F9') := '\1EE9';
      vni_mapping('\00D6\00D9') := '\1EE8';
      vni_mapping('u\00FB') := '\1EE7';
      vni_mapping('U\00DB') := '\1EE6';
      vni_mapping('u\00EF') := '\1EE5';
      vni_mapping('U\00CF') := '\1EE4';
      vni_mapping('\00F4\00EF') := '\1EE3';
      vni_mapping('\00D4\00CF') := '\1EE2';
      vni_mapping('\00F4\00F5') := '\1EE1';
      vni_mapping('\00D4\00D5') := '\1EE0';
      vni_mapping('\00F4\00FB') := '\1EDF';
      vni_mapping('\00D4\00DB') := '\1EDE';
      vni_mapping('\00F4\00F8') := '\1EDD';
      vni_mapping('\00D4\00D8') := '\1EDC';
      vni_mapping('\00F4\00F9') := '\1EDB';
      vni_mapping('\00D4\00D9') := '\1EDA';
      vni_mapping('o\00E4') := '\1ED9';
      vni_mapping('O\00C4') := '\1ED8';
      vni_mapping('o\00E3') := '\1ED7';
      vni_mapping('O\00C3') := '\1ED6';
      vni_mapping('o\00E5') := '\1ED5';
      vni_mapping('O\00C5') := '\1ED4';
      vni_mapping('o\00E0') := '\1ED3';
      vni_mapping('O\00C0') := '\1ED2';
      vni_mapping('o\00E1') := '\1ED1';
      vni_mapping('O\00C1') := '\1ED0';
      vni_mapping('o\00FB') := '\1ECF';
      vni_mapping('O\00DB') := '\1ECE';
      vni_mapping('o\00EF') := '\1ECD';
      vni_mapping('O\00CF') := '\1ECC';
      vni_mapping('e\00E4') := '\1EC7';
      vni_mapping('E\00C4') := '\1EC6';
      vni_mapping('e\00E3') := '\1EC5';
      vni_mapping('E\00C3') := '\1EC4';
      vni_mapping('e\00E5') := '\1EC3';
      vni_mapping('E\00C5') := '\1EC2';
      vni_mapping('e\00E0') := '\1EC1';
      vni_mapping('E\00C0') := '\1EC0';
      vni_mapping('e\00E1') := '\1EBF';
      vni_mapping('E\00C1') := '\1EBE';
      vni_mapping('e\00F5') := '\1EBD';
      vni_mapping('E\00D5') := '\1EBC';
      vni_mapping('e\00FB') := '\1EBB';
      vni_mapping('E\00DB') := '\1EBA';
      vni_mapping('e\00EF') := '\1EB9';
      vni_mapping('E\00CF') := '\1EB8';
      vni_mapping('a\00EB') := '\1EB7';
      vni_mapping('A\00CB') := '\1EB6';
      vni_mapping('a\00FC') := '\1EB5';
      vni_mapping('A\00DC') := '\1EB4';
      vni_mapping('a\00FA') := '\1EB3';
      vni_mapping('A\00DA') := '\1EB2';
      vni_mapping('a\00E8') := '\1EB1';
      vni_mapping('A\00C8') := '\1EB0';
      vni_mapping('a\00E9') := '\1EAF';
      vni_mapping('A\00C9') := '\1EAE';
      vni_mapping('a\00E4') := '\1EAD';
      vni_mapping('A\00C4') := '\1EAC';
      vni_mapping('a\00E3') := '\1EAB';
      vni_mapping('A\00C3') := '\1EAA';
      vni_mapping('a\00E5') := '\1EA9';
      vni_mapping('A\00C5') := '\1EA8';
      vni_mapping('a\00E0') := '\1EA7';
      vni_mapping('A\00C0') := '\1EA6';
      vni_mapping('a\00E1') := '\1EA5';
      vni_mapping('A\00C1') := '\1EA4';
      vni_mapping('a\00FB') := '\1EA3';
      vni_mapping('A\00DB') := '\1EA2';
      vni_mapping('a\00EF') := '\1EA1';
      vni_mapping('A\00CF') := '\1EA0';
      vni_mapping('u\00F5') := '\0169';
      vni_mapping('U\00D5') := '\0168';
      vni_mapping('a\00EA') := '\0103';
      vni_mapping('A\00CA') := '\0102';
      vni_mapping('y\00F9') := '\00FD';
      vni_mapping('u\00F9') := '\00FA';
      vni_mapping('u\00F8') := '\00F9';
      vni_mapping('o\00F5') := '\00F5';
      vni_mapping('o\00F9') := '\00F3';
      vni_mapping('o\00F8') := '\00F2';
      vni_mapping('e\00E2') := '\00EA';
      vni_mapping('e\00F9') := '\00E9';
      vni_mapping('e\00F8') := '\00E8';
      vni_mapping('a\00F5') := '\00E3';
      vni_mapping('a\00E2') := '\00E2';
      vni_mapping('a\00F9') := '\00E1';
      vni_mapping('a\00F8') := '\00E0';
      vni_mapping('Y\00D9') := '\00DD';
      vni_mapping('U\00D9') := '\00DA';
      vni_mapping('U\00D8') := '\00D9';
      vni_mapping('O\00D5') := '\00D5';
      vni_mapping('O\00D9') := '\00D3';
      vni_mapping('O\00D8') := '\00D2';
      vni_mapping('E\00C2') := '\00CA';
      vni_mapping('E\00D9') := '\00C9';
      vni_mapping('E\00D8') := '\00C8';
      vni_mapping('A\00D5') := '\00C3';
      vni_mapping('A\00C2') := '\00C2';
      vni_mapping('A\00D9') := '\00C1';
      vni_mapping('A\00D8') := '\00C0';

      -- Processing
      -- Part 1
      v_result := asciistr(p_vni_string);
      v_result := replace(v_result, '\00D1', '\0110');    -- DD
      v_result := replace(v_result, '\00F1', '\0111');    -- dd
      v_result := replace(v_result, '\00D3', '\0128');    -- I~
      v_result := replace(v_result, '\00F3', '\0129');    -- i~
      v_result := replace(v_result, '\00D2', '\1ECA');    -- I.
      v_result := replace(v_result, '\00F2', '\1ECB');    -- i.
      v_result := replace(v_result, '\00C6', '\1EC8');    -- I?
      v_result := replace(v_result, '\00E6', '\1EC9');    -- i?
      v_result := replace(v_result, '\00CE', '\1EF4');    -- Y.
      v_result := replace(v_result, '\00EE', '\1EF5');    -- y.

      -- Part 2
      -- Transform "O\u00C2" -> "\u00C6" to later transform back to "\u00D4" in Part 3
      --v_count := REGEXP_COUNT(v_result, '\\', 1, 'c');
      v_startIndex := 1;
      v_foundIndex := 0;
      v_pattern := '';
      v_str := v_result;
      v_result := '';
      v_foundIndex := INSTR(v_str, '\', v_startIndex);
      while ( v_foundIndex > 0)            
      loop
          v_pattern := substr(v_str, v_foundIndex, 5);
          case
            when v_pattern = '\00D4' then
              v_pattern := substr(v_str, v_foundIndex, 10);
            when v_pattern = '\00D6' then
              v_pattern := substr(v_str, v_foundIndex, 10);
            when v_pattern = '\00F4' then
              v_pattern := substr(v_str, v_foundIndex, 10);
            when v_pattern = '\00F6' then
              v_pattern := substr(v_str, v_foundIndex, 10);
            else
              v_pattern := substr(v_str, v_foundIndex - 1, 6);
          end case;
         
        if vni_mapping.EXISTS(v_pattern) then    
          if length(v_pattern) = 10 then
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
            v_result := v_result || vni_mapping(v_pattern);
            v_startIndex := v_foundIndex + 10;    
          else
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - 1 - v_startIndex);
            v_result := v_result || vni_mapping(v_pattern);
            v_startIndex := v_foundIndex - 1 + 6;    
          end if;
        else
          v_pattern := substr(v_str, v_foundIndex, 5);
          v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
          v_result := v_result || v_pattern;
          v_startIndex := v_foundIndex + 5;              
        end if;
         v_foundIndex := INSTR(v_str, '\', v_startIndex);
      end loop;
      v_str := v_result || substr(v_str,v_startIndex);
      v_result := v_str;
     
      -- Part 3
      v_result := replace(v_result, '\00D4', '\01A0');    -- O+
      v_result := replace(v_result, '\00F4', '\01A1');    -- o+
      v_result := replace(v_result, '\00D6', '\01AF');    -- U+
      v_result := replace(v_result, '\00F6', '\01B0');    -- u+
      v_result := replace(v_result, '\00C6', '\00D4');    -- O^
      v_result := replace(v_result, '\00E6', '\00F4');    -- o^
      RETURN unistr(v_result);
    END VNI_TO_UNI;


    -- OLAS1252_TO_UNI
    FUNCTION  OLAS_TO_UNI (p_olas_string varchar2) RETURN VARCHAR2 AS
    /*
     *  OLAS codepage 1252 to Unicode conversion
     *
     *  The process consists of 3 parts:
     *
     *  1) process which patterns have 6 chars
     *  2) and then, process which patterns have 10 chars
     *  3) process which patterns have 5 chars
     *
     * @author     Nguyen Tich Thanh
     * @version    1.0, 16/05/2011
     */
      olas_mapping MAPPING_T;
      v_result VARCHAR2(512);
      v_pattern VARCHAR2(10);
      v_str  VARCHAR2(512);
      v_startIndex PLS_INTEGER;
      v_foundIndex PLS_INTEGER;
    BEGIN
      -- Initialization for olas_mapping
      olas_mapping('A\00DD') := '\1EA0'; -- Ạ
      olas_mapping('A\00DE') := '\00C1'; -- Á
      olas_mapping('A\00EC') := '\00C3'; -- Ã
      olas_mapping('A\00FD') := '\1EA2'; -- Ả
      olas_mapping('A\00FE') := '\00C0'; -- À
      olas_mapping('E\00DD') := '\1EB8'; -- Ẹ
      olas_mapping('E\00DE') := '\00C9'; -- É
      olas_mapping('E\00EC') := '\1EBC'; -- Ẽ
      olas_mapping('E\00FD') := '\1EBA'; -- Ẻ
      olas_mapping('E\00FE') := '\00C8'; -- È
      olas_mapping('I') := 'I'; -- I
      olas_mapping('I\00DD') := '\1ECA'; -- Ị
      olas_mapping('I\00DE') := '\00CD'; -- Í
      olas_mapping('I\00EC') := '\0128'; -- Ĩ
      olas_mapping('I\00FD') := '\1EC8'; -- Ỉ
      olas_mapping('I\00FE') := '\00CC'; -- Ì
      olas_mapping('O\00DD') := '\1ECC'; -- Ọ
      olas_mapping('O\00DE') := '\00D3'; -- Ó
      olas_mapping('O\00EC') := '\00D5'; -- Õ
      olas_mapping('O\00FD') := '\1ECE'; -- Ỏ
      olas_mapping('O\00FE') := '\00D2'; -- Ò
      olas_mapping('U\00DD') := '\1EE4'; -- Ụ
      olas_mapping('U\00DE') := '\00DA'; -- Ú
      olas_mapping('U\00EC') := '\0168'; -- Ũ
      olas_mapping('U\00FD') := '\1EE6'; -- Ủ
      olas_mapping('U\00FE') := '\00D9'; -- Ù
      olas_mapping('Y\00DD') := '\1EF4'; -- Ỵ
      olas_mapping('Y\00DE') := '\00DD'; -- Ý
      olas_mapping('Y\00EC') := '\1EF8'; -- Ỹ
      olas_mapping('Y\00FD') := '\1EF6'; -- Ỷ
      olas_mapping('Y\00FE') := '\1EF2'; -- Ỳ
      olas_mapping('\00C2\00DD') := '\1EAC'; -- Ậ
      olas_mapping('\00C2\00DE') := '\1EA4'; -- Ấ
      olas_mapping('\00C2\00EC') := '\1EAA'; -- Ẫ
      olas_mapping('\00C2\00FD') := '\1EA8'; -- Ẩ
      olas_mapping('\00C2\00FE') := '\1EA6'; -- Ầ
      olas_mapping('\00C3\00DE') := '\1EAE'; -- Ắ
      olas_mapping('\00C3\00EC') := '\1EB4'; -- Ẵ
      olas_mapping('\00C3\00FD') := '\1EB2'; -- Ẳ
      olas_mapping('\00C3\00FE') := '\1EB0'; -- Ằ
      olas_mapping('\00CA\00DD') := '\1EC6'; -- Ệ
      olas_mapping('\00CA\00DE') := '\1EBE'; -- Ế
      olas_mapping('\00CA\00EC') := '\1EC4'; -- Ễ
      olas_mapping('\00CA\00FD') := '\1EC2'; -- Ể
      olas_mapping('\00CA\00FE') := '\1EC0'; -- Ề
      olas_mapping('\00D2\00DD') := '\1EF0'; -- Ự
      olas_mapping('\00D2\00DE') := '\1EE8'; -- Ứ
      olas_mapping('\00D2\00EC') := '\1EEE'; -- Ữ
      olas_mapping('\00D2\00FD') := '\1EEC'; -- Ử
      olas_mapping('\00D2\00FE') := '\1EEA'; -- Ừ
      olas_mapping('\00D4\00DD') := '\1ED8'; -- Ộ
      olas_mapping('\00D4\00DE') := '\1ED0'; -- Ố
      olas_mapping('\00D4\00EC') := '\1ED6'; -- Ỗ
      olas_mapping('\00D4\00FD') := '\1ED4'; -- Ổ
      olas_mapping('\00D4\00FE') := '\1ED2'; -- Ồ
      olas_mapping('\00D5\00DD') := '\1EE2'; -- Ợ
      olas_mapping('\00D5\00DE') := '\1EDA'; -- Ớ
      olas_mapping('\00D5\00EC') := '\1EE0'; -- Ỡ
      olas_mapping('\00D5\00FD') := '\1EDE'; -- Ở
      olas_mapping('\00D5\00FE') := '\1EDC'; -- Ờ
      olas_mapping('\00E2\00DD') := '\1EAD'; -- ậ
      olas_mapping('\00E2\00DE') := '\1EA5'; -- ấ
      olas_mapping('\00E2\00EC') := '\1EAB'; -- ẫ
      olas_mapping('\00E2\00FD') := '\1EA9'; -- ẩ
      olas_mapping('\00E2\00FE') := '\1EA7'; -- ầ
      olas_mapping('\00E3\00DD') := '\1EB7'; -- ặ
      olas_mapping('\00E3\00DE') := '\1EAF'; -- ắ
      olas_mapping('\00E3\00EC') := '\1EB5'; -- ẵ
      olas_mapping('\00E3\00FD') := '\1EB3'; -- ẳ
      olas_mapping('\00E3\00FE') := '\1EB1'; -- ằ
      olas_mapping('\00EA\00DD') := '\1EC7'; -- ệ
      olas_mapping('\00EA\00DE') := '\1EBF'; -- ế
      olas_mapping('\00EA\00EC') := '\1EC5'; -- ễ
      olas_mapping('\00EA\00FD') := '\1EC3'; -- ể
      olas_mapping('\00EA\00FE') := '\1EC1'; -- ề
      olas_mapping('\00F2\00DD') := '\1EF1'; -- ự
      olas_mapping('\00F2\00DE') := '\1EE9'; -- ứ
      olas_mapping('\00F2\00EC') := '\1EEF'; -- ữ
      olas_mapping('\00F2\00FD') := '\1EED'; -- ử
      olas_mapping('\00F2\00FE') := '\1EEB'; -- ừ
      olas_mapping('\00F4\00DD') := '\1ED9'; -- ộ
      olas_mapping('\00F4\00DE') := '\1ED1'; -- ố
      olas_mapping('\00F4\00EC') := '\1ED7'; -- ỗ
      olas_mapping('\00F4\00FD') := '\1ED5'; -- ổ
      olas_mapping('\00F4\00FE') := '\1ED3'; -- ồ
      olas_mapping('\00F5\00DD') := '\1EE3'; -- ợ
      olas_mapping('\00F5\00DE') := '\1EDB'; -- ớ
      olas_mapping('\00F5\00EC') := '\1EE1'; -- ỡ
      olas_mapping('\00F5\00FD') := '\1EDF'; -- ở
      olas_mapping('\00F5\00FE') := '\1EDD'; -- ờ
      olas_mapping('a\00DD') := '\1EA1'; -- ạ
      olas_mapping('a\00DE') := '\00E1'; -- á
      olas_mapping('a\00EC') := '\00E3'; -- ã
      olas_mapping('a\00FD') := '\1EA3'; -- ả
      olas_mapping('a\00FE') := '\00E0'; -- à
      olas_mapping('e\00DD') := '\1EB9'; -- ẹ
      olas_mapping('e\00DE') := '\00E9'; -- é
      olas_mapping('e\00EC') := '\1EBD'; -- ẽ
      olas_mapping('e\00FD') := '\1EBB'; -- ẻ
      olas_mapping('e\00FE') := '\00E8'; -- è
      olas_mapping('i\00DD') := '\1ECB'; -- ị
      olas_mapping('i\00DE') := '\00ED'; -- í
      olas_mapping('i\00EC') := '\0129'; -- ĩ
      olas_mapping('i\00FD') := '\1EC9'; -- ỉ
      olas_mapping('i\00FE') := '\00EC'; -- ì
      olas_mapping('o\00DD') := '\1ECD'; -- ọ
      olas_mapping('o\00DE') := '\00F3'; -- ó
      olas_mapping('o\00EC') := '\00F5'; -- õ
      olas_mapping('o\00FD') := '\1ECF'; -- ỏ
      olas_mapping('o\00FE') := '\00F2'; -- ò
      olas_mapping('u\00DD') := '\1EE5'; -- ụ
      olas_mapping('u\00DE') := '\00FA'; -- ú
      olas_mapping('u\00EC') := '\0169'; -- ũ
      olas_mapping('u\00FD') := '\1EE7'; -- ủ
      olas_mapping('u\00FE') := '\00F9'; -- ù
      olas_mapping('y\00DD') := '\1EF5'; -- ỵ
      olas_mapping('y\00DE') := '\00FD'; -- ý
      olas_mapping('y\00EC') := '\1EF9'; -- ỹ
      olas_mapping('y\00FD') := '\1EF7'; -- ỷ
      olas_mapping('y\00FE') := '\1EF3'; -- ỳ

      -- Processing
      v_result := asciistr(p_olas_string);
      v_startIndex := 1;
      v_foundIndex := 0;
      v_pattern := '';
      v_str := v_result;
      v_result := '';
      v_foundIndex := INSTR(v_str, '\', v_startIndex);
      while ( v_foundIndex > 0)            
      loop
          -- xy ly pattern = 6 chars
          v_pattern := substr(v_str, v_foundIndex - 1, 6);
          if not olas_mapping.EXISTS(v_pattern) then
              -- xy ly pattern = 10 chars
              v_pattern := substr(v_str, v_foundIndex, 10);
          end if;    
        if olas_mapping.EXISTS(v_pattern) then    
          if length(v_pattern) = 10 then
            -- xy ly pattern = 10 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
            v_result := v_result || olas_mapping(v_pattern);
            v_startIndex := v_foundIndex + 10;    
          else
            -- xy ly pattern = 6 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - 1 - v_startIndex);
            v_result := v_result || olas_mapping(v_pattern);
            v_startIndex := v_foundIndex - 1 + 6;    
          end if;
        else
          -- xy ly pattern = 5 chars
          v_pattern := substr(v_str, v_foundIndex, 5);
          v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
          v_result := v_result || v_pattern;
          case
            when v_pattern = '\00E3' then
              v_result := replace(v_result, v_pattern, '\0103'); --ã
            when v_pattern = '\00C3' then
              v_result := replace(v_result, v_pattern, '\0102'); --Ã
            when v_pattern = '\00E2' then
              v_result := replace(v_result, v_pattern, '\00E2'); --â
            when v_pattern = '\00C2' then
              v_result := replace(v_result, v_pattern, '\00C2'); --Â
            when v_pattern = '\00EA' then
              v_result := replace(v_result, v_pattern, '\00EA'); --ê
            when v_pattern = '\00CA' then
              v_result := replace(v_result, v_pattern, '\00CA'); --Ê
            when v_pattern = '\00F4' then
              v_result := replace(v_result, v_pattern, '\00F4'); --ô
            when v_pattern = '\00D4' then
              v_result := replace(v_result, v_pattern, '\00D4'); --Ô
            when v_pattern = '\00F2' then
              v_result := replace(v_result, v_pattern, '\01B0'); --ò
            when v_pattern = '\00D2' then
              v_result := replace(v_result, v_pattern, '\01AF'); --Ò
            when v_pattern = '\00F0' then
              v_result := replace(v_result, v_pattern, '\0111'); --ð
            when v_pattern = '\00D0' then
              v_result := replace(v_result, v_pattern, '\0110'); --Ð
            when v_pattern = '\00D5' then
              v_result := replace(v_result, v_pattern, '\01A0'); --Õ
            when v_pattern = '\00F5' then
              v_result := replace(v_result, v_pattern, '\01A1'); --õ
            else
              v_result := v_result;
          end case;
          v_startIndex := v_foundIndex + 5;              
        end if;
         v_foundIndex := INSTR(v_str, '\', v_startIndex);
      end loop;
      v_str := v_result || substr(v_str,v_startIndex);
      v_result := v_str;
      RETURN unistr(v_result);
    END OLAS_TO_UNI;

    -- OLAS 1258 TO UNI
    FUNCTION  OLAS1258_TO_UNI (p_olas1258_string varchar2) RETURN VARCHAR2 AS
    /*
     *  OLAS codepage 1258 to Unicode conversion
     *
     *  The process consists of 3 parts:
     *
     *  1) process which patterns have 6 chars
     *  2) and then, process which patterns have 10 chars
     *  3) process which patterns have 5 chars
     *
     * @author     Nguyen Tich Thanh
     * @version    1.0, 16/05/2011
     */
      olas1258_mapping MAPPING_T;
      v_result VARCHAR2(512);
      v_pattern VARCHAR2(10);
      v_str  VARCHAR2(512);
      v_startIndex PLS_INTEGER;
      v_foundIndex PLS_INTEGER;
    BEGIN
      -- Initialization for olas1258_mapping
      olas1258_mapping('a\00EC') := '\00E1'; --aì
      olas1258_mapping('a\00CC') := '\00E0'; --aÌ
      olas1258_mapping('a\00D2') := '\1EA3'; --aÒ
      olas1258_mapping('a\00DE') := '\00E3'; --aÞ
      olas1258_mapping('a\00F2') := '\1EA1'; --aò
      olas1258_mapping('A\00EC') := '\00C1'; --Aì
      olas1258_mapping('A\00CC') := '\00C0'; --AÌ
      olas1258_mapping('A\00D2') := '\1EA2'; --AÒ
      olas1258_mapping('A\00DE') := '\00C3'; --AÞ
      olas1258_mapping('A\00F2') := '\1EA0'; --Aò
      olas1258_mapping('\00E3\00EC') := '\1EAF'; --ãì
      olas1258_mapping('\00E3\00CC') := '\1EB1'; --ãÌ
      olas1258_mapping('\00E3\00D2') := '\1EB3'; --ãÒ
      olas1258_mapping('\00E3\00DE') := '\1EB5'; --ãÞ
      olas1258_mapping('\00E3\00F2') := '\1EB7'; --ãò
      olas1258_mapping('\00C3\00EC') := '\1EAE'; --Ãì
      olas1258_mapping('\00C3\00CC') := '\1EB0'; --ÃÌ
      olas1258_mapping('\00C3\00D2') := '\1EB2'; --ÃÒ
      olas1258_mapping('\00C3\00DE') := '\1EB4'; --ÃÞ
      olas1258_mapping('\00C3\00F2') := '\1EA0'; --Ãò
      olas1258_mapping('\00E2\00EC') := '\1EA5'; --âì
      olas1258_mapping('\00E2\00CC') := '\1EA7'; --âÌ
      olas1258_mapping('\00E2\00D2') := '\1EA9'; --âÒ
      olas1258_mapping('\00E2\00DE') := '\1EAB'; --âÞ
      olas1258_mapping('\00E2\00F2') := '\1EAD'; --âò
      olas1258_mapping('\00C2\00EC') := '\1EA4'; --Âì
      olas1258_mapping('\00C2\00CC') := '\1EA6'; --ÂÌ
      olas1258_mapping('\00C2\00D2') := '\1EA8'; --ÂÒ
      olas1258_mapping('\00C2\00DE') := '\1EAA'; --ÂÞ
      olas1258_mapping('\00C2\00F2') := '\1EAC'; --Âò
      olas1258_mapping('e\00EC') := '\00E9'; --eì
      olas1258_mapping('e\00CC') := '\00E8'; --eÌ
      olas1258_mapping('e\00D2') := '\1EBB'; --eÒ
      olas1258_mapping('e\00DE') := '\1EBD'; --eÞ
      olas1258_mapping('e\00F2') := '\1EB9'; --eò
      olas1258_mapping('E\00EC') := '\00C9'; --Eì
      olas1258_mapping('E\00CC') := '\00C8'; --EÌ
      olas1258_mapping('E\00D2') := '\1EBA'; --EÒ
      olas1258_mapping('E\00DE') := '\1EBC'; --EÞ
      olas1258_mapping('E\00F2') := '\1EB8'; --Eò
      olas1258_mapping('\00EA\00EC') := '\1EBF'; --êì
      olas1258_mapping('\00EA\00CC') := '\1EC1'; --êÌ
      olas1258_mapping('\00EA\00D2') := '\1EC3'; --êÒ
      olas1258_mapping('\00EA\00DE') := '\1EC5'; --êÞ
      olas1258_mapping('\00EA\00F2') := '\1EC7'; --êò
      olas1258_mapping('\00CA\00EC') := '\1EBE'; --Êì
      olas1258_mapping('\00CA\00CC') := '\1EC0'; --ÊÌ
      olas1258_mapping('\00CA\00D2') := '\1EC2'; --ÊÒ
      olas1258_mapping('\00CA\00DE') := '\1EC4'; --ÊÞ
      olas1258_mapping('\00CA\00F2') := '\1EC6'; --Êò
      olas1258_mapping('o\00EC') := '\00F3'; --oì
      olas1258_mapping('o\00CC') := '\00F2'; --oÌ
      olas1258_mapping('o\00D2') := '\1ECF'; --oÒ
      olas1258_mapping('o\00DE') := '\00F5'; --oÞ
      olas1258_mapping('o\00F2') := '\1ECD'; --oò
      olas1258_mapping('O\00EC') := '\00D3'; --Oì
      olas1258_mapping('O\00CC') := '\00D2'; --OÌ
      olas1258_mapping('O\00D2') := '\1ECE'; --OÒ
      olas1258_mapping('O\00DE') := '\00D5'; --OÞ
      olas1258_mapping('O\00F2') := '\1ECC'; --Oò
      olas1258_mapping('\00F4\00EC') := '\1ED1'; --ôì
      olas1258_mapping('\00F4\00CC') := '\1ED3'; --ôÌ
      olas1258_mapping('\00F4\00D2') := '\1ED5'; --ôÒ
      olas1258_mapping('\00F4\00DE') := '\1ED7'; --ôÞ
      olas1258_mapping('\00F4\00F2') := '\1ED9'; --ôò
      olas1258_mapping('\00D4\00EC') := '\1ED0'; --Ôì
      olas1258_mapping('\00D4\00CC') := '\1ED2'; --ÔÌ
      olas1258_mapping('\00D4\00D2') := '\1ED4'; --ÔÒ
      olas1258_mapping('\00D4\00DE') := '\1ED6'; --ÔÞ
      olas1258_mapping('\00D4\00F2') := '\1ED8'; --Ôò
      olas1258_mapping('y\00EC') := '\00FD'; --yì
      olas1258_mapping('y\00CC') := '\1EF3'; --yÌ
      olas1258_mapping('y\00D2') := '\1EF7'; --yÒ
      olas1258_mapping('y\00DE') := '\1EF9'; --yÞ
      olas1258_mapping('y\00F2') := '\1EF5'; --yò
      olas1258_mapping('Y\00EC') := '\00DD'; --Yì
      olas1258_mapping('Y\00CC') := '\1EF2'; --YÌ
      olas1258_mapping('Y\00D2') := '\1EF6'; --YÒ
      olas1258_mapping('Y\00DE') := '\1EF8'; --YÞ
      olas1258_mapping('Y\00F2') := '\1EF4'; --Yò
      olas1258_mapping('u\00EC') := '\00FA'; --uì
      olas1258_mapping('u\00CC') := '\00F9'; --uÌ
      olas1258_mapping('u\00D2') := '\1EE7'; --uÒ
      olas1258_mapping('u\00DE') := '\0169'; --uÞ
      olas1258_mapping('u\00F2') := '\1EE5'; --uò
      olas1258_mapping('U\00EC') := '\00DA'; --Uì
      olas1258_mapping('U\00CC') := '\00D9'; --UÌ
      olas1258_mapping('U\00D2') := '\1EE6'; --UÒ
      olas1258_mapping('U\00DE') := '\0168'; --UÞ
      olas1258_mapping('U\00F2') := '\1EE4'; --Uò
      olas1258_mapping('\00FD\00EC') := '\1EE9'; --ýì
      olas1258_mapping('\00FD\00CC') := '\1EEB'; --ýÌ
      olas1258_mapping('\00FD\00D2') := '\1EED'; --ýÒ
      olas1258_mapping('\00FD\00F2') := '\1EF1'; --ýò
      olas1258_mapping('\00DD\00EC') := '\1EE8'; --Ýì
      olas1258_mapping('\00DD\00CC') := '\1EEA'; --ÝÌ
      olas1258_mapping('\00DD\00D2') := '\1EEC'; --ÝÒ
      olas1258_mapping('\00DD\00DE') := '\1EEE'; --ÝÞ
      olas1258_mapping('\00DD\00F2') := '\1EF0'; --Ýò
      olas1258_mapping('i\00EC') := '\00ED'; --iì
      olas1258_mapping('i\00CC') := '\00EC'; --iÌ
      olas1258_mapping('i\00D2') := '\1EC9'; --iÒ
      olas1258_mapping('i\00DE') := '\0129'; --iÞ
      olas1258_mapping('i\00F2') := '\1ECB'; --iò
      olas1258_mapping('I\00EC') := '\00CD'; --Iì
      olas1258_mapping('I\00CC') := '\00CC'; --IÌ
      olas1258_mapping('I\00D2') := '\1EC8'; --IÒ
      olas1258_mapping('I\00DE') := '\0128'; --IÞ
      olas1258_mapping('\00D5\00EC') := '\1EDA'; --Õì
      olas1258_mapping('\00D5\00CC') := '\1EDC'; --ÕÌ
      olas1258_mapping('\00D5\00D2') := '\1EDE'; --ÕÒ
      olas1258_mapping('\00D5\00DE') := '\1EE0'; --ÕÞ
      olas1258_mapping('\00D5\00F2') := '\1EE2'; --Õò
      olas1258_mapping('\00F5\00EC') := '\1EDB'; --õì
      olas1258_mapping('\00F5\00CC') := '\1EDD'; --õÌ
      olas1258_mapping('\00F5\00D2') := '\1EDF'; --õÒ
      olas1258_mapping('\00F5\00DE') := '\1EE1'; --õÞ
      olas1258_mapping('\00F5\00F2') := '\1EE3'; --õò
      olas1258_mapping('\00EA\00DE') := '\1EC5'; --êÞ
      olas1258_mapping('\00FD\00DE') := '\1EEF'; --ýÞ
      olas1258_mapping('I\00F2') := '\1ECA'; --Iò
      olas1258_mapping('I') := 'I'; --I

      -- Processing
      -- Part 1
      v_result := asciistr(p_olas1258_string);
      v_startIndex := 1;
      v_foundIndex := 0;
      v_pattern := '';
      v_str := v_result;
      v_result := '';
      v_foundIndex := INSTR(v_str, '\', v_startIndex);
      -- xy ly
      while ( v_foundIndex > 0)            
      loop
          -- assign v_pattern = 6 chars
          v_pattern := substr(v_str, v_foundIndex - 1, 6);
          if not olas1258_mapping.EXISTS(v_pattern) then
              -- assign v_pattern = 10 chars
              v_pattern := substr(v_str, v_foundIndex, 10);
          end if;    
        if olas1258_mapping.EXISTS(v_pattern) then    
          if length(v_pattern) = 10 then
            --xu ly 10 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
            v_result := v_result || olas1258_mapping(v_pattern);
            v_startIndex := v_foundIndex + 10;    
          else
            --xu ly 6 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - 1 - v_startIndex);
            v_result := v_result || olas1258_mapping(v_pattern);
            v_startIndex := v_foundIndex - 1 + 6;    
          end if;
        else
          --xu ly 5 chars
          v_pattern := substr(v_str, v_foundIndex, 5);
          v_result := v_result || substr(v_str, v_startIndex, v_foundIndex - v_startIndex);
          v_result := v_result || v_pattern;
          case
             when v_pattern = '\00E3' then
                v_result := replace(v_result, v_pattern, '\0103'); --ã
             when v_pattern = '\00C3' then
                v_result := replace(v_result, v_pattern, '\0102'); --Ã
             when v_pattern = '\00E2' then
                v_result := replace(v_result, v_pattern, '\00E2'); --â
             when v_pattern = '\00C2' then
                v_result := replace(v_result, v_pattern, '\00C2'); --Â
             when v_pattern = '\00EA' then
                v_result := replace(v_result, v_pattern, '\00EA'); --ê
             when v_pattern = '\00CA' then
                v_result := replace(v_result, v_pattern, '\00CA'); --Ê
             when v_pattern = '\00F4' then
                v_result := replace(v_result, v_pattern, '\00F4'); --ô
             when v_pattern = '\00D4' then
                v_result := replace(v_result, v_pattern, '\00D4'); --Ô
             when v_pattern = '\00FD' then
                v_result := replace(v_result, v_pattern, '\01B0'); --ý
             when v_pattern = '\00DD' then
                v_result := replace(v_result, v_pattern, '\01AF'); --Ý
             when v_pattern = '\00F2' then
                v_result := replace(v_result, v_pattern, '\1ECA'); --ò
             when v_pattern = '\00F0' then
                v_result := replace(v_result, v_pattern, '\0111'); --ð
             when v_pattern = '\00D0' then
                v_result := replace(v_result, v_pattern, '\0110'); --Ð
             when v_pattern = '\00D5' then
                v_result := replace(v_result, v_pattern, '\01A0'); --Õ
             when v_pattern = '\00F5' then
                v_result := replace(v_result, v_pattern, '\01A1'); --õ
             else
                v_result := v_result;
          end case;
          v_startIndex := v_foundIndex + 5;              
        end if;
         v_foundIndex := INSTR(v_str, '\', v_startIndex);
      end loop;
      v_str := v_result || substr(v_str,v_startIndex);
      v_result := v_str;
      RETURN unistr(v_result);
    END OLAS1258_TO_UNI;

    -- Unicode to Vni
    FUNCTION  UNI_TO_VNI (p_uni_string varchar2) RETURN VARCHAR2 AS
    /*
     *  Unicode to Vni conversion
     *
     * @author     Nguyen Tich Thanh
     * @version    1.0, 16/05/2011
     */
      uni_mapping MAPPING_T;
      v_result VARCHAR2(512);
      v_pattern VARCHAR2(10);
      v_str  VARCHAR2(512);
      v_startIndex PLS_INTEGER;
      v_foundIndex PLS_INTEGER;
    BEGIN
      -- Initialization for uni_mapping
      uni_mapping('\00E1') := 'a\00F9'; --á
      uni_mapping('\00E0') := 'a\00F8'; --à
      uni_mapping('\1EA3') := 'a\00FB'; --ả
      uni_mapping('\00E3') := 'a\00F5'; --ã
      uni_mapping('\1EA1') := 'a\00EF'; --ạ
      uni_mapping('\00C1') := 'A\00D9'; --Á
      uni_mapping('\00C0') := 'A\00D8'; --À
      uni_mapping('\1EA2') := 'A\00DB'; --Ả
      uni_mapping('\00C3') := 'A\00D5'; --Ã
      uni_mapping('\1EA0') := 'A\00CF'; --Ạ
      uni_mapping('\1EAF') := 'a\00E9'; --ắ
      uni_mapping('\1EB1') := 'a\00E8'; --ằ
      uni_mapping('\1EB3') := 'a\00FA'; --ẳ
      uni_mapping('\1EB5') := 'a\00FC'; --ẵ
      uni_mapping('\1EB7') := 'a\00EB'; --ặ
      uni_mapping('\1EAE') := 'A\00C9'; --Ắ
      uni_mapping('\1EB0') := 'A\00C8'; --Ằ
      uni_mapping('\1EB2') := 'A\00DA'; --Ẳ
      uni_mapping('\1EB4') := 'A\00DC'; --Ẵ
      uni_mapping('\1EA0') := 'A\00CF'; --Ạ
      uni_mapping('\1EA5') := 'a\00E1'; --ấ
      uni_mapping('\1EA7') := 'a\00E0'; --ầ
      uni_mapping('\1EA9') := 'a\00E5'; --ẩ
      uni_mapping('\1EAB') := 'a\00E3'; --ẫ
      uni_mapping('\1EAD') := 'a\00E4'; --ậ
      uni_mapping('\1EA4') := 'A\00C1'; --Ấ
      uni_mapping('\1EA6') := 'A\00C0'; --Ầ
      uni_mapping('\1EA8') := 'A\00C5'; --Ẩ
      uni_mapping('\1EAA') := 'A\00C3'; --Ẫ
      uni_mapping('\1EAC') := 'A\00C4'; --Ậ
      uni_mapping('\00E9') := 'e\00F9'; --é
      uni_mapping('\00E8') := 'e\00F8'; --è
      uni_mapping('\1EBB') := 'e\00FB'; --ẻ
      uni_mapping('\1EBD') := 'e\00F5'; --ẽ
      uni_mapping('\1EB9') := 'e\00EF'; --ẹ
      uni_mapping('\00C9') := 'E\00D9'; --É
      uni_mapping('\00C8') := 'E\00D8'; --È
      uni_mapping('\1EBA') := 'E\00DB'; --Ẻ
      uni_mapping('\1EBC') := 'E\00D5'; --Ẽ
      uni_mapping('\1EB8') := 'E\00CF'; --Ẹ
      uni_mapping('\1EBF') := 'e\00E1'; --ế
      uni_mapping('\1EC1') := 'e\00E0'; --ề
      uni_mapping('\1EC3') := 'e\00E5'; --ể
      uni_mapping('\1EC5') := 'e\00E3'; --ễ
      uni_mapping('\1EC7') := 'e\00E4'; --ệ
      uni_mapping('\1EBE') := 'E\00C1'; --Ế
      uni_mapping('\1EC0') := 'E\00C0'; --Ề
      uni_mapping('\1EC2') := 'E\00C5'; --Ể
      uni_mapping('\1EC4') := 'E\00C3'; --Ễ
      uni_mapping('\1EC6') := 'E\00C4'; --Ệ
      uni_mapping('\00F3') := 'o\00F9'; --ó
      uni_mapping('\00F2') := 'o\00F8'; --ò
      uni_mapping('\1ECF') := 'o\00FB'; --ỏ
      uni_mapping('\00F5') := 'o\00F5'; --õ
      uni_mapping('\1ECD') := 'o\00EF'; --ọ
      uni_mapping('\00D3') := 'O\00D9'; --Ó
      uni_mapping('\00D2') := 'O\00D8'; --Ò
      uni_mapping('\1ECE') := 'O\00DB'; --Ỏ
      uni_mapping('\00D5') := 'O\00D5'; --Õ
      uni_mapping('\1ECC') := 'O\00CF'; --Ọ
      uni_mapping('\1ED1') := 'o\00E1'; --ố
      uni_mapping('\1ED3') := 'o\00E0'; --ồ
      uni_mapping('\1ED5') := 'o\00E5'; --ổ
      uni_mapping('\1ED7') := 'o\00E3'; --ỗ
      uni_mapping('\1ED9') := 'o\00E4'; --ộ
      uni_mapping('\1ED0') := 'O\00C1'; --Ố
      uni_mapping('\1ED2') := 'O\00C0'; --Ồ
      uni_mapping('\1ED4') := 'O\00C5'; --Ổ
      uni_mapping('\1ED6') := 'O\00C3'; --Ỗ
      uni_mapping('\1ED8') := 'O\00C4'; --Ộ
      uni_mapping('\00FD') := 'y\00F9'; --ý
      uni_mapping('\1EF3') := 'y\00F8'; --ỳ
      uni_mapping('\1EF7') := 'y\00FB'; --ỷ
      uni_mapping('\1EF9') := 'y\00F5'; --ỹ
      uni_mapping('\1EF5') := '\00EE'; --ỵ
      uni_mapping('\00DD') := 'Y\00D9'; --Ý
      uni_mapping('\1EF2') := 'Y\00D8'; --Ỳ
      uni_mapping('\1EF6') := 'Y\00DB'; --Ỷ
      uni_mapping('\1EF8') := 'Y\00D5'; --Ỹ
      uni_mapping('\1EF4') := '\00CE'; --Ỵ
      uni_mapping('\00FA') := 'u\00F9'; --ú
      uni_mapping('\00F9') := 'u\00F8'; --ù
      uni_mapping('\1EE7') := 'u\00FB'; --ủ
      uni_mapping('\0169') := 'u\00F5'; --ũ
      uni_mapping('\1EE5') := 'u\00EF'; --ụ
      uni_mapping('\00DA') := 'U\00D9'; --Ú
      uni_mapping('\00D9') := 'U\00D8'; --Ù
      uni_mapping('\1EE6') := 'U\00DB'; --Ủ
      uni_mapping('\0168') := 'U\00D5'; --Ũ
      uni_mapping('\1EE4') := 'U\00CF'; --Ụ
      uni_mapping('\1EE9') := '\00F6\00F9'; --ứ
      uni_mapping('\1EEB') := '\00F6\00F8'; --ừ
      uni_mapping('\1EED') := '\00F6\00FB'; --ử
      uni_mapping('\1EF1') := '\00F6\00EF'; --ự
      uni_mapping('\1EE8') := '\00D6\00D9'; --Ứ
      uni_mapping('\1EEA') := '\00D6\00D8'; --Ừ
      uni_mapping('\1EEC') := '\00D6\00DB'; --Ử
      uni_mapping('\1EEE') := '\00D6\00D5'; --Ữ
      uni_mapping('\1EF0') := '\00D6\00CF'; --Ự
      uni_mapping('\00ED') := '\00ED'; --í
      uni_mapping('\00EC') := '\00EC'; --ì
      uni_mapping('\1EC9') := '\00E6'; --ỉ
      uni_mapping('\0129') := '\00F3'; --ĩ
      uni_mapping('\1ECB') := '\00F2'; --ị
      uni_mapping('\00CD') := '\00CD'; --Í
      uni_mapping('\00CC') := '\00CC'; --Ì
      uni_mapping('\1EC8') := '\00C6'; --Ỉ
      uni_mapping('\0128') := '\00D3'; --Ĩ
      uni_mapping('\1EDA') := '\00D4\00D9'; --Ớ
      uni_mapping('\1EDC') := '\00D4\00D8'; --Ờ
      uni_mapping('\1EDE') := '\00D4\00DB'; --Ở
      uni_mapping('\1EE0') := '\00D4\00D5'; --Ỡ
      uni_mapping('\1EE2') := '\00D4\00CF'; --Ợ
      uni_mapping('\1EDB') := '\00F4\00F9'; --ớ
      uni_mapping('\1EDD') := '\00F4\00F8'; --ờ
      uni_mapping('\1EDF') := '\00F4\00FB'; --ở
      uni_mapping('\1EE1') := '\00F4\00F5'; --ỡ
      uni_mapping('\1EE3') := '\00F4\00EF'; --ợ
      uni_mapping('\1EC5') := 'e\00E3'; --ễ
      uni_mapping('\1EEF') := '\00F6\00F5'; --ữ
      uni_mapping('\1ECA') := '\00D2'; --Ị
      uni_mapping('\0103') := 'a\00EA'; --ă
      uni_mapping('\0102') := 'A\00CA'; --Ă
      uni_mapping('\00E2') := 'a\00E2'; --â
      uni_mapping('\00C2') := 'A\00C2'; --Â
      uni_mapping('\00EA') := 'e\00E2'; --ê
      uni_mapping('\00CA') := 'E\00C2'; --Ê
      uni_mapping('\00F4') := 'o\00E2'; --ô
      uni_mapping('\00D4') := 'O\00C2'; --Ô
      uni_mapping('\01B0') := '\00F6'; --ư
      uni_mapping('\01AF') := '\00D6'; --Ư
      uni_mapping('\1ECA') := '\00D2'; --Ị
      uni_mapping('\0111') := '\00F1'; --đ
      uni_mapping('\0110') := '\00D1'; --Đ
      uni_mapping('\01A0') := '\00D4'; --Ơ
      uni_mapping('\01A1') := '\00F4'; --ơ

      -- Processing
      -- Part 1
      v_result := asciistr(p_uni_string);
      v_startIndex := 1;
      v_foundIndex := 0;
      v_pattern := '';
      v_str := v_result;
      v_result := '';
      v_foundIndex := INSTR(v_str, '\', v_startIndex);
      -- xy ly
      while ( v_foundIndex > 0)            
      loop
          -- assign v_pattern = 5 chars
          v_pattern := substr(v_str, v_foundIndex , 5);    
        if uni_mapping.EXISTS(v_pattern) then    
            --xu ly 5 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex  - v_startIndex);
            v_result := v_result || uni_mapping(v_pattern);
            v_startIndex := v_foundIndex + 5;              
        else
          --xu ly 5 chars
            v_result := v_result || substr(v_str, v_startIndex, v_foundIndex  - v_startIndex);
            v_result := v_result || v_pattern;
            v_startIndex := v_foundIndex + 5;              
        end if;
         v_foundIndex := INSTR(v_str, '\', v_startIndex);
      end loop;
      v_str := v_result || substr(v_str,v_startIndex);
      v_result := v_str;
      RETURN unistr(v_result);
    END UNI_TO_VNI;

    END CONVERTOR;