Sqlserver2005迁移至Oracle系列之四:在Oracle中创建位或运算函数-bitor
CREATE OR REPLACE FUNCTION bitor
(
n1 INT,
n2 INT
) RETURN INTEGER IS
RESULT INTEGER;
i INT := 0;
g1 INT := 0;
x INT := 0;
n11 INT;
n12 INT;
n21 INT;
n22 INT;
BEGIN
n11 := n1;
n21 := n2;
g1 := greatest(n11, n21);
WHILE g1 / 2 > 0 LOOP
n12 := MOD(n11, 2);
n11 := trunc(n11 / 2);
n22 := MOD(n21, 2);
n21 := trunc(n21 / 2);
x := x + power(2, i) * greatest(n12, n22);
g1 := greatest(n11, n21);
i := i + 1;
IF g1 = 1 THEN
n12 := MOD(n11, 2);
n22 := MOD(n21, 2);
x := x + power(2, i) * greatest(n12, n22);
EXIT;
END IF;
END LOOP;
RETURN(x);
EXCEPTION
WHEN OTHERS THEN
RETURN(0);
END bitor;
/