2

I'm querying the DB and need to parse one of the fields for specific values (using string functions). So I figured it'd be best to write a function for it. I've never written a function before in plsql, so I decided to look at some examples.

I got a copy of a simple "square" function which takes a number and returns the square of it, but am not sure how to call it from the SQL statement.

I only have read access. Will I be able to write functions and use them to retrieve the data I need? And if so, how?

1 Answer 1

3

To be able to create a function your user needs the CREATE PROCEDURE privilege granted to it by the DBA:

grant create procedure to myschema;

If you have the privilege then you can create a function like this

create function square(n in number) return number
is
  return n*n;
end;

And you can call it from SQL like this:

select num, square(num)
from mytable;

Note: in Oracle it is usually preferred to create functions in packages, in which case the calling SQL would be like:

select num, mypackage.square(num)
from mytable;
Sign up to request clarification or add additional context in comments.

1 Comment

Hmm so I will need more privileges for that. Guess I will have to make do with what I have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.