keerthi2016
Programmer
Oracle : 9i.
I was about to check whether the field is numeric or not. I have written a oralce function to check whether it is numeric or not.
Even for null values it is returning as numeric values. Could you please let me know what is wrong in my procedure.
I was about to check whether the field is numeric or not. I have written a oralce function to check whether it is numeric or not.
Even for null values it is returning as numeric values. Could you please let me know what is wrong in my procedure.
Code:
Input Values :
Column Name : ZIP_CODE Data Type varchar2
1. null
2. 8937
3. 4757
4. null
5. null
6. null
create or replace procedure Main
AS
cursor data
IS
select CHAIN_ID,INTERNAL_CONTACT, ZIP_CODE, ZIP_EXTENSION from staging;
v_chainid NUMBER;
v_zip NUMBER;
v_internalcontact NUMBER;
v_zipcode NUMBER;
BEGIN
for i in data loop
select count(*) into v_chainid from chain where chain_id=i.CHAIN_ID;
select count(*) into v_internalcontact from RSG_REPS where internal_contact=UPPER(LTRIM(RTRIM(i.INTERNAL_CONTACT)));
select IS_NUMBER(i.ZIP_CODE)INTO v_zipcode from DUAL;
if v_zipcode=1 THEN
DBMS_OUTPUT.PUT_LINE ('Datas are numeric'|| v_zipcode);
else
DBMS_OUTPUT.PUT_LINE ('Datas are not numeric'|| v_zipcode);
END IF;
end loop;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Program errors while sending email due to:'||SQLERRM);
END;
Function :
CREATE or replace FUNCTION is_number (p_string IN VARCHAR2)
RETURN INT
IS
v_new_num NUMBER;
BEGIN
v_new_num := TO_NUMBER(p_string);
RETURN 1;
EXCEPTION
WHEN VALUE_ERROR THEN
RETURN 0;
END is_number;
set serveroutput on
exec main
Output:
Data are numeric1
Data are numeric1
Data are numeric1
Data are numeric1
Data are numeric1
[code]