i am new in oracle sql and pl sql.i have write pl sql function that takes data from php in xml format.Here is the pl sql code below and it works fine:
FUNCTION save_overtime(overtime_data NVARCHAR2 ) RETURN clob IS ret clob;
xmlData XMLType;
v_code NUMBER;
v_errm VARCHAR2(100);
BEGIN
xmlData:=XMLType(overtime_data);
INSERT INTO TBL_OVERTIME SELECT x.* FROM XMLTABLE('/overtime'
PASSING xmlData
COLUMNS OT_EMPID NVARCHAR2(10) PATH 'employee_id',
OT_DATE DATE PATH 'date',
OT_HOUR NUMBER(4,0) PATH 'overtime_hour'
) x;
ret:=to_char(sql%rowcount);
COMMIT;
RETURN '<result><status affectedRow='||ret||'>success</status></result>';
EXCEPTION
WHEN OTHERS THEN
v_code := SQLCODE;
v_errm := SUBSTR(SQLERRM, 1, 100);
DBMS_OUTPUT.PUT_LINE (v_code || ' ' || v_errm);
-- '<result><status>Error</status> <error_message>'|| 'Error Code:' || v_code || ' ' || 'Error Message:' || v_errm ||'</error_message> </result>';
RETURN '<result><status>Error</status> <error_message>'|| 'Error Message:' || v_errm ||'</error_message> </result>';
END save_overtime;
While inserting data, I noticed that oracle table is also accepting data which are bigger than its initial size! For example, following columns accepting data which are bigger than size 10.
EMPID NVARCHAR2(10)
if the data is 12 in length then it takes the 1st 10 chars.But to me,i think it should be an invalid/error.Because, otherwise defining column size is meaningless.I know about adding constraints.But adding many constraints for such small things is very boring and tedious.If i did any wrong/mistake,then please help me to understand that.thanks