Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Numeric Conversion

Author  Topic 

BilalKhan
Starting Member

5 Posts

Posted - 2010-04-26 : 04:14:50
I want to convert the field value into numeric form using the formula:

?[((radix)^position * alphvalue) mod m] where
A= 10, S = 28, I = 18, N = 22, radix = 36, m= 731
The value of position is marked from right to left start-ing with 0.

For Example:
ASIN
Let m = 731 (large prime number)

?[((36)^3 * 10)mod 731) + ((36)^2 * 28)mod 731)+
((36)^1 * 18)mod 731) + ((36)^0 * 22)mod 731) ]
= 182+ 469 + 648 + 22
= 1321

I APPLY THE FOLLOWING CODE in ORACLE.


DECLARE
A NUMBER := 10;
S NUMBER := 28;
I NUMBER := 18;
N NUMBER := 22;
radix NUMBER := 36;
m NUMBER := 731;

TYPE var_type IS TABLE OF NUMBER;


var var_type;
lp var_type;

r1 NUMBER;
r2 NUMBER;

len NUMBER;

counter NUMBER := 0;

EXP exception;
BEGIN
len := LENGTH ('ASIM');
lp := var_type ();
lp.EXTEND (len + 1);


FOR i IN REVERSE 1 .. len
LOOP
lp (i) := i;
--DBMS_OUTPUT.put_line (lp (i));
END LOOP;

var :=
var_type (A,
S,
I,
N);

FOR i IN REVERSE lp.FIRST .. lp.LAST
LOOP
FOR j IN var.FIRST .. var.LAST + 1
LOOP
BEGIN
IF lp (i) IS NULL
THEN
RAISE EXP;
END IF;

--DBMS_OUTPUT.put_line ('i=' || i || 'j=' || j || 'Varj' || var (j)|| 'Varj' || nvl(lp (j),0));
DBMS_OUTPUT.put_line ('When values of Variable is' || var (i) || '-and loop is=' || lp (j));
r1 := MOD ( (POWER (radix, lp (j)) * NVL (var (i), 0)), m);
DBMS_OUTPUT.put_line (r1);



counter := counter + 1;

IF var.COUNT IS NOT NULL
THEN
var.delete (counter);
END IF;

EXIT;
EXCEPTION
WHEN EXP
THEN
DBMS_OUTPUT.put_line ('When values of Variable is' || 0|| '-and loop is=' || lp (j));

r2 := MOD ( (POWER (radix, 0) * var (i)), m);
DBMS_OUTPUT.put_line (r2);
EXIT;
WHEN OTHERS
THEN
EXIT;
END;
END LOOP;


len := len - 1;
END LOOP;
END;


But it show th e following error messages i.e

ORA-06533: Subscript beyond count
ORA-06512: at line 53
ORA-06510: PL/SQL: unhandled user-defined exception



I WANT THAT PROGRAM Convert all the field value in numeric form using above formula. it it Possible then help me in this regards! thanks.

Student

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-04-26 : 04:22:26
This is a Microsoft SQL Server forum.
Do you need help with

a) Converting the code to Microsoft SQL Server T-SQL
b) Debugging the code for Oracle




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

BilalKhan
Starting Member

5 Posts

Posted - 2010-04-26 : 04:29:32
Sir i want to convert the field value using the formula
?[((radix)^ position * alphvalue) mod pr] for example

ASIM
Let pr = 731 (large prime number)
whereAlphavalue A = 10, B= 11,......Z=35
radix = 36,
position value start from right to left, mean right most alphabet position value is 0, next is 1 and so on

For Example:
ASIM
?[((36)3 * 10)mod 731) + ((36)2 * 28)mod 731)+
((36)1 * 18)mod 731) + ((36)0 * 22)mod 731) ]
= 182+ 469 + 648 + 22

= 1321

So plz help me to convert the Name field value into numeric form


Student
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-04-26 : 06:29:32
...using Microsoft T-SQL code or using PL-SQL?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

BilalKhan
Starting Member

5 Posts

Posted - 2010-04-27 : 02:47:12
I need PL/SQL Code. plz help me in this regards!

Student
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-27 : 02:58:20
quote:
Originally posted by BilalKhan

I need PL/SQL Code. plz help me in this regards!

Student


Post your question at Oracle forums such as www.orafaq.com

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

BilalKhan
Starting Member

5 Posts

Posted - 2010-04-27 : 03:34:18
if u send me in T-SQL, then it also help me in this regards!
Go to Top of Page
   

- Advertisement -