Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

throwing error ORA-06512

SmithJohn45Apr 11 2025

Testing function for Restful Service in Oracle Apex , below is an anonymous pl/sql block then below this actual function, when run this block for a non-existing employee number (empno=10303) which should exist and off course it is throwing an error but the error message is not clear enough to understand the problem why and what error occurred, how to handle it and show complete meaningful error so user can understand what problem occur here? please help for it

note: it is working for an existing employee in master table.

declare 
-- 
    myjsonpayload clob := 
'[ 
 {
   "salary_month": "2025-02",
   "empno": "10303",
   "emp_name": "Rowin Bost",
   "date_of_joining": "2025-02-04",
   "actual_salary": "18000",
   "the_increment": null,
   "effective_from": null,
   "basic_salary_after_increment": "18000",
   "add_others": "1800",
   "less_others": "1800",
   "notes_for_add_less": "ADD: 3 DAYS DEMO, LESS: PREJOINING DAYS"
 }
]'; 
-- 
msg varchar2(3000); 
-- 
begin 
 msg :=  hr_emp_addless_create2(APEX_UTIL.CLOB_TO_BLOB(p_clob => myjsonpayload)); 
 dbms_output.put_line(msg); 
exception 
 when others then 
   dbms_output.put_line(msg||' - '||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE); 
end;

error it is showing: hr_emp_addless_create2 ORA-06512: at "EDUX.HR_EMP_ADDLESS_CREATE2", line 9

create or replace FUNCTION hr_emp_addless_create2 (p_data IN BLOB)
 RETURN VARCHAR2
 AS
c_data clob := TO_CLOB (p_data);
v_data varchar2(3000) := substr(to_char(c_data),1,1000);
t_stamp timestamp;
BEGIN
 SELECT CURRENT_TIMESTAMP INTO t_stamp FROM DUAL;
 INSERT INTO HR_EMP_ADDLESS_UPL
                         (
                          empno, 
                          salary_month, 
                          date_of_joining, 
                          actual_salary, 
                          the_increment, 
                          effective_from,
                          basic_salary_after_increment, 
                          add_others, 
                          less_others, 
                          notes_for_add_less,
                          is_locked,
                          campus_code
                         )
 SELECT l.empno,
        l.salary_month,         
        TO_DATE(l.date_of_joining,'YYYY-MM-DD'),
        l.actual_salary,
        l.the_increment,
        TO_DATE(l.effective_from,'YYYY-MM-DD'),
        l.basic_salary_after_increment,
        l.add_others,
        l.less_others,
        l.notes_for_add_less,
        'N',
        hr_get_campus_code_emp(l.empno)
  FROM  JSON_TABLE
        (TO_CLOB (p_data),
        '$[*]'
        COLUMNS
          (
           empno                         PATH '$.empno',
           salary_month                  PATH '$.salary_month',
           date_of_joining               PATH '$.date_of_joining',
           actual_salary                 PATH '$.actual_salary',
           the_increment                 PATH '$.the_increment',
           effective_from                PATH '$.effective_from',
           basic_salary_after_increment  PATH '$.basic_salary_after_increment',
           add_others                    PATH '$.add_others',
           less_others                   PATH '$.less_others',
           notes_for_add_less            PATH '$.notes_for_add_less'
           )) l;
     
 COMMIT;
 RETURN ('Add/ Less/ Incr Successfully Created...');
EXCEPTION
 WHEN OTHERS THEN
    --DBMS_OUTPUT.PUT_LINE(SQLERRM);
    insert into test_errors (error_msg) values('hr_emp_addless_create2 '||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
    commit;
     RETURN ('hr_emp_addless_create2 '||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END hr_emp_addless_create2;

with kind regards

This post has been answered by Paulzip on Apr 11 2025
Jump to Answer
Comments
Post Details
Added on Apr 11 2025
5 comments
258 views