HI All,
I have customize table in that ten sample record is there all are string field ,I use below code to delete the record ,but is not working,Please help on this
public static void main(Args _args)
{
JMTrialTestTB JMTrialTestTB;
delete_from JMTrialTestTB
where str2Int(JMTrialTestTB.BU) >= 6 && str2Int(JMTrialTestTB.BU) <= 8 ;
}
You could use comparison operators with string fields as well:
delete_from jmTrialTestTB where jmTrialTestTB.BU >= '6' && jmTrialTestTB.BU <= '8';
But you would quickly get into troubles because 9 > 10 isn't the same as '9' > '10'.
If you want to have numbers in those fields and work with them as with number, they should be numbers. You have a wrong data type there. And if you want to allow strings there, then it's wrong to expect just numbers.
If you really can't do either, you can create a view with a computed column where you'll try to convert strings to numbers. Then you can filter by this computed column.
Did you try the code that I already shared? I don't have any other suggestions, just this one.
I Tried below code ,but no luck,could you please share your org code
delete_from JMTrialTestTB
where 0 >= 6 && 0 <= 8 ;
Hi Tony,
yes, it's possible.
Hi,
Thanks for reply, I want to delete the record between 6 to 9 record .
Its possible to use delete_from method
Your problem is that you have x function str2int in this statement.
If you would see the resulting SQL statement, you would notice that at the time when str2int is called, you don't have anything selected in JMTrialTestB buffer, hence the result is 0.
Remember that the system first has to generate the SQL statement, then send this SQL statement to the database. And this database that you send to the database will obviously not contain any x logic.
So your statement is actually:
delete_from JMTrialTestTB where 0 >= 6 && 0 <= 8;
But you could just do it like this:
delete_from JMTrialTestTB where JMTrialTestTB == '6' || JMTrialTestTB == '7' || JMTrialTestTB == '8';
If this is not feasible (you have to handle dozens of numbers), then you have to use a while select statement, and evaluate your condition one record at a time.
UPDATE: fixed typos.
Hi MCallebert.
Thanks for the reply, Could you please provide more details on this .
Hi Tony,
Try to encapsulate your query in a transaction
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156