-
Selecting the number of characters from a field?
Gurus,
I'm new to SQL and I'm hoping someone can help me. I need to write an SQL statement to give me the number of users with less than 8 characters in the name. Please help!!!
-
you will need the length() function then
-
declare
v_len number;
c1_rec c1%ROWTYPE;
cursor c1 is select username from dba_users;
begin
open c1;
loop;
fetch c1 into c1_rec;
exit when c1_rec%NOTFOUND;
select getlength(c1_rec.username) into v_len from dual;
if(v_len>8)
then
dbms_output.put_line();
fi;
end loop;
close c1;
end;
Hope this will suffice your requirement.
Regards
Barun
-
I'm sorry to say that, Barun, but your script is nothing but bunch of errors.
The sql needed might be something like this:
Code:
select count(*) from the_table where length(username)<8;
Ales The whole difference between a little boy and an adult man is the price of toys
-
Originally Posted by B.B
declare
v_len number;
c1_rec c1%ROWTYPE;
cursor c1 is select username from dba_users;
begin
open c1;
loop;
fetch c1 into c1_rec;
exit when c1_rec%NOTFOUND;
select getlength(c1_rec.username) into v_len from dual;
if(v_len>8)
then
dbms_output.put_line();
fi;
end loop;
close c1;
end;
Hope this will suffice your requirement.
Regards
Barun
Wow! Script doesn't even attempt to solve poster's business specifications. Why would you do it simple and well when you can do it complex and all wrong, isn't it?
Ales is spot on correct.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|