SQL中缀算术转后缀算术表达式并计算的函数

上传人:206****923 文档编号:37506028 上传时间:2018-04-17 格式:DOCX 页数:3 大小:18.36KB
返回 下载 相关 举报
SQL中缀算术转后缀算术表达式并计算的函数_第1页
第1页 / 共3页
SQL中缀算术转后缀算术表达式并计算的函数_第2页
第2页 / 共3页
SQL中缀算术转后缀算术表达式并计算的函数_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《SQL中缀算术转后缀算术表达式并计算的函数》由会员分享,可在线阅读,更多相关《SQL中缀算术转后缀算术表达式并计算的函数(3页珍藏版)》请在金锄头文库上搜索。

1、-创建函数(原创:cson_cson)create function dbo.js(bds varchar(1000)returns floatasbegindeclare i int,j intdeclare c1 char(1),c2 char(1),c varchar(100)declare v1 float,v2 float,v floatdeclare t table(id int identity(1,1),s varchar(100)declare s table(id int identity(1,1),s varchar(100)declare sv table(id int

2、 identity(1,1),v float)select i = 0,j = len(bds),c2 = ,c = while i 0 or (c2 = - and c1 in(,*,-,+,/,()begin select c = c + c2 continue endif c 0begininsert t(s) select s from s where id isnull(select max(id) from s where s in(),0) order by id descdelete s where id = isnull(select max(id) from s where

3、 s in(),0)continueendif charindex(c2,+-)0begininsert t(s) select s from s where id isnull(select max(id) from s where s in(),0) order by id descdelete s where id isnull(select max(id) from s where s in(),0)if c2 0begininsert t(s) select s from s where id isnull(select max(id) from s where s in(,+,-)

4、,0) order by id descdelete s where id isnull(select max(id) from s where s in(,+,-),0)insert s select c2continueendif charindex(c2,()0 insert s select c2endif c insert t(s) select cinsert t(s) select s from s order by id descselect i = 0,j = max(id) from twhile i jbeginselect i = i + 1select c = s f

5、rom t where id = iif c = ( continueif c not in(*,-,+,/) begin insert sv(v) select convert(float,c) continue endselect v2 = v from sv delete sv where id = (select max(id) fromsv)select v1 = v from sv delete sv where id = (select max(id) fromsv)select v = case c when + then v1 + v2 when - then v1 - v2when * then v1 * v2 when / then v1 / v2 endinsert sv(v) select vendselect v = v from svreturn vend-测试示例declare bds varchar(100)select bds = 1+(2+3)*4-9select dbo.js(bds) as func-运行结果/*func-12*/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号