1

Since I am new to mysql .

select concat ((select to_char(count(*)) from users) ,' of users')  from dual;
(or)
select concat ((select to_char(count(*)) from users) ,' of users')  ;

I am expecting "100 of users" as result set output. in oracle, the above-mentioned statement will work , but not in mysql. i am getting result value as 1.

2 Answers 2

2

You can use the following, using CONCAT (or CONCAT_WS) and a CAST to char:

-- using CONCAT
SELECT CONCAT(CAST(COUNT(*) AS CHAR), ' of users') FROM users;

-- using CONCAT_WS
SELECT CONCAT_WS(' ', CAST(COUNT(*) AS CHAR), 'of users') FROM users;

Instead of TO_CHAR you need to use CAST(... AS CHAR(5)). Since MySQL 8.0 the CONCAT can concat the result of COUNT(*) and of users without a CAST or CONVERT (explicit conversion).

demo: https://www.db-fiddle.com/f/3mVqPxrDZHURyMbX6px4L/0

Sign up to request clarification or add additional context in comments.

2 Comments

it is returning Blob
tried select concat(count(*),' of users') from users;
0

try below way it will works below is an example not directly yours

SELECT CONCAT(CAST(COUNT(*) AS CHAR(5)), ' of users') FROM Vendor;

http://sqlfiddle.com/#!9/4704eb/18

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.