473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

basic plsql question

i had a basic question on plsql, if i have a variable as varchar2,
containing some text like 'A12345', how do i write a function to make
sure that the first char. is the letter 'A' or 'a' and the next five
characters are numbers? sorry about asking a basic question, but i'm
not the dba here, he recently left and i'm just the web developer
having to do this for now.
Jul 19 '05 #1
5 4842

"jmaxsherkimer" <jm***********@hotmail.com> wrote in message
news:f8**************************@posting.google.c om...
i had a basic question on plsql, if i have a variable as varchar2,
containing some text like 'A12345', how do i write a function to make
sure that the first char. is the letter 'A' or 'a' and the next five
characters are numbers? sorry about asking a basic question, but i'm
not the dba here, he recently left and i'm just the web developer
having to do this for now.

Look in the docs you can find documentation at otn.oracle.com. Look in the
SQL Reference guide. (there are a ton of docs, but that is the one you want)
You will probably use substr and translate. You can test it in sqlplus by
select substr('A12345',1,1) from dual;

etc.
That will allow you to evaluate the expression so you can test your function
quickly. Once you are satisfied with your exprerssion you can put the
expression in your code.
Jim
Jul 19 '05 #2
This function will let you test the format any string up to 50
characters. You may modify is needed.

function word_format (word varchar2) return varchar2 is
fmt varchar2(50);
ltr char(1);
begin
for x in 1..length(word) loop
ltr := substr(word,x,1);
fmt := fmt || case
when ltr between 'A' and 'Z' then 'X'
when ltr between 'a' and 'z' then 'X'
when ltr between '0' and '9' then '9'
else ltr
end;
end loop;

return fmt;
end;
/

if word_format('A54698') = 'X99999' then
.....
end if;
Jul 19 '05 #3
This procedure is better. You could use the translate function alone,
but the string parameters would make your code long and unwieldy.

create function word_fmt (word varchar2) return varchar2 is
begin
return translate(word,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX9999999999'
);
end;

if word_fmt('a52132') = 'X99999' then
.....
end if;

or

if translate(word, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX9999999999') =
'X99999' then
....
end if;
Jul 19 '05 #4
You can use regular expressions on 10g.

see the documentation at http://tahiti.oracle.com

bye,
pedro
jmaxsherkimer wrote:
i had a basic question on plsql, if i have a variable as varchar2,
containing some text like 'A12345', how do i write a function to make
sure that the first char. is the letter 'A' or 'a' and the next five
characters are numbers? sorry about asking a basic question, but i'm
not the dba here, he recently left and i'm just the web developer
having to do this for now.

Jul 19 '05 #5
r0***@insightbb.com (Wario) wrote in message news:<92**************************@posting.google. com>...
This procedure is better. You could use the translate function alone,
but the string parameters would make your code long and unwieldy.

create function word_fmt (word varchar2) return varchar2 is
begin
return translate(word,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX9999999999'
);
end;

First character should be 'a' or 'A', other four characters are digits,
so translate function call can look like

translate(word, 'aA0123456789', 'AA9999999999')

if word_fmt('a52132') = 'X99999' then
.....
end if;

or

if translate(word, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX9999999999') =
'X99999' then
....
end if;

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Corrine | last post by:
I am trying to pass a temporary BLOB that I've created in Java, to a PLSQL function that modifies it, and then to retrieve this modified value back to Java, all using JDBC. I can't figure out...
11
by: David | last post by:
I am learning plsql. I would like to run a stored procedure to calculate my bank account value by predicted 10% annual growth rate. Below is my plsql that is having problems. Your help is highly...
15
by: marvado | last post by:
Hi, can I run phpinfo(); or any php code from an oracle plsql package using htp.p from the oracle web toolkit owa? what I need is to run any php code using htp.p() I might be missing...
1
amitpatel66
by: amitpatel66 | last post by:
Hi, Is PLSQL Anonymous block allowed in CASE WHEN statement when CASE is used in SELECT statement. Check below code which executes but does not return anything: SELECT job, CASE WHEN job =...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
0
by: dreams | last post by:
Hi every one, I don't know how to retrieve the result from plsql into vb :( my plsql function is: create or replace function log_in (name in int) return int is x int; begin x :=1;
0
by: sybrandb | last post by:
"Jorge Pinto" <jorgep@sympatico.cawrote in message news:<L2HQa.3116$104.264170@news20.bellglobal.com>... utl_smtp is only a wrapper for a java procedure. Need I say more. And oh yes, you may need...
5
by: jmaxsherkimer | last post by:
i had a basic question on plsql, if i have a variable as varchar2, containing some text like 'A12345', how do i write a function to make sure that the first char. is the letter 'A' or 'a' and the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.