Home » Developer & Programmer » Forms » oracle 9i (xp)
oracle 9i [message #393756] Tue, 24 March 2009 05:03 Go to next message
pratik123
Messages: 41
Registered: October 2007
Location: hyderabad
Member
hi seniours
i am new in procedure writing

can some detail explai (output) of this script


BEGIN
IF LENGTH(p_text) MOD 8 > 0 THEN
l_units := TRUNC(LENGTH(p_text)/8) + 1;
p_text := RPAD(p_text, l_units * 8, g_pad_chr);
END IF;
END;

x in advance
Re: oracle 9i [message #393758 is a reply to message #393756] Tue, 24 March 2009 05:09 Go to previous messageGo to next message
mm_kanish05
Messages: 493
Registered: January 2007
Location: Chennai
Senior Member

If pl/sql use

dbms_output.put_line

if Forms use

Message

Kanish
Re: oracle 9i [message #393767 is a reply to message #393756] Tue, 24 March 2009 05:26 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
First of all, there's no output at all (as Kanish has already said). Moreover, your piece of code is invalid so it won't do anything:
SQL> select length('some text') mod 8
  2  from dual;
select length('some text') mod 8
                               *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

Therefore, unless you provide more (meaningful) information, it is difficult to help.
Re: oracle 9i [message #393771 is a reply to message #393756] Tue, 24 March 2009 05:33 Go to previous messageGo to next message
cookiemonster
Messages: 13963
Registered: September 2008
Location: Rainy Manchester
Senior Member
Littlefoot: I thought it waws invalid when I first clapped eyes on it, but apparently it's not:
Connected to:
Oracle Database 10g Release 10.2.0.2.0 - 64bit Production

SQL> set serveroutput on
SQL> DECLARE
  2  
  3    p_text VARCHAR2(9) := 'AAAAAAAAA';
  4  
  5  BEGIN
  6  
  7    dbms_output.put_line(LENGTH(p_text) MOD 8);
  8    
  9  END;
 10  /
1

PL/SQL procedure successfully completed.

SQL> 



O/P: try using dbms_output.put_line or message to display the values calculated by each line. Then it should become obvious what it's doing.
Re: oracle 9i [message #393775 is a reply to message #393756] Tue, 24 March 2009 05:39 Go to previous messageGo to next message
rajy_salim
Messages: 204
Registered: January 2008
Location: Beirut - Lebanon
Senior Member
dbms_output.put_line does not work in Forms, but message;pause; does perfectly.

Rajy
Re: oracle 9i [message #393782 is a reply to message #393756] Tue, 24 March 2009 05:53 Go to previous messageGo to next message
pratik123
Messages: 41
Registered: October 2007
Location: hyderabad
Member
ok full script is

CREATE OR REPLACE PACKAGE BODY toolkit AS

  g_key     RAW(32767)  := UTL_RAW.cast_to_raw('12345678');
  g_pad_chr VARCHAR2(1) := '~';

  PROCEDURE padstring (p_text  IN OUT  VARCHAR2);


  -- --------------------------------------------------
  FUNCTION encrypt (p_text  IN  VARCHAR2) RETURN RAW IS
  -- --------------------------------------------------
    l_text       VARCHAR2(32767) := p_text;
    l_encrypted  RAW(32767);
  BEGIN
    padstring(l_text);
    DBMS_OBFUSCATION_TOOLKIT.desencrypt(input          => UTL_RAW.cast_to_raw(l_text),
                                        key            => g_key,
                                        encrypted_data => l_encrypted);
    RETURN l_encrypted;
  END;
  -- --------------------------------------------------



  -- --------------------------------------------------
  FUNCTION decrypt (p_raw  IN  RAW) RETURN VARCHAR2 IS
  -- --------------------------------------------------
    l_decrypted  VARCHAR2(32767);
  BEGIN
    DBMS_OBFUSCATION_TOOLKIT.desdecrypt(input => p_raw,
                                        key   => g_key,
                                        decrypted_data => l_decrypted);

    RETURN RTrim(UTL_RAW.cast_to_varchar2(l_decrypted), g_pad_chr);
  END;
  -- --------------------------------------------------


  -- --------------------------------------------------
  PROCEDURE padstring (p_text  IN OUT  VARCHAR2) IS
  -- --------------------------------------------------
    l_units  NUMBER;
  BEGIN
    IF LENGTH(p_text) MOD 8 > 0 THEN
      l_units := TRUNC(LENGTH(p_text)/8) + 1;
      p_text  := RPAD(p_text, l_units * 8, g_pad_chr);
    END IF;
  END;
  -- --------------------------------------------------

END toolkit;
/

[EDITED by LF: applied [code] tags]

[Updated on: Tue, 24 March 2009 06:10] by Moderator

Report message to a moderator

Re: oracle 9i [message #393785 is a reply to message #393771] Tue, 24 March 2009 06:02 Go to previous messageGo to next message
cookiemonster
Messages: 13963
Registered: September 2008
Location: Rainy Manchester
Senior Member
cookiemonster wrote on Tue, 24 March 2009 10:33
try using dbms_output.put_line or message to display the values calculated by each line. Then it should become obvious what it's doing.

Re: oracle 9i [message #393789 is a reply to message #393771] Tue, 24 March 2009 06:14 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Hm, interesting. Didn't know that it works that way:
SQL> declare
  2    p_text varchar2(9) := 'aaaaaaaaa';
  3    result number;
  4  begin
  5    result := length(p_text) mod 8;
  6    dbms_output.put_line(result);
  7  end;
  8  /
1

PL/SQL procedure successfully completed.

SQL> declare
  2    p_text varchar2(9) := 'aaaaaaaaa';
  3    result number;
  4  begin
  5    select length(p_text) mod 8
  6      into result
  7      from dual;
  8    dbms_output.put_line(result);
  9  end;
 10  /
  select length(p_text) mod 8
                            *
ERROR at line 5:
ORA-06550: line 5, column 29:
PL/SQL: ORA-00923: FROM keyword not found where expected
ORA-06550: line 5, column 3:
PL/SQL: SQL Statement ignored


SQL>

So it appears that such a syntax works fine in expressions.
Re: oracle 9i [message #393792 is a reply to message #393789] Tue, 24 March 2009 06:21 Go to previous messageGo to next message
babuknb
Messages: 1736
Registered: December 2005
Location: NJ
Senior Member

SQL>  declare
  2        p_text varchar2(9) := 'aaaaaaaaa';
  3        result number;
  4      begin
  5        select mod(8,length(p_text))
  6          into result
  7          from dual;
  8        dbms_output.put_line(result);
  9     end;
 10   /
8

PL/SQL procedure successfully completed.

SQL> set serveroutput on
SQL> /
8

PL/SQL procedure successfully completed.


I hope some syntax problem in your code.

[Updated on: Tue, 24 March 2009 06:21]

Report message to a moderator

Re: oracle 9i [message #393794 is a reply to message #393792] Tue, 24 March 2009 06:26 Go to previous message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Well, it would certainly help if you'd read the whole topic (instead of only the last message).

It is not about
mod(8,length(p_text))
but
length(p_text) mod 8
as posted by the original poster and me being confused with its usage.
Previous Topic: Using Data Grid in Forms 6i
Next Topic: Validation Filed value
Goto Forum:
  


Current Time: Mon Feb 03 20:38:32 CST 2025