0
votes

I have a table with wingNo and FlatNo.

WingNo          FlatNo
A                001
A                002
B                1
A                101

etc

I need to order by WingNo & FlatNo in Asc order. Where WingNo & FlatNo both are String. The result should be:-

WingNo         FlatNo
A               001
A               002
A               101
B               1


criteria.addOrder(Order.asc("wingNo"));
criteria.addOrder(Order.asc("flatNo"));

How can I use the order by with String filed treated as numbers?

1

1 Answers

0
votes

If the FlatNo field be a fixed-width text or varchar field in your database table, then your current ordering logic should already be giving you the behavior you want. This is because zero-padded fixed width number strings sort lexicographically identically to the underlying numbers.

If the FlatNo column does not have fixed width and/or could be missing left zero padding, then you would have to do more work. If you had this long term need, it might just be easier to make FlatNo a numeric column.