Yes, you can do all that in one function:

1) gets a value from a sequence; 2) inserts a entry in a table using the value obtained in 1); 3) RETURNS that value.

I was simply making assumptions about what your particular problem might have been. As I said, if my assumptions were wrong, and I'm guessing they were, then I need more info.

The function looks fine to me:

If you simply have:

...
val := addNode (...)
...

you should not have a problem. Again, are you calling this function inside a SELECT statement, because that is not allowed.

If this is not the case, then I am at a loss. In order for us to help, you will then need to *really* elaborate on what is happening. How are you calling the function, precisely? What line do you get the error on? What happens if you remove all the code except the SELECT and INSERT? Any and every piece of information that might possibly shed some light would be appreciated.

However, just as a point on style. Functions should only be used when the entire purpose is to calculate a value. If you are simply returning values as a matter of convenience, and not the primary focus of the code, then a procedure should be used. Since the main purpose of this proc is to insert some records, then it really should be a proc and not a function, IMHO.

- Chris