0

Hi I am facing an issue while converting string value to integer. Actually I am reading data from the table and there are fields like 39% and they are string data type. Now i want to convert them into INteger datatype and load them in to another table.

I tried using select values in PDI but it is giving me error like. "Could't convert String to Integer."

Please help me in resolving this issue.

1 Answers1

0

The percentage sign isn't part of the integer type in Java, so first you need to remove that character in order to make the type casting.

  1. Add a new "Replace in string" step between the data origin and "Select values"
  2. Double click on the new added step and on the "In stream field" select the field that needs to be cleaned
  3. On "Search", type "%" (without the parentheses) and click Ok to close the dialog.

That should do the trick.

t3b4n
  • 603
  • 9
  • 23
  • I did the same as you explained. Still i am getting the error that couldn't convert string to integer. –  Dec 27 '17 at 17:04
  • I tested it using PDI 6, and worked fine. Maybe your string has something else, like a space, that's messing around. Paste your exception here and maybe I can help you ;) – t3b4n Dec 27 '17 at 19:19
  • Suc String(100) : couldn't convert String to number : non-numeric character found at position 1 for value [%3%9%%%] –  Dec 27 '17 at 20:49
  • concat(ROUND((Suc_Tot/Total)*100),'%')--- I am using this statement to get the valu with special character. And i want to write the data to another table by changing the data type string for this percent value to Integer. –  Dec 27 '17 at 20:51
  • Why are you concatenating the "%" symbol to the number and then removing it? – t3b4n Dec 27 '17 at 20:58
  • I had a different tables in database and I am doing this calculation to get the percentage of data from two different fields. after this I have to write this data to the target table. In the table input I wrote the query to get the percentage value but it is getting string data type by default. I want it to be the integer data type. –  Dec 27 '17 at 21:42
  • The "concat" function is adding that symbol to the output, so in order to get rid of it, it's as simple as not using that function in your query. Go from this: concat(ROUND((Suc_Tot/Total)*100),'%') to this: ROUND((Suc_Tot/Total)*100). That's all. – t3b4n Dec 27 '17 at 23:49