how to use the LPAD function with COUNT?

Asked

Viewed 55 times

0

For example only:

I am trying to select where a zero will be added to the left if the number is less than 10.

Examples:

SELECT COUNT(1);

Returns => 1

SELECT LPAD(1, 2, 0);

Returns => 01

SELECT LPAD(COUNT(1), 2, 0);

Returns => BLOB

How do I use the function LPAD with COUNT, or one that does something similar?

  • I tested your code on my server and it worked, which version of yours MySQL?

  • Strange, for me it always returns "blob". The mysql version here is: 5.6.39-cll-Lve

  • I tested on another server and returned correctly too, only for information the version of this server is 5.6.39-83.1.

1 answer

0

After searching a little, discover that this may be a bug generated by Drive. Thus, the problem that was occurring to me, will not necessarily happen on other computers.

To fix this, and have the expected value in my select, just make a casting of this blob.

SELECT CAST(LPAD(COUNT(1), 2, 0) AS CHAR(2));

Returns => 01

Browser other questions tagged

You are not signed in. Login or sign up in order to post.