Kayshav.com
About Developer Oracle 11g Technology Information Sitemap

Factorial Function
-- Function uses the 11g PL/SQL datatype SIMPLE_INTEGER 
-- for I/O.  The testing query handles null value so that 
-- function will not error out due use of SIMPLE_INTEGER.

CREATE OR REPLACE FUNCTION factorial(i_val IN 
  SIMPLE_INTEGER DEFAULT 1)  
 RETURN SIMPLE_INTEGER AS  
BEGIN  
  IF i_val > 1 THEN  
   RETURN i_val * factorial(i_val - 1);  
  ELSE  
   RETURN 1;  
END IF;  
END factorial;  
/

-- Testing Function with 11g Named Notation syntax
-- factorial(i_val=> i_num) factorial_

WITH q_t AS
 (SELECT NVL(&i_num,1) i_num FROM DUAL)
SELECT
 i_num,  factorial(i_val=> i_num) factorial_
FROM q_t;

Oracle Function Testing with 11g Named Notation syntax


Oracle 11gXEr2 - Index

Oracle registered trademark of Oracle Corporation.

Last Revised On: September 23, 2014

  24107