oracle 9i [message #393756] |
Tue, 24 March 2009 05:03 |
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 #393771 is a reply to message #393756] |
Tue, 24 March 2009 05:33 |
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 #393782 is a reply to message #393756] |
Tue, 24 March 2009 05:53 |
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 |
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 #393792 is a reply to message #393789] |
Tue, 24 March 2009 06:21 |
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 |
|
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 but as posted by the original poster and me being confused with its usage.
|
|
|