eatSleepCode
eatSleepCode

Reputation: 4637

Passing value to the function in sql query

Consider the following situation:

SELECT TestPkg.getData(123) FROM dual;

returns correct result, but

SELECT TestPkg.getData(SELECT TO_NUMBER('123') FROM dual) FROM dual;

gives error as missing expression, why is that so? How to tackle with such situation where we are passing value to function which is dependent on value from query.

Upvotes: 1

Views: 770

Answers (2)

Thorsten Kettner
Thorsten Kettner

Reputation: 94859

To evaluate a select result you need brackets:

SELECT TestPkg.getData( (SELECT TO_NUMBER('123') FROM dual) ) FROM dual;

One pair for the function call, one for the evaluation of the select result.

Upvotes: 5

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

I think you need:

SELECT TestPkg.getData(TO_NUMBER('123')) FROM dual;

Upvotes: 1

Related Questions