Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR ALTER PROCEDURE PRO_ROMANOS_TO_ARABICOS (
- ANUMERAL VARCHAR(100),
- ADEFAULT INTEGER)
- RETURNS (
- RESULT INTEGER)
- AS
- DECLARE VARIABLE I INTEGER;
- DECLARE VARIABLE C CHAR(1);
- DECLARE VARIABLE N CHAR(1);
- DECLARE VARIABLE VC INTEGER;
- DECLARE VARIABLE VN INTEGER;
- DECLARE VARIABLE TOTAL INTEGER;
- BEGIN
- RESULT = :ADEFAULT;
- I = 1;
- TOTAL = 0;
- ANUMERAL = UPPER(:ANUMERAL);
- WHILE (I <= CHARACTER_LENGTH(:ANUMERAL)) DO
- BEGIN
- C = SUBSTRING(:ANUMERAL FROM :I FOR 1);
- IF (:C NOT IN ('I', 'V', 'X', 'L', 'C', 'D', 'M')) THEN
- BEGIN
- SUSPEND;
- EXIT;
- END
- I = I + 1;
- END
- I = CHARACTER_LENGTH(:ANUMERAL);
- WHILE (I > 0) DO
- BEGIN
- N = '';
- C = SUBSTRING(:ANUMERAL FROM CHARACTER_LENGTH(:ANUMERAL) FOR 1);
- VC = 0;
- VN = 0;
- IF (CHARACTER_LENGTH(:ANUMERAL) > 1) THEN
- N = SUBSTRING(:ANUMERAL FROM CHARACTER_LENGTH(:ANUMERAL)-1 FOR 1);
- IF (:C = 'I') THEN
- VC = 1;
- ELSE
- IF (:C = 'V') THEN
- VC = 5;
- ELSE
- IF (:C = 'X') THEN
- VC = 10;
- ELSE
- IF (:C = 'L') THEN
- VC = 50;
- ELSE
- IF (:C = 'C') THEN
- VC = 100;
- ELSE
- IF (:C = 'D') THEN
- VC = 500;
- ELSE
- IF (:C = 'M') THEN
- VC = 1000;
- IF (:N = 'I') THEN
- VN = 1;
- ELSE
- IF (:N = 'V') THEN
- VN = 5;
- ELSE
- IF (:N = 'X') THEN
- VN = 10;
- ELSE
- IF (:N = 'L') THEN
- VN = 50;
- ELSE
- IF (:N = 'C') THEN
- VN = 100;
- ELSE
- IF (:N = 'D') THEN
- VN = 500;
- ELSE
- IF (:N = 'M') THEN
- VN = 1000;
- IF (:VN < :VC) THEN
- BEGIN
- TOTAL = :TOTAL + (:VC - :VN);
- IF (:VN = 0) THEN
- BEGIN
- RESULT = :TOTAL;
- SUSPEND;
- EXIT;
- END
- ANUMERAL = SUBSTRING(:ANUMERAL FROM 1 FOR CHARACTER_LENGTH(:ANUMERAL)-2);
- I = I - 2;
- END
- ELSE
- BEGIN
- TOTAL = :TOTAL + :VC;
- ANUMERAL = SUBSTRING(:ANUMERAL FROM 1 FOR CHARACTER_LENGTH(:ANUMERAL)-1);
- I = I - 1;
- END
- END
- RESULT = :TOTAL;
- SUSPEND;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement