DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Selecting the number of characters from a field?

  1. #1
    Join Date
    Nov 2005
    Posts
    10

    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!!!

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    you will need the length() function then

  3. #3
    Join Date
    Apr 2009
    Posts
    10
    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

  4. #4
    Join Date
    Apr 2001
    Location
    Czechia
    Posts
    712
    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

  5. #5
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Quote Originally Posted by B.B View Post
    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
  •  


Click Here to Expand Forum to Full Width