create or replace function get_projectcode(p_id number) return varchar2
as
--流程控制用来生成调单的流水号,形如20060112-0001
p_str varchar2(2000);
p_out varchar2(2000);
begin
select to_char(A_STARTDATE,'yyyy')||to_char(A_STARTDATE,'Q') into p_str from project where projectid = p_id;
begin
select to_char(max(to_number(projectcode)+1)) into p_out from project where instr(projectcode,p_str) = 1;
exception
when OTHERS then
p_out := null;
end;
if p_out is null then
p_out := p_str ||'0001';
end if;
return p_out;
exception
when OTHERS then
return null;
end get_projectcode;
大家看上面的程序,我的本意是想"生成调单的流水号,形如20060112-0001"
可结果老是生成了形如20060112 的,我现在想形成20060112-0001; 后面的####的转换方式我想这样:我在库里面有个季节 workday 这个字段,当先中第一季度时候形成形如20060112-0001,第二季度时候形成形如20060112-0002 依次类推.我不讳写这程序.求大家帮我该下上面的程序 !!! 求你们了 ,我真的急用.
as
--流程控制用来生成调单的流水号,形如20060112-0001
p_str varchar2(2000);
p_out varchar2(2000);
begin
select to_char(A_STARTDATE,'yyyy')||to_char(A_STARTDATE,'Q') into p_str from project where projectid = p_id;
begin
select to_char(max(to_number(projectcode)+1)) into p_out from project where instr(projectcode,p_str) = 1;
exception
when OTHERS then
p_out := null;
end;
if p_out is null then
p_out := p_str ||'0001';
end if;
return p_out;
exception
when OTHERS then
return null;
end get_projectcode;
大家看上面的程序,我的本意是想"生成调单的流水号,形如20060112-0001"
可结果老是生成了形如20060112 的,我现在想形成20060112-0001; 后面的####的转换方式我想这样:我在库里面有个季节 workday 这个字段,当先中第一季度时候形成形如20060112-0001,第二季度时候形成形如20060112-0002 依次类推.我不讳写这程序.求大家帮我该下上面的程序 !!! 求你们了 ,我真的急用.
解决方案 »
- ORA-01009: 必需的参数缺失什么情况
- oracle数据库服务器加入域后,客户端连不上???
- 控制文件的2个问题
- 存儲過程問題
- 需oracle 920X(x>5) for windows下载
- 做查询时,如果字段a为空则显示“空值” 如果不为空则显示“有值”,请问要怎么写?谢谢!!!
- ORACLE9I导出数据时当导出数据文件到4G就停止导出了,请问是何原因?
- ========[求助]日期, 时间 问题======
- 怎么把这个带BETWEEN 的日期查询条件转换成数字比较
- oracle视图update出错,急急急!!!
- !!求一条简短的SQL语句 在线等!!! 解决了马上给分
- Oracle 10g 在Linux上配置pc环境遇到的问题(PL/SQL执行)
begin
select to_char(max(to_number(projectcode)+1)) into p_out from project where instr(projectcode,p_str) = 1;
exception
when OTHERS then
p_out := null;
--你看看程序有没有执行到这里来 ...
end;Case 2:
把 p_out := p_str ||'0001'; 改成:
p_out := p_str ||'000'||substr(p_q,-1);如果你取得是程序运行的时间 (sysdate) 的话:
select to_char(sysdate,'Q') into p_q from dual;
然后把 p_out := p_str ||'0001'; 改成:
p_out := p_str ||'000'||substr(p_q,-1);
as
--流程控制用来生成调单的流水号,形如20060112-0001
p_str varchar2(2000);
cnt number;
v_temp varchar2(10);
p_out varchar2(2000);
begin
select decode(workday,'季节1','1','季节2','2','季节3','3','4')
into v_temp from table1;
select to_char(A_STARTDATE,'yyyy')||to_char(A_STARTDATE,'Q') into p_str from project where projectid = p_id;
select count(*) into cnt
from project where instr(projectcode,p_str) = 1;
if (cnt<=0) then
p_out := p_str ||to_char(v_temp,'fm0000');
else
select to_char(max(to_number(projectcode)+1)) into p_out from project where instr(projectcode,p_str) = 1;
end if; return p_out;
exception
when OTHERS then
return null;
end get_projectcode;