Dynamic String Parsing

Question
Let’s say I have given data as string:

+———-+

|Size |

+———-+

|15X10 |

|5X4 |

|3 |

|2X6X5 |

+———-+

I want to write this column as integer like this:

+———-+

|Size |

+———-+

|150 |

|20 |

|3 |

|60 |

+———-+

Some of them are multiply of three numbers, some of them just one number. I can split the string but cannot make MySQL to calculate the number. Thank you.

 

Answer

It’s hard to implement random four arithmetic operations with multilevel brackets and multiple operands in SQL automatically. But SPL, with powerful structured data computing ability, can handle them dynamically. Here’s the SPL script:

 

A

1

$select * from tb

2

=A1.run(Size=eval(replace(Size,"X","*")))

A1: Query data from table tb;

undefined
A2: Replace character X with the multiplication sign * to dynamically parse the strings into expressions for further calculation.

undefined