有一个数据表
设备编号(EID) 允许使用(yxsy) 设备检修时间(jxsj) 检修间隔时间(jg) 下次检修时间(yjsj) 是否超期(cq)
001 T 2009-12-7 12 2010-12-7 是
002 F 2008-12-1 12 2009-11-27 否
003 T 2011-1-8 6 2011-7-8 否
004 T 2011-1-7 6 2011-7-7 否
我需要对允许使用的设备进行“下次检修时间”的计算,计算原则是:在现有的“设备检修时间”上加上“检修间隔时间”(以月为单位),如果检修的时间在一个月的5号之前,就必须把算出来的时间提前到上个月的月末倒数第三天。
还需要计算“是否超期”,计算的原则是 “允许使用” 的设备,它的“下次检修时间 ”如果比当前时间要早,就设为 超期 ,否则设为 F。请问这样的函数,怎么写?
谢谢
设备编号(EID) 允许使用(yxsy) 设备检修时间(jxsj) 检修间隔时间(jg) 下次检修时间(yjsj) 是否超期(cq)
001 T 2009-12-7 12 2010-12-7 是
002 F 2008-12-1 12 2009-11-27 否
003 T 2011-1-8 6 2011-7-8 否
004 T 2011-1-7 6 2011-7-7 否
我需要对允许使用的设备进行“下次检修时间”的计算,计算原则是:在现有的“设备检修时间”上加上“检修间隔时间”(以月为单位),如果检修的时间在一个月的5号之前,就必须把算出来的时间提前到上个月的月末倒数第三天。
还需要计算“是否超期”,计算的原则是 “允许使用” 的设备,它的“下次检修时间 ”如果比当前时间要早,就设为 超期 ,否则设为 F。请问这样的函数,怎么写?
谢谢
第二个 先把下次检修时间刷正确 提交了 再处理这一步
update tablename set cq = (case
when to_date(yjsj, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'是' else '否'
end) where yxsy = 'T'
select case
when to_number(to_char(add_months(to_date(jxsj,
'yyyy-mm-dd hh24:mi:ss'),
jg),
'dd')) < 5 then
last_day(add_months(to_date(jxsj, 'yyyy-mm-dd hh24:mi:ss'), jg - 1)) - 3
else
add_months(to_date(jxsj, 'yyyy-mm-dd hh24:mi:ss'), jg)
end as newtime
from tablename
select case when to_number(to_CHAR(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI),
'dd')) < 5 then
last_day(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI - 1)) - 3
else
add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI)
end as newtime
from TAIZHANG_ZQ_VIEW
update TAIZHANG set KBZ = (case
when to_date(KZHOUQI, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'T' else 'F'
end) where KSBZT = 'T';错误信息:
行号= 1 列号= 34 错误文本= PLS-00103: 出现符号 "SELECT"在需要下列之一时: ( return compress compiled wrapped
行号= 9 列号= 3 错误文本= PLS-00103: 出现符号 "UPDATE"在需要下列之一时: . , @ ; for <an identifier> <a double-quoted delimited-identifier> group having intersect minus order partition start subpartition union where connect SAMPLE_
这些错误 我没有弄懂。麻烦大侠费心了
谢谢
行号= 1 列号= 34 错误文本= PLS-00103: 出现符号 "SELECT"在需要下列之一时: ( return compress compiled wrapped
begin
select case when to_number(to_CHAR(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'),
KZHOUQI), 'dd')) < 5 then
last_day(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI - 1)) - 3
else
add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI)
end as newtime
from TAIZHANG_ZQ_VIEW;
update TAIZHANG set KBZ = (case
when to_date(KZHOUQI, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'T' else 'F'
end) where KSBZT = 'T';
select count(ID) as chgrecnum from TAIZHANG where KSBZT='T';
return(chgrevnum);
end;这样改以后,有新的错误:
行号= 3 列号= 2 错误文本= PLS-00428: 在此 SELECT 语句中缺少 INTO 子句
行号= 10 列号= 3 错误文本= PL/SQL: SQL Statement ignored
行号= 11 列号= 16 错误文本= PL/SQL: ORA-00904: "KZHOUQI": 标识符无效
行号= 15 列号= 3 错误文本= PLS-00428: 在此 SELECT 语句中缺少 INTO 子句
begin
select case when to_number(to_CHAR(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'),
KZHOUQI), 'dd')) < 5 then
last_day(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI - 1)) - 3
else
add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI)
end as newtime
from TAIZHANG_ZQ_VIEW;
update TAIZHANG set KBZ = (case
when to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'T' else 'F'
end) where KSBZT = 'T';
select count(ID) as chgrecnum from TAIZHANG where KSBZT='T';
return(chgrevnum);
end;
有些东西 我没有注意,新的错误:
行号= 3 列号= 2 错误文本= PLS-00428: 在此 SELECT 语句中缺少 INTO 子句
行号= 16 列号= 3 错误文本= PLS-00428: 在此 SELECT 语句中缺少 INTO 子句
先定义一个变量,例如 time varchar:=""; 再select sysdate into time from dual 否则会报错
标识符无效那个问题 你看看那个表里有那个字段吗?
IS chgrevnum NUMBER(6);
newtime varchar:="";
begin
select case when to_number(to_CHAR(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'),
KZHOUQI), 'dd')) < 5 then
last_day(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI - 1)) - 3
else
add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI)
end into newtime
from TAIZHANG_ZQ_VIEW;
update TAIZHANG set KBZ = (case
when to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'T' else 'F'
end) where KSBZT = 'T';
select count(ID) into chgrecnum from TAIZHANG where KSBZT='T';
return(chgrevnum);
end;越来越糊涂,再次麻烦大侠行号= 0 列号= 0 错误文本= ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01400: 无法将 NULL 插入 ("SYS"."OBJ$"."NAME")
行号= 2 列号= 10 错误文本= PLS-00215: 字符串长度限制在范围 (1...32767)
newtime varchar:="";
begin
select case when to_number(to_CHAR(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'),
KZHOUQI), 'dd')) < 5 then
last_day(add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI - 1)) - 3
else
add_months(to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss'), KZHOUQI)
end into newtime
from TAIZHANG_ZQ_VIEW;
update TAIZHANG set KBZ = (case
when to_date(KJZRQ, 'yyyy-mm-dd hh24:mi:ss') > sysdate then
'T' else 'F'
end) where KSBZT = 'T';
end;改成过程,还是这个错误:行号= 0 列号= 0 错误文本= ORA-00604: 递归 SQL 级别 1 出现错误 ORA-01400: 无法将 NULL 插入 ("SYS"."OBJ$"."NAME")
行号= 2 列号= 10 错误文本= PLS-00215: 字符串长度限制在范围 (1...32767)