DBAsupport.com Forums - Powered by vBulletin
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Palindrome

  1. #1
    Join Date
    Jun 2003
    Location
    australia
    Posts
    74

    Palindrome

    Hi if you are looking for some DBA stuff then dont' read...this is just for programming skills.

    Can anyone tell me how I can write a program in pl/sql, which would say if a given string is palindrome or not????

    Palindrome:
    A word, phrase, verse, or sentence that reads the same backward or forward. For example: MADAM

    Thanks in advance
    rajorcl

  2. #2
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    use the to_palindrom function
    I'm stmontgo and I approve of this message

  3. #3
    Join Date
    Feb 2001
    Location
    Adelaide, Australia
    Posts
    159

    Re: Palindrome

    Originally posted by kanthbethi
    Hi if you are looking for some DBA stuff then dont' read...this is just for programming skills.
    Then why the heck have you posted this in the 'Database Administration' forum!!???


  4. #4
    Join Date
    Jun 2003
    Location
    australia
    Posts
    74
    thought that someone who had nothing to do like me would help me with it. If you can help, but don't be nutzzzzzzzzzzzzzz
    rajorcl

  5. #5
    Join Date
    Dec 2001
    Location
    Slovenia, Kranj
    Posts
    82
    CREATE OR REPLACE FUNCTION palindrome
    (str VARCHAR2)
    RETURN NUMBER
    IS
    t NUMBER;
    len NUMBER;
    BEGIN
    len := LENGTH(str);
    --
    FOR t IN 1..len LOOP
    IF SUBSTR(str,t,1) <> SUBSTR(str,len-t+1,1) THEN
    RETURN 0;
    END IF;
    END LOOP;
    --
    RETURN 1;
    END;

    Next time please post this type of question in the right forum (it's not so hard you know)

    Well I have something to do...I am helping you

  6. #6
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    Originally posted by kanthbethi
    thought that someone who had nothing to do like me would help me with it. If you can help, but don't be nutzzzzzzzzzzzzzz
    I am all for helping people but you cross posted this in more than one forum and showed no attempt at even trying it. I am much more inclined to help someone who posts code and says , hey I tried this but it does not work can you offer any suggestions
    I'm stmontgo and I approve of this message

  7. #7
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    Interesting way to get your high-school homework done; ask somebody else.
    Jeff Hunter

  8. #8
    Join Date
    Jun 2003
    Location
    australia
    Posts
    74
    Ok .......sorry to all you big brothers....I was eager to learn, but I forgot to mention that I was trying and will keep trying so that I will be helping others as you are doing now.

    Ok here is what I have done for prime numbers and palindromes, If I have made any mistakes in them please do tell me.

    -------------PRIME NUMBERS---------

    declare
    v_cont number :=2;
    v_prime number :=&Num;
    begin
    for v_cont in 2..200
    loop
    if v_prime > 200 then
    dbms_output.put_line('Number too Large');
    exit;
    elsif
    v_prime <= 0 then
    dbms_output.put_line('Number too Small');
    exit;
    elsif
    mod(v_prime, v_cont) = 0 then
    dbms_output.put_line('Number ' ||v_prime|| ' is not a Prime number');
    exit;
    elsif v_cont = v_prime-1 then
    dbms_output.put_line('Number ' ||v_prime|| ' is a Prime number');
    end if;
    exit when v_cont=v_prime-1;
    end loop;
    end;
    /

    ------------PALINDROME-------
    Declare
    word VARCHAR2 (100):='&word';
    i number;
    j number;
    BEGIN
    j:=LENGTH(word);
    FOR i IN 1..j
    LOOP
    IF SUBSTR(word,i,1) != SUBSTR(word,j-i+1,1) THEN
    dbms_output.put_line(word|| ' is not a Palindrome');
    exit;
    else
    dbms_output.put_line(word|| ' is a Palindrome');
    exit;
    END IF;
    END LOOP;
    END;
    /
    rajorcl

  9. #9
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Regarding the various palindrome routines that have been posted here:

    I find it interesting an amusing that all of you are substringing the whole input string, letter by letter from first to last. Wouldn't it be quicker to check only the letters from the first half of the input string?

    So instead of something like that:
    Code:
    j:=LENGTH(word);
    FOR i IN 1..j
    LOOP
    IF SUBSTR(word,i,1) != SUBSTR(word,j-i+1,1) THEN
    ...
    use something like that:
    Code:
    j:=TRUNC(LENGTH(word)/2);
    FOR i IN 1..j
    LOOP
    IF SUBSTR(word,i,1) != SUBSTR(word,-i,1) THEN
    ...
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  10. #10
    Join Date
    Oct 2003
    Posts
    65
    Hello kanthbethi,

    First learn how to ask Q in a forum.If you dont have any work..dont think even others will be like you.

    if you have this type of attitude you will never learn things or no one will be ready to help you out.

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