CREATE OR REPLACE function SMERP2122.get_ledger_restrict(p_unit number , p_user number ) return varchar2 as
retval varchar2(4000);
cnt number;
alist varchar2(4000);
lno number := 0;
begin
select count(*) into cnt from
(
select a.txn_ide , a.user_id , segment6 , segment7, segment8, segment9, segment10, segment11
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b
where a.txn_ide = b.txn_ide and a.user_id = p_user
) ;
retval := ' segment4 = ' || p_unit ;
if nvl(cnt,0) <> 0 then
for i in (
select a.txn_ide , a.user_id , segment6 , segment7, segment8,segment9, segment10, segment11
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b
where a.txn_ide = b.txn_ide and a.user_id = p_user
)
loop
if nvl(i.segment6,0) <> 0 then
retval := retval || ' and ( segment6 not in ( ' || i.segment6 || ') ) ' ;
end if;
if nvl(i.segment7,0) <> 0 then
retval := retval || ' and ( segment7 not in (' || i.segment7 || ' ) ) ';
end if;
if nvl(i.segment8,0) <> 0 then
retval := retval || ' and ( segment8 not in ( ' || i.segment8 || ' )) ';
end if;
if nvl(i.segment9,0) <> 0 then
retval := retval || ' and ( segment9 not in ( ' || i.segment9 || ' ) ) ';
end if;
if nvl(i.segment10,0) <> 0 then
retval := retval || ' and ( segment10 not in ( ' || i.segment10 || ' ) ) ' ;
end if;
if nvl(i.segment11,0) <> 0 then
retval := retval || ' and ( segment11 not in ( ' || i.segment11 || ' ) ) ' ;
end if;
if retval is not null then
retval := ' ( ' || retval || ' ) ' ;
end if ;
end loop ;
end if;
select count(*) into cnt from
(
select a.txn_ide , a.user_id , accode
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b , SMF_USER_LEDGER_CODE_D c
where a.txn_ide = b.txn_ide
and b.txn_ide = c.txn_ide
and a.user_id = p_user
);
if nvl(cnt,0) <> 0 then
for i in ( select a.txn_ide , a.user_id , accode
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b , SMF_USER_LEDGER_CODE_D c
where a.txn_ide = b.txn_ide
and b.txn_ide = c.txn_ide
and a.user_id = p_user
)
loop
if lno = 0 then
--alist := ' AND ACCODE NOT IN ( ' || I.ACCODE ;
alist := 'where ACCODE NOT IN ( ' || I.ACCODE ;
lno := lno + 1;
end if;
if lno > 0 then
alist := alist || ' , ' || I.ACCODE ;
end if;
end loop;
alist := alist || ' ) ';
end if;
-- retval := retval || alist ;
retval := alist ;
return retval;
end;
/
retval varchar2(4000);
cnt number;
alist varchar2(4000);
lno number := 0;
begin
select count(*) into cnt from
(
select a.txn_ide , a.user_id , segment6 , segment7, segment8, segment9, segment10, segment11
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b
where a.txn_ide = b.txn_ide and a.user_id = p_user
) ;
retval := ' segment4 = ' || p_unit ;
if nvl(cnt,0) <> 0 then
for i in (
select a.txn_ide , a.user_id , segment6 , segment7, segment8,segment9, segment10, segment11
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b
where a.txn_ide = b.txn_ide and a.user_id = p_user
)
loop
if nvl(i.segment6,0) <> 0 then
retval := retval || ' and ( segment6 not in ( ' || i.segment6 || ') ) ' ;
end if;
if nvl(i.segment7,0) <> 0 then
retval := retval || ' and ( segment7 not in (' || i.segment7 || ' ) ) ';
end if;
if nvl(i.segment8,0) <> 0 then
retval := retval || ' and ( segment8 not in ( ' || i.segment8 || ' )) ';
end if;
if nvl(i.segment9,0) <> 0 then
retval := retval || ' and ( segment9 not in ( ' || i.segment9 || ' ) ) ';
end if;
if nvl(i.segment10,0) <> 0 then
retval := retval || ' and ( segment10 not in ( ' || i.segment10 || ' ) ) ' ;
end if;
if nvl(i.segment11,0) <> 0 then
retval := retval || ' and ( segment11 not in ( ' || i.segment11 || ' ) ) ' ;
end if;
if retval is not null then
retval := ' ( ' || retval || ' ) ' ;
end if ;
end loop ;
end if;
select count(*) into cnt from
(
select a.txn_ide , a.user_id , accode
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b , SMF_USER_LEDGER_CODE_D c
where a.txn_ide = b.txn_ide
and b.txn_ide = c.txn_ide
and a.user_id = p_user
);
if nvl(cnt,0) <> 0 then
for i in ( select a.txn_ide , a.user_id , accode
from SMF_USER_LEDGER_M a , SMF_USER_LEDGER_SEG11_D b , SMF_USER_LEDGER_CODE_D c
where a.txn_ide = b.txn_ide
and b.txn_ide = c.txn_ide
and a.user_id = p_user
)
loop
if lno = 0 then
--alist := ' AND ACCODE NOT IN ( ' || I.ACCODE ;
alist := 'where ACCODE NOT IN ( ' || I.ACCODE ;
lno := lno + 1;
end if;
if lno > 0 then
alist := alist || ' , ' || I.ACCODE ;
end if;
end loop;
alist := alist || ' ) ';
end if;
-- retval := retval || alist ;
retval := alist ;
return retval;
end;
/
No comments:
Post a Comment