I am working on something. I got to check a string for validation. This string has a country code and a university code (from their own tables in the database) and a bunch of numbers. Now I need to validate this string. I need to check this string on the country code and university code and if it has numbers yes or no.
I have tried alot of things at the moment. I tried to use alot of if statements, regexp_like, instr, substr, select statements and others. But I am not capable of checking the string for it's country and university code (and if it has matching numbers).
My code at the moment is as follows:
create or replace function checkForCorrectness (
isin varchar2)
return integer
as
isCorrect integer := 0;
checkISIN varchar2(50);
checkCountryCode country.code%type;
checkUniversityCode university.code%type;
e_onbekendeLandCode exception;
e_onbekendeUniCode exception;
e_lengteNummer exception;
begin
--checkISIN := isin;
/*
if checkISIN like '%NL%'
then dbms_output.put_line('Beschikt over een landcode');
if checkISIN like '%KTU%'
then dbms_output.put_line('Beschikt over een universiteit code');
if checkISIN like ''
then dbms_output.put_line('Beschikt over een nummerreeks');
end if;
end if;
end if;
*/
--select isin
--into checkISIN
--from dual
--where regexp_like(checkISIN, '^[[:digit:]]+$');
isin := regexp_like(isin, '[[:digit:]]');
dbms_output.put_line(checkISIN);
return isCorrect;
exception
when e_lengteNummer
then dbms_output.put_line('Foutmelding: Nummereeks is kleiner dan 9');
when e_onbekendeLandCode
then dbms_output.put_line('Foutmelding: Landcode is niet geldig of bestaat niet');
when e_onbekendeUniCode
then dbms_output.put_line('Foutmelding: Universiteit code is niet geldig of bestaat niet');
end checkForCorrectness;
/
show errors function checkForCorrectness
/*
begin
dbms_output.put_line(checkForCorrectness('NL 4633 4809 KTU'));
end;
At the moment I am so confused I don't even know what to do anymore. I hope some of you guys could help me out.
To make a long story short. I got this check value (and many more):
ASSERT_EQUALS(checkForCorrectness('NL 4633 4809 KTU'),1);
ASSERT_EQUALS(checkForCorrectness('NL 4954 2537 7808 MSM'),1);
The input is a string that contains a country code (NL) a number (4633 4809) and a university code (KTU). if the result is true or it is validated it returns 1 else 0.
I hope my question is not too vague.
If someone can explain to me what kind of functions and steps I need to make/take, would be awesome
Thanks in advance
NL 4 9 5 425 MSMbe valid)? Or do numbers always appear in groups of 4? Are you trying to validate the country and university code against lookup tables? Or just check that they are two and three letter codes respectively?