question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Execute function returning boolean with input parameters in PLSQL

See original GitHub issue

How can I run a function returning a boolean in PLSQL using linq2db?

Steps to reproduce

return _db.DataConnection.SelectAsync(() => MyPkg.MyFunction(myParameter));

Expected result: return a true or false based on result of the function execution

this is failing with invalid datatype, not sure how to achieve this, ExecuteProc<T> doesn’t work to run functions.

Thanks

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Aug 29, 2022

Ok, there is nothing we can do here as this error is returned by Oracle.

I’ve managed to call function using this definition (taken from here) but it is not very exciting…:

Option 1: use Execute

db.Execute(@"WITH
FUNCTION convert_bool(i IN VARCHAR2) RETURN NUMBER AS
BEGIN
	RETURN CASE ISSUE3742(i) WHEN TRUE THEN 1 WHEN FALSE THEN 0 END;
END convert_bool;
SELECT convert_bool(:p) FROM SYS.DUAL", new { p = "test" });

Option 2: use Sql.Expression and query prefix

// ** marker instructs linq2db to add "hint" before query
db.NextQueryHints.Add(@"**WITH
FUNCTION convert_bool(i IN VARCHAR2) RETURN NUMBER AS
BEGIN
	RETURN CASE ISSUE3742(i) WHEN TRUE THEN 1 WHEN FALSE THEN 0 END;
END convert_bool;");

db.Select(() => Issue3742Function("test"));

[Sql.Expression("convert_bool({0})", ServerSideOnly = true)]
public static bool Issue3742Function(string parameter) => ThrowHelper.ThrowInvalidOperationException<bool>();

Option 3: you can always add wrapper function in Oracle to call plsql function and convert result to number

1reaction
MaceWinducommented, Aug 29, 2022

Sometimes I wonder what’s wrong with Oracle? 🤦‍♂️

Why introduce boolean and then make it unavailable to SQL?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Return boolean inside a create procedure pl sql
So i need to input the employee's name(parameter), and check if that his salary is lower than the average salary of his' department,...
Read more >
Calling an Oracle Function with PL/SQL BOOLEAN Type ...
With the next version, we can call a function like this one: FUNCTION f_bool (i BOOLEAN) RETURN BOOLEAN;
Read more >
Calling a function that returns a boolean in PL/SQL - Oracle
I'm hoping to get some help with the syntax for calling a function (provided by 3rd party software) that returns a boolean value....
Read more >
SQL & PL/SQL » Function with Boolean as IN Parameter
Hi, I have the function as below: 1 create or replace function f1(a number) 2 return varchar2 3 as 4 begin 5 IF...
Read more >
8 Using PL/SQL Subprograms
The function spec begins with the keyword FUNCTION and ends with the RETURN clause, which specifies the datatype of the return value. Parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found