473,473 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 4846

"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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.