Substr In Talend

One Star

Substr In Talend

Dears,
I have a table in oracle . I want to extract first 12 characters from each record present in the table. For this I have written a job, but here I am getting a java exception(java.lang.StringIndexOutOfBoundsException: String index out of range: 12). This exception is because my third record is less than 12 characters and so my third record is not inserted into my database. Can anyone please tell me how to handle this scenario. Even I have tried with TOS 3.0. Is it a bug with Talend?. Can anyone please share your valuable ideas.
Error:
Starting job Talend_Substr at 14:27 09/12/2008.
connecting to socket on port 3453
connected
connecting to socket on port 5049
connected
Exception in component tMap_1
java.lang.StringIndexOutOfBoundsException: String index out of range: 12
at java.lang.String.substring(String.java:1765)
at routines.StringHandling.LEFT(StringHandling.java:184)
at test.talend_substr_0_1.Talend_Substr.tOracleInput_1Process(Talend_Substr.java:585)
at test.talend_substr_0_1.Talend_Substr.runJobInTOS(Talend_Substr.java:883)
at test.talend_substr_0_1.Talend_Substr.main(Talend_Substr.java:785)
disconnected
disconnected
Job Talend_Substr ended at 14:27 09/12/2008.

Input Data:
SQL> select name, length(name) from talend_substr;
NAME LENGTH(NAME)
------------------------------ ------------
Rama chandran 13
Sankaran Arumugam 17
G Anand 7

Output Data:
SQL> select name, length(name) from talend_substr_dup;
NAME LENGTH(NAME)
------------------------------ ------------
Rama chandra 12
Sankaran Aru 12

if I change my data, I am not getting any error. Here I have added more characters to my third record.
Input Data:
SQL> select name, length(name) from talend_substr;
NAME LENGTH(NAME)
------------------------------ ------------
Rama chandran 13
Sankaran Arumugam 17
G Anand Srinivisan 18
Output Data:
SQL> select name, length(name) from talend_substr_dup;
NAME LENGTH(NAME)
------------------------------ ------------
Rama chandra 12
Sankaran Aru 12
G Anand Srin 12
Regards,
Ram
Employee

Re: Substr In Talend

For me there is a problem with LEFT function.
It should not throw such an exception.
You can open a bug on our
As a wrokaround, you can use the LEN function :
(LEN(myrow.myString)>=12)?LEFT(myrow.myString):myrow.myString
HTH,
One Star

Re: Substr In Talend

Thanx a ton Smiley Happy for your excellent solution. This code is for java version.

(StringHandling.LEN(row1.name)>12)?StringHandling.LEFT(row1.name,12)Smiley FrustratedtringHandling.LEFT(row1.name,StringHandling.LEN(row1.name))
Regards,
Ram