Sometimes it is needed to order type fields VARCHAR as INT. If you order a VARCHAR type field, the result can look like this:
123456789101
10
2a
2b
2c
3a
3b
340
4
5
but, really, what you wanted is something like this:
123456789101
2a
2b
2c
3a
3b
4
5
10
340
Follow this example:
123ORDER BY
(core_gmoulds_obras_ctrl_dim_pecas.referencia+0) ASC,
core_gmoulds_obras_ctrl_dim_pecas.referencia ASC
Did it work for you? Please let me know in the comments below.