I want to write a PL/SQL function that takes as a parameter 2 arguments. First parameter is an integer and second parameter is an Oracle sequence object.
This function returns a decimal value which is param1.param2 where param2 must be the next value of the sequence object taken as parameter.
Example: function myFc(15,objSq). Suppose objSq.nextVal is 33 then the returned decimal value must be 15.33
This seems a little strange. You should always know what sequence you’re going to be using and please be aware that a sequence will never generate a gap-free sequence of numbers, a perfect 1, 2 ..n.
As you don’t know an object name you have to use execute immediate, which enables you to use it. You should probably also use
dbms_assertto protect against SQL Injection.The answer to your question would look something like this:
However, I don’t understand why you would want to do this. You obviously know the name of the sequence that you are attempting to use. Instead of using a function you could simply use this information in your calling code:
Lastly, as David says in his comment this is a very strange requirement. Are you absolutely certain that this is what you want to be doing? Maybe by explaining why you’re doing this someone may be able to come up with a better suggestion.