if not (i_ReLaunch = 1 and (dt_enddate is not null))
How this epression will be evaluated in Oracle 10g
when the input value of the i_ReLaunch = null and the value of the dt_enddate is not null
it is entering the loop.
According to the rules in normal c# and all it should not enter the loop as
it will be as follows with the values.
If( not(false and (true))
= if not( false)
=if( true) which implies it should enters the loop
But it is not happening
Can someone let me know if i am wrong at any place
Boolean operations with NULL value in Oracle return UNKNOWN - not true or false. So you have something like this:
If( not(UNKNOWN and (true)) = if not( UNKNOWN) =if( UNKNOWN )
In this case, IF will treat UNKNOWN as false.
If i_relaunch can be null, then you need to use some of NULL handling functions(NVL, NVL2, NULLIF, COALESCE, LNNVL) to be sure that you have correct result.
See these article for more information:
Nulls: Nothing to Worry About
Fundamentals of PL/SQL. Scroll down to - Handling Null Values in Comparisons and Conditional Statements
Related
I'm having trouble bringing a case then into HiveQL.
I have a column with data:
if column is NULL = FALSE
if the column is PEOPLE = TRUE. It returns all results as TRUE.
What's wrong with my role?
SELECT
id,
datetime,
CASE
WHEN tb_people !="" THEN 'TRUE'
ELSE 'FALSE'
END
FROM <BD>.<TABLE>
!="" is only checking for blank strings. "" and NULL are two different things. As such, what you're looking for is:
SELECT
id,
datetime,
CASE
WHEN tb_people IS NOT NULL THEN 'TRUE'
ELSE 'FALSE'
END
FROM <BD>.<TABLE>
I'd also recommend using the boolean true and false rather than string literals. This would let you replace your entire case statement with ifnotnull(tb_people) https://hive.apache.org/javadocs/r3.0.0/api/org/apache/hadoop/hive/ql/exec/vector/expressions/IsNotNull.html.
I wish to have a region displayed only if
SELECT * FROM REI_LABOUR_RATE_REQUEST
WHERE BILLING_PARTNER = :P6_FILTER_DEALER
returns at least one row and the element :P6_FILTER_YEAR is not NULL.
I tried this by writing:
SELECT * FROM REI_LABOUR_RATE_REQUEST
WHERE BILLING_PARTNER = :P6_FILTER_DEALER
AND :P6_FILTER_YEAR != NULL;
but that somehow never returns any row.
Did you try having a conditional display on the region with the type being "Value of item IS NOT NULL" and P6_FILTER_DEALER as the expression.
This should work as long as the value of the item is submitted and the item has the value stored in the session.
Region Source:
SELECT * FROM REI_LABOUR_RATE_REQUEST
WHERE BILLING_PARTNER = :P6_FILTER_DEALER
As #Tony Andrews says:
:P6_FILTER_YEAR != NULL will never be true. use :P6_FILTER_YEAR IS NOT
NULL instead. In fact the condition is redundant here, because
BILLING_PARTNER = :P6_FILTER_DEALER will only be true when
:P6_FILTER_YEAR is not null anyway.
I have to validate some elements for null and then stop execution if they are null.
I have few rules like below which checks for some null values and adds errors
rule "Require begin date for Service Period"
salience 100
when
$servicePeriod : ServicePeriod(beginDate == null)
// check this to avoid the infinite loop
eval(!$servicePeriod.getValidationErrors().contains("Begin date is required."))
then
$servicePeriod.getValidationErrors().add("Begin date is required.");update($servicePeriod);
end
I have some rules like below which first checks 'validationErrors.size() == 0'. Even though validation errors size is greater than zero, it continues to check other validation and fails as they are null. Please let me know how I can modify these rules to avoid exception.
// Rules for Firefighter deduction calculation
rule "Firefighter Annual Salary Deposit Calculation"
salience 50
when
$servicePeriod : ServicePeriod(validationErrors.size() == 0 , periodType.name == "DEPOSIT" , payType.name == "ANNUAL SALARY" , serviceType.name == "FIREFIGHTER" )
then
calculateDeduction($servicePeriod, 0.075);
end
I suspect that you're thinking that in Java, such constraints are evaluated from left to right, so if the first constraint checks for 0 or null, then further constraints are safe. However, this is not the case in Drools comma-separated constraints.
I think that you might be able to switch to a more Java-style expression:
ServicePeriod(
validationErrors.size() == 0,
periodType != null && periodType.name == "DEPOSIT",
payType != null && payType.name == "ANNUAL SALARY",
serviceType != null && serviceType.name == "FIREFIGHTER" )
I'm not totally sure without testing though.
When using sum with lambda in Linq to SQL using the following code:
int query = (from f in odc.RDetails
where f.ticketID == int.Parse(ticket.ToString())
select f).Sum(x => x.Rate);
I get the following error:
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
. You have to make sure x.Rate is an int, and not an int? (an int that accepts null as a value).
. If the query has no elements, .Sum won't do anything and will return null. Choose a default value, let's say 0.
var query = from f in odc.RDetails
where f.ticketID == int.Parse(ticket.ToString())
select f;
int result = query.Any()
? query.Sum(x => x.Rate ?? 0) // use the ?? if x.Rate is an "int?".
: 0; // default value you can choose.
I would break the int.Parse(ticket.ToString()) onto its own line to isolate that parse from the Linq for debugging.
We don't know whether that is throwing the exception or if one of the RDetails.Rate values is null. Is it indeed a Nullable<int>?
If RDetails.Rate is a Nullable<int>, then you could ...Sum(x => x.Rate ?? 0) and avoid the exception.
I am trying to perform to calculation. I have a donations (d) table that contains Quantity Needed (d.QtyNeeded) and I need to determine the numbers of items still needed by pulling quantity filled (qtyfilled) from the donors table. Not every donation has a donor, so I need a conditional statement to handle nulls so the sum will work. When I try to compile, I am getting an error: *Operator '-' cannot be applied to operands of type 'int' and 'bool'. I am not great at Linq yet, what am I missing or is there a better way?
QtyOpen = d.QtyNeeded - (from dv in db.Donors
select dv).All(v => v.QtyFilled == null)
? 0
: (from dv in db.Donations
select dv.QtyFilled).Sum()
The problem is not the LINQ statement, but rather precedence in the subtraction operator. Consider this example:
int result = quantity - true ? 0 : otherValue;
This fails to compile for the exact same reason, Operator '-' cannot be applied to operands of type 'int' and 'bool'. The solution is to simply group the conditional statement in parens:
int result = quantity - (true ? 0 : otherValue);
So, your example should compile by adding parens around your entire conditional operator statement.
Try filtering out the nulls within the initial select by adding a where in the select:
QtyOpen = d.QtyNeeded - (from dv in db.Donors
where dv.QtyFilled != null
select dv.QtyFilled).Sum();