Skip to content

Commit f6b4e96

Browse files
committed
Added betwnstr example
1 parent ede9fa1 commit f6b4e96

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

examples/award_bonus/run_award_bonus_test.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
@@award_bonus.sql
33
@@test_award_bonus.pkg
44

5-
set serveroutput on
5+
set serveroutput on size unlimited format truncated
6+
67
exec ut.run(user||'.test_award_bonus',ut_documentation_reporter());
78

89
drop package test_award_bonus;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
create or replace function betwnstr( a_string varchar2, a_start_pos integer, a_end_pos integer ) return varchar2 is
2+
l_start_pos pls_integer := a_start_pos;
3+
begin
4+
if l_start_pos = 0 then
5+
l_start_pos := 1;
6+
end if;
7+
return substr( a_string, l_start_pos, a_end_pos - l_start_pos + 1);
8+
end;
9+
/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@betwnstr.sql
2+
@@test_betwnstr.pkg
3+
4+
set serveroutput on size unlimited format truncated
5+
6+
exec ut.run(user||'.test_betwnstr',ut_documentation_reporter());
7+
8+
drop package test_betwnstr;
9+
drop function betwnstr;
10+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
create or replace package test_betwnstr as
2+
3+
-- %suite(Between string function)
4+
5+
-- %test(Returns substring from start position to end position)
6+
procedure normal_case;
7+
8+
-- %test(Returns substring when start position is zero)
9+
procedure zero_start_position;
10+
11+
-- %test(Returns string until end if end position is greated than string length)
12+
procedure big_end_position;
13+
14+
-- %test(Returns null for null inlut srting value)
15+
procedure null_string;
16+
end;
17+
/
18+
19+
create or replace package body test_betwnstr as
20+
21+
procedure normal_case is
22+
begin
23+
ut.expect( betwnstr( '1234567', 2, 5 ) ).to_( equal('2345') );
24+
end;
25+
26+
procedure zero_start_position is
27+
begin
28+
ut.expect( betwnstr( '1234567', 0, 5 ) ).to_( equal('12345') );
29+
end;
30+
31+
32+
procedure big_end_position is
33+
begin
34+
ut.expect( betwnstr( '1234567', 0, 500 ) ).to_( equal('1234567') );
35+
end;
36+
37+
procedure null_string is
38+
begin
39+
ut.expect( betwnstr( null, 2, 5 ) ).to_( be_null );
40+
end;
41+
42+
end;
43+
/

0 commit comments

Comments
 (0)