SQL中的单位转换表 [英] unit conversion table in SQL

查看:233
本文介绍了SQL中的单位转换表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库中实现质量,体积,温度等单位的单位转换功能。我的背景是软件开发,因此我自然倾向于为此任务创建一堆用户定义的功能。但是我暗中怀疑有一种更 SQLish的方式可以做到这一点。

I want to implement unit-conversion functionality in a database for units of mass, volume, temperature, etc. My background is in software development, so I naturally lean towards creating a bunch of User-Defined Functions for this task. But I have sneaking suspicion there is a more "SQLish" way of accomplishing this.

基于表的方法,例如此处此处非常好,但我认为没有简单的方法可以将此方法扩展到与单个乘数无关的单位,例如温度(F-to-C,C-to-F)或原子质量(kgmol-kg) 。我已经看到了多步骤的方法(例如在此处中描述的方法),但是这些方法看起来太复杂了,以至于无法做到有用。

The table-based method, such as the one described here or here would be excellent, but I see no simple way of extending this approach for units which are not related by a single multiplier, such as temperature (F-to-C, C-to-F) or atomic mass (kgmol-to-kg). I have seen multi-step approaches (such as the one described here), but these seem far too convoluted to be useful.

我在这里遗漏了一些明显的东西吗,或者函数真的是唯一的方法吗?

Am I missing something obvious here, or are functions really the only way to go?

推荐答案

最后,我决定坚持使用UDF。做出此决定的主要动机是,鉴于这项任务的频率不高,基于表格的方法的复杂性似乎没有道理。另外,几个函数(例如 ConvertMass())依赖于子查询(例如,确定给定组件的原子量)。因此,UDF似乎是最明智的选择。

In the end, I decided to stick with UDFs. The primary motivation for that decision was that the complexity of the table-based approach didn't seem to be justified, given the infrequency of this task. Also, several of the functions (e.g. ConvertMass()) are dependent on subqueries (to determine the atomic weight of a given component, for example). So UDFs seemed like the most prudent way to go.

这篇关于SQL中的单位转换表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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