There are two if statements in my pl sql code where I am doing the same action. I tried to combine the two if statements with 'OR' condition. But it fails. If I check two conditions separately as in below it works as expected.
IF(rec_.invoice_id IS NOT NULL) THEN
IF (Tax_API.Tax_Items_Taxable_Exist(rec_.company, Tax_Source_API.DB_INVOICE, TO_CHAR(rec_.invoice_id), TO_CHAR(rec_.item_id), '*', '*', '*') = 'TRUE')THEN
type := 'A';
END IF;
ELSE
IF(Report_Type_API.Is_Taxable_Db(rec_.company, rec_.report_code, rec_.account_date)='TRUE') THEN
type := 'A';
END IF;
END IF;
If I combine two if statements with a 'OR' condition as below, why does not it work?
IF ((Tax_API.Tax_Items_Taxable_Exist(rec_.company, Tax_Source_API.DB_INVOICE, TO_CHAR(rec_.invoice_id), TO_CHAR(rec_.item_id), '*', '*', '*') = 'TRUE') OR (Report_Type_API.Is_Taxable_Db(rec_.company, rec_.report_code, rec_.account_date)='TRUE'))THEN
CodePudding user response:
That would be
IF rec_.invoice_id IS NOT NULL
AND ( tax_api.tax_items_taxable_exist (rec_.company,
tax_source_api.db_invoice,
TO_CHAR (rec_.invoice_id),
TO_CHAR (rec_.item_id),
'*',
'*',
'*') = 'TRUE'
OR report_type_api.is_taxable_db (rec_.company,
rec_.report_code,
rec_.account_date) =
'TRUE')
THEN
TYPE := 'A';
END IF;
CodePudding user response:
You want to include the tests for the NULL
state of rec_.invoice_id
on both sides of the OR
condition:
IF ( rec_.invoice_id IS NOT NULL
AND Tax_API.Tax_Items_Taxable_Exist(
rec_.company,
Tax_Source_API.DB_INVOICE,
TO_CHAR(rec_.invoice_id),
TO_CHAR(rec_.item_id),
'*',
'*',
'*'
) = 'TRUE'
)
OR ( rec_.invoice_id IS NULL
AND Report_Type_API.Is_Taxable_Db(
rec_.company,
rec_.report_code,
rec_.account_date
) = 'TRUE'
)
THEN
type := 'A';
END IF;