Home » SQL & PL/SQL » SQL & PL/SQL » How to print Boolean or True/False value in Sql (Oracle 12c, Windows)
How to print Boolean or True/False value in Sql [message #668653] |
Wed, 07 March 2018 21:58  |
 |
akssre
Messages: 26 Registered: March 2018
|
Junior Member |
|
|
Dear All,
Good Morning!
Just started the journey... I hope I will learn more and more with your help and assistance.
Is there any way to find out the availability of employee present in a table with Status 'Yes' or 'No' with a sql statement. Following is the workflow I tried.
SQL> create table employee (name varchar2 (20));
Table created
SQL> insert into employee values ('JOHN');
1 row inserted
SQL> insert into employee values ('SCOTT');
1 row inserted
SQL> insert into employee values ('CHARLES');
1 row inserted
SQL> select * from employee;
NAME
--------------------
JOHN
SCOTT
CHARLES
SQL> SELECT emp.NAME, estat.status
from (SELECT NAME,
(CASE
WHEN NAME IN ('JOHN', 'MICHAEL') THEN
'Yes'
ELSE
'No'
END) status
from employee) estat,
employee emp
where emp.name = estat.name
and status = 'Yes';
NAME STATUS
-------------------- ------
JOHN Yes
But I want result like following:-
NAME STATUS
-------------------- ------
JOHN Yes
Michael No
Best Regards,
AKS
[Edit MC: add code tags]
[Updated on: Wed, 07 March 2018 23:36] by Moderator Report message to a moderator
|
|
|
|
|
Re: How to print Boolean or True/False value in Sql [message #668670 is a reply to message #668660] |
Thu, 08 March 2018 09:00   |
 |
akssre
Messages: 26 Registered: March 2018
|
Junior Member |
|
|
Dear Littlefoot,
Thank you for your response.
That is exactly the problem, i do not have a source to compare. I tried before reaching out to community.
And yes with your response problem is partially resolved but it is not feasible to add and union for all the employees. It might be 10 or 100.
I am not sure how to resolve this. Though many thanks to all experts response.
Best Regards,
AKS
[Updated on: Thu, 08 March 2018 09:01] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: How to print Boolean or True/False value in Sql [message #672921 is a reply to message #672918] |
Thu, 01 November 2018 02:08   |
 |
Michel Cadot
Messages: 68758 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
SQL does not know BOOLEAN datatype.
The simplest way is to use:
SQL> declare
2 l_test boolean;
3 begin
4 l_test := true;
5 dbms_output.put_line(case when l_test then 'TRUE' else 'FALSE' end);
6 l_test := false;
7 dbms_output.put_line(case when l_test then 'TRUE' else 'FALSE' end);
8 end;
9 /
TRUE
FALSE
PL/SQL procedure successfully completed.
You can also use a function to convert your boolean:
SQL> declare
2 l_test boolean;
3 function tochar(p in boolean) return varchar2 is
4 begin
5 return case when l_test then 'TRUE' else 'FALSE' end;
6 end;
7 begin
8 l_test := true;
9 dbms_output.put_line(tochar(l_test));
10 l_test := false;
11 dbms_output.put_line(tochar(l_test));
12 end;
13 /
TRUE
FALSE
PL/SQL procedure successfully completed.
You can also use a predefined function:
SQL> begin
2 dbms_output.put_line(sys.diutil.bool_to_int(true));
3 dbms_output.put_line(sys.diutil.bool_to_int(false));
4 end;
5 /
1
0
PL/SQL procedure successfully completed.
[Updated on: Thu, 01 November 2018 02:11] Report message to a moderator
|
|
|
|
|
|
|
Goto Forum:
Current Time: Thu Jun 05 10:48:47 CDT 2025
|