In Oracle APEX, the Amount page item is configured as a Number field with a format mask, while the corresponding backend database column (AMT) is defined as a NUMBER data type.
During runtime, APEX applies the format mask at the session state level, resulting in values that include thousand separators (commas).
When the session value is persisted to the database, this formatted string causes a data type conversion error, since the AMT column expects a pure numeric value.
To handle this, developers typically apply the TO_NUMBER() conversion function in PL/SQL processes to strip formatting before DML operations.
This ensures data integrity and prevents ORA-01722 (invalid number) errors during inserts or updates.
Instead of using a format mask, we can apply below JavaScript code on the global page and call it wherever needed.
function setformatAuto(input) {
const formatter = new Intl.NumberFormat('en-IN', {
currency: 'INR',
minimumFractionDigits: 2
});
// Check if input is an APEX page item
if (apex.item(input)) {
var val = apex.item(input).getValue();
if (val !== '') {
var reslt = formatter.format(val).replace(/\D00$/, '');
apex.item(input).setValue(reslt, '', true);
}
} else {
// Treat input as a selector for HTML elements
$(input).each(function() {
var val = $(this).text();
if (val !== '') {
var reslt = formatter.format(val).replace(/\D00$/, '');
$(this).text(reslt);
}
});
}
}
If the user expects the mask to appear while entering the value, call the function on custom attribute section like below.
onkeyup="setformatAuto(this);"
Comments
Post a Comment