日期:2014-05-17  浏览次数:20750 次

请教一个问题---关于oracle中的nvl函数
本意是针对不同语言获取表中最大的模板号,如果为空的话执行用默认值

函数主要部分如下
for i in 1 .. icount loop
    j := i - 1;
    sqlcmd := 'select msglang from (select msglang, rownum rn from (select distinct(msglang) from mdsp_t_msgtemplate)) where rn = '||i;
    execute immediate sqlcmd into lang;
    dbms_output.put_line('smpa_sis_templ_lang.'||j||'='||lang);
    defTmpid := get_default_tmpleid(lang, 'mtn');
    sqlcmd := 'select nvl(max(t.templateid), '||defTmpid||') from smpa_t_template t where t.lang = '''||lang||'''';
    execute immediate sqlcmd into tmpid;
    dbms_output.put_line('smpa_sis_templ_templateid.'||j||'='||tmpid);
    rlid := rlid + 100;
end loop;


获取到的值如下
smpa_sis_templ_size=7
smpa_sis_templ_lang.0=fa
smpa_sis_templ_templateid.0=810500
smpa_sis_templ_lang.1=fr
smpa_sis_templ_templateid.1=5000066
smpa_sis_templ_lang.2=zh
smpa_sis_templ_templateid.2=710500
smpa_sis_templ_lang.3=ar
smpa_sis_templ_templateid.3=110002
smpa_sis_templ_lang.4=pt
smpa_sis_templ_templateid.4=310002
smpa_sis_templ_lang.5=en
smpa_sis_templ_templateid.5=5000095
smpa_sis_templ_lang.6=el
smpa_sis_templ_templateid.6=910500

问题是粗体的两个值不对 
单独获取的时候
fr 是310097
en 是310110
请问这个函数中有什么问题会导致这个值获取的不对?
oracle??nvl函数

------解决方案--------------------
nvl()中间要是有空值的话就会出错
------解决方案--------------------
取不到最大值就用defTmpid表示。有什么问题呢?
------解决方案--------------------
nvl(col,1) 
if col is NULL then nvl(col,1)=1