oracle用户自定义函数问题,望求助!!

Josir 2009-03-12 02:39:13
各位好,因本人对oracle是初学者在其方面上欠缺还很多,所以望给予指教:
下面是在oracle中增加自定义函数 fn_getdays 但是在if... then ... else if ... ...方面出现了问题,经努力还是没找到原因。
望在行的人帮忙看下,指点一下,感激不尽,下面是我修改过的,但是有问题给予改正。该函数是为求本月的实际天数,p1参数是传入的日期比如:“20040101”
------------------------------
create or replace function fn_getdays(p1 varchar2) return integer
is
v_year varchar(4);
v_month varchar2(2);
v_return int;
--Result integer;
begin
v_year := substring(p1,1,4);
v_month := substring(p1,5,2);

if v_month in ('01','03','05','07','08','10','12') then --如果是31天的月份
v_return := 31
else if v_month in ('04','06','09','11') then --如果是30天的月份
v_return := 30
end if;
else if v_month in ('02') then --如果是2月份
begin
if cast(v_year as int) / 4 = 0 then --如果整除4,则是闰年
v_return := 29
else
v_return := 28
end if;
end if;
end;
end if;
end if;
return(v_return);
end fn_getdays;
...全文
204 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cmknba 2011-12-16
  • 打赏
  • 举报
回复
create or replace function fn_getdays(p1 varchar2) return integer
is
v_year int;
v_month varchar2(2);
v_return int; --Result integer;
begin
v_year := cast(substr(p1,1,4)as int);
v_month := substr(p1,5,2);

if v_month in ('01','03','05','07','08','10','12') then --如果是31天的月份
v_return := 31;
elsif v_month in ('04','06','09','11') then --如果是30天的月份
v_return := 30;
elsif v_month in ('02') then --如果是2月份
begin

if mod(v_year,4) = 0 and mod(v_year,100)!=0 or mod(v_year,400) = 0 then
--①、普通年:能被4整除且不能被100整除的为闰年。(如2004年就是闰年,1901年不是闰年)
--②、世纪年:能被400整除的是闰年。(如2000年是闰年,1900年不是闰年)
--and 的优先级高于or
v_return := 29;
else
v_return := 28;
end if;
end;
end if;
return(v_return);
end fn_getdays;
白发程序猿 2009-03-12
  • 打赏
  • 举报
回复
对,是没加;
Josir 2009-03-12
  • 打赏
  • 举报
回复
是没有加 ;结尾的原因吧?
Josir 2009-03-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ling242a 的回复:]
只有两个if,却有5个end if
这么明显的错误,楼主居然都发现不了

SQL code
create or replace function fn_getdays(p1 varchar2) return integer
is
v_year varchar(4);
v_month varchar2(2);
v_return int; --Result integer;
begin
v_year := substring(p1,1,4);
v_month := substring(p1,5,2);

if v_month in ('01','03','05','07','08','10','12') then --如果是31天的…
[/Quote]

不好意思啊,这个是个失误,我在改这个if问题时,找原因多加了还没给删除,所以...
刚才试了下还是不行的,跟之前我遇到的一样,在几个 else if ... else if ... else... 遇到如下的报错,请问这个是因为什么呢??:
FUNCTION NCHR.FN_GETDAYS 编译错误

错误:PLS-00103: 出现符号 "ELSE"在需要下列之一时:
* & = - + ; < / > at in is
mod remainder not rem <an exponent (**)> <> or != or ~= >= <=
<> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset
member SUBMULTISET_
符号 ";" 被替换为 "ELSE" 后继续。
行:12
文本:else if v_month in ('04','06','09','11') then --如果是30天的月份

错误:PLS-00103: 出现符号 "ELSE"在需要下列之一时:
* & = - + ; < / > at in is
mod remainder not rem <an exponent (**)> <> or != or ~= >= <=
<> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset
member SUBMULTISET_
符号 ";" 被替换为 "ELSE" 后继续。
行:14
文本:else if v_month in ('02') then --如果是2月份

错误:PLS-00103: 出现符号 "ELSE"在需要下列之一时:
* & = - + ; < / > at in is
mod remainder not rem <an exponent (**)> <> or != or ~= >= <=
<> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset
member SUBMULTISET_
符号 ";" 被替换为 "ELSE" 后继续。
行:18
文本:else

错误:PLS-00103: 出现符号 "END"在需要下列之一时:
* & = - + ; < / > at in is
mod remainder not rem <an exponent (**)> <> or != or ~= >= <=
<> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset
member SUBMULTISET_
符号 ";" 被替换为 "END" 后继续。
行:20
文本:end if;

错误:PLS-00103: 出现符号 "FN_GETDAYS"在需要下列之一时:
if
行:24
文本:end fn_getdays;
白发程序猿 2009-03-12
  • 打赏
  • 举报
回复
只有两个if,却有5个end if
这么明显的错误,楼主居然都发现不了

create or replace function fn_getdays(p1 varchar2) return integer
is
v_year varchar(4);
v_month varchar2(2);
v_return int; --Result integer;
begin
v_year := substring(p1,1,4);
v_month := substring(p1,5,2);

if v_month in ('01','03','05','07','08','10','12') then --如果是31天的月份
v_return := 31
else if v_month in ('04','06','09','11') then --如果是30天的月份
v_return := 30
else if v_month in ('02') then --如果是2月份
begin
if cast(v_year as int) / 4 = 0 then --如果整除4,则是闰年
v_return := 29
else
v_return := 28
end if;
end;
end if;
return(v_return);
end fn_getdays;
rexyudl 2009-03-12
  • 打赏
  • 举报
回复
这个是IF的语法.
IF condition1 THEN
 statement1;
ELSIF condition2 THEN
 statement2;
ELSIF condition3 THEN
 statement3;
ELSE
 statement4;
END IF;



vf6.0,要考二级没系统的下哈 Microsoft Visual FoxPro 6.0 for Windows 的常见问题 这些是有关 Microsoft Visual FoxPro 最常见的问题。在您求助 Microsoft 产品支持服务之前,请先查阅这张列表。 若想打印这些附注,请从“文件”菜单中选择“打印”命令。此文档分为以下四部分: --------------------------------------------------------------------- 部分 1. 技术支持与市场 部分 2. Visual FoxPro 6.0 新增功能 部分 3. 从其他版本的 FoxPro 和 Visual FoxPro 中移植 部分 4. Visual FoxPro 常见问题 --------------------------------------------------------------------- 部分 1. 技术支持与市场 问题 1-1: 从何处可以获得产品的更新版本? 答案: 在 Visual FoxPro 的 Web 站点上即可获得产品的更新信息,其中包括有关 Service Pack 和更新的示例、向导及其他代码的信息,该站点的网址为: www.microsoft.com/vfoxpro 请定期查看该网站,以便下载产品的最新版本。 问题 1-2: 从何处可以得到有关 Visual FoxPro 的详细资料? 答案: 通过 Microsoft Visual FoxPro Web 站点是随时获得各种最新产品发布信息的最佳途径。在此站点上不仅有新的产品公告,而且还提供了产品的更新信息、技术文章、白皮书、专业开发人员设计的优秀示例、会议公告、以及与其他许多 FoxPro web 站点的各种链接。 问题 1-3: 如何获得技术支持,以及如何报告软件错误? 答案: Microsoft Visual FoxPro Web 站点已经链接到了多种联机支持选项,其中包括覆盖面广阔的有关所有产品 Microsoft Knowledge Base(Microsoft 知识库)。您还可以阅读一份有关常见问题的清单。除联机支持之外,还可以直接通过电话获得技术支持。“帮助”菜单中的选项可列出技术支持的电话号码。这些电话号码也可用于报告产品中的错误。 问题 1-4. 什么是 Knowledge Base?如何使用它? 答案: Knowledge Base 是内容广泛的论文集,覆盖了如何使用产品的各种特性、已知的软件错误及其解决方案或回避的方法、以及其他有助于使用各种 Microsoft 产品的有用信息。通过以下站点可访问整个 Knowledge Base: support.microsoft.com 问题 1-5: 是否会有 Visual FoxPro 6.0a? 答案: Microsoft 公司一向承诺为用户提供高质量的产品。如果确实需要,我们将提供 Visual FoxPro 6.0 的错误修订版。但是,修订版不会使用 6.0a 版的形式。Visual FoxPro 6.0 中任何错误的修正都将包含在 Visual Studio Service Pack 中。同时还会在 Visual FoxPro 的 www.microsoft.com/vfoxpro 或 Visual Studio 的www.microsoft.com/vstudio 的 Web 站点上发布修订公告。 问题 1-6: Microsoft 公司为应用程序的开发提供了一些优秀的解决方案。怎样才能知道应该向客户推荐和使用哪种产品? 答案: 在选择适用某项任务的产品时,需要考虑多方面的因素。Microsoft Visual FoxPro web 站点上有一份优秀的策略背景论文,它比较了 Visual FoxPro、Visual Basic、SQL Server 和 Access 等 Microsoft 产品之间的不同。 问题 1-7: 哪里可以找到 Visual FoxPro 的使用示例? 答案: Visual FoxPro 6.0 产品中带有丰富的示例,其中有一些是针对 6.0 版特有功能的新示例。与 Visual FoxPro 以前的版本不同,这些示例将与所有 Visual Studio 示例安装在一起。您必须运行 MSDN Library 的“自定义”安装来安装这些示例。在 Visual FoxPro 中可使用新的 HOME(2) 函数方便地找到已安装示例的位置。 除了产品中所自带的示例外,Microsoft Visual FoxPro web 站点还将经常提供新的示例。

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧