0

sorry for the repeated question. I already asked for help about this by the use of ORACLE database. But now I really wanted to know how can I split this using MySQL database

It is possible to split field values using a specific character? Here is my sample table

value
10uF
2K
1.0uF
200UF

I want it to split by this:

 value       capacitance/resistance
 10            uF
 2             K
 1.0           uF
 200           UF

Hope you can help me once again. Thanks! and more power!

1
  • I'm guessing the second value should really be "2K". Commented Jul 9, 2015 at 1:15

1 Answer 1

1

You can use below code

create table temp
(value varchar(10)
 );

insert into temp values ('10uF');
insert into temp values('2K');

SELECT value + 0 AS num
     , REPLACE(value,value+0,'') AS unit
  FROM temp

O/P

num letter
10  uF
2   K

The trick the query is using is to evaluate the column value in a numeric context, by adding a zero. MySQL will return the numeric value.

But this wont work in case of 10Uf10,2k3..

Hope all your data is digit + charachter

Fiddle for the same

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

7 Comments

thanks for the answer it worked! :) But one thing I want to know, what if my data have a special character like "?"
@MyrtsGC "?" come after digit or in between digit?
o/p will be num=0 and letter = ?
and also what if my data have a "/" special character, between the digit? Thanks a lot!
@MyrtsGrc if any charachter come in between the digit this will not work.
|

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.