yuzhenquan
2014-07-03 12:00:00
数据库动态添加大字段设计key:value
针对灵活的业务配置需求,固定的字段无法满足多变的业务类型变化。因此需要通过大字段数据库设计,通过键值方式处理。
字段存储格式:{B01:100,B02:2.45}
=================读取字段键值对应数据方法:f_getvalue=============================
create or replace function f_getvalue(fld IN VARCHAR2,ipath IN VARCHAR2) RETURN VARCHAR2 is res VARCHAR2(200); findChar varchar2(50); findIndex integer; begin if fld is null then res := ''; else if instr(fld,ipath) = 0 then res := ''; else findChar := ','; findIndex := instr(fld, ',',instr(fld, ipath || ':')); if findIndex = 0 then findChar := '}'; end if; res := substr(fld,instr(fld, ipath || ':') + length(ipath || ':'),instr(fld,findChar,instr(fld, ipath || ':')) - (instr(fld, ipath || ':') + length(ipath || ':'))); end if; end if; return(res); end f_getvalue;
==============存储数据方法:f_setvalue===========================
create or replace function f_setvalue(fld IN VARCHAR2,ipath IN VARCHAR2,value in varchar2) RETURN VARCHAR2 is res VARCHAR2(4000); val number(20,8); begin val := to_number(value); if fld is null then if val=0 then res :=''; else res := '{' || ipath || ':' || value || '}'; end if ; else if instr(fld,ipath) <> 0 then if instr(fld, ',',instr(fld, ipath || ':')) <> 0 then if val=0 then res := substr(fld,0,instr(fld,ipath) -1 ) || substr(fld, instr(fld,',',instr(fld, ipath|| ':') ) + 1 ); else res := substr(fld,0,instr(fld,ipath) + length(ipath)) || value || substr(fld, instr(fld,',',instr(fld, ipath|| ':')) ); end if; else if val=0 then res :=substr(fld,0,instr(fld,ipath) - 2 ); if length(res) > 2 then res:= res || '}'; end if; else res := substr(fld,0,instr(fld,ipath) + length(ipath))|| value || '}'; end if ; end if; else if val =0 then res := fld; else res := substr(fld,0,length(fld) - 1) || ',' || ipath || ':' || value || '}'; end if ; end if; end if; return(res);
猜你喜欢
- mysql数据库动态添加字段设计
- 仿京东数据库表单的sql设计
- sql server版全国省市区地址
- springboot2 aop注解配置多个数据库并实现多数据源动态切换和数据库读写分离
- 全国省市区三级级联带区号和邮编完整sql数据库记录
- 全国行政区划编码,省、市、县、乡镇、村/街道sql数据库记录
- Mybatis之痒:Mybatis实体Bean的属性property转成数据库column
- java Swing导入SQL脚本建立初始化数据库表,支持Mysql、Oracle、SqlServer数据库
- java如何验证数据库中是否有表和表中是否有列
- java jdbc操作数据库的工具类
- java jndi连接数据库
- java H2数据库使用并实现增删改查功能
请下载代码后再发表评论



3334004690 LV11
1月15日
JIJI994 LV1
2024年5月21日
Joe___ LV1
2023年11月15日
liupengfei LV7
2022年9月13日
杨知青
2021年4月8日
暂无贡献等级
423256321 LV4
2021年1月7日
watercolor LV5
2020年10月10日
tsd97677 LV8
2020年10月9日
xiongfan LV6
2020年9月28日
304299224
2020年9月10日
暂无贡献等级