gyurisc
gyurisc

Reputation: 11492

ORACLE SQL function that can be used in the where part of a select statement

I would like to create a function that can be used in the where part of a select statement. Like this:

select 'x' from table where addNumber(4,3)=7; 

I know how to do this in MS SQL, but I would like to do this Oracle SQL. How can I do this?

Upvotes: 0

Views: 166

Answers (1)

cagcowboy
cagcowboy

Reputation: 30848

You need to write a PL/SQL function...

CREATE OR REPLACE FUNCTION addNumber(firstParam  IN NUMBER,
                                     secondParam IN NUMBER)
RETURN NUMBER
IS 
BEGIN
   RETURN firstParam + secondParam;
END;
/

...run this into the scheam you're using (probably using SQL*Plus) and then call it as you did in your SQL statement above.

Upvotes: 1

Related Questions