从后端的字符串中获取值 [英] get value from string in backend

查看:113
本文介绍了从后端的字符串中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择``25 * 100''


Select ''25*100''


how to solve it in postgresql.

推荐答案

一种方法是根据运算符拆分数据.例如要相乘,也许像这样:
One way to do this is to split the data based on the operator. For example to multiply, perhaps something like:
SELECT 
 CAST( SUBSTRING('25*100' FROM 1 TO (POSITION('*' IN '25*100') - 1)) AS INTEGER)
 *
 CAST( SUBSTRING('25*100' FROM (POSITION('*' IN '25*100') + 1) TO 9999999) AS INTEGER)



加法:

为了弄清楚情况,使用单个字符串来完成此操作是一个坏主意.实际需要的是使用词法分析器将操作正确划分为正确的顺序.

该示例仅适用于单个乘法运算,没有其他作用.

因此,总体解决方案应该是重新考虑应用程序设计,以便以某种不同的方式处理计算.



Addition:

To clarify the situation, using a single string to do this is a bad idea. What actually would be required is to use a lexer to properly split the operations into correct order.

The example works only with a single multiply operation, nothing else.

So the overall solution should be to rethink the application design in order to handle the calculations in some different way.


这篇关于从后端的字符串中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆