1 /*
2 * chap 02
3 * -------------------------------------------------
4 */
5
6 -- 01
7 create or replace function wordcount(str in varchar2)
8 return pls_integer
9 as
10 words pls_integer := 0;
11 len pls_integer := nvl(length(str), 0);
12 inside_a_word boolean;
13 begin
14 for i in 1..len + 1
15 loop
16 if ascii(substr(str, i, 1)) < 33 or i > len
17 then
18 if inside_a_word
19 then
20 words := words + 1;
21 inside_a_word := false;
22 end if;
23 else
24 inside_a_word := true;
25 end if;
26 end;
27 /
28 show error;
![]()
create function wordcount(str in varchar2)
return pls_integer
as
declare local variables here
-- 注意, 这里直接就可以声明了, 不需要在使用declare 声明了+
-- declare 声明, 是针对独立的pl/sql块的
begin
implement algorithm here
exception
exception execute
end;
/
Create Function