Quote:
Originally Posted by ricci
Hi everyone.
I'm trying to make a conditional statement inside a execute stayment, Is this posible??. I put what i'm trying to do, thanks for your help.
Code:
DECLARE VLI_CR1REG, VLI_CR2REG, VLV_CR1COMP, VLV_CR2COMP VARCHAR(5);
SET VLV_QUERY = ('BEGIN ATOMIC DECLARE VLV_QUERY VARCHAR(1000);' ||
'IF ' || VLI_CR2REG || ' ' || VLV_CR1COMP || ' ' || VLI_CR1REG ||' AND ' || VLI_CR1REG ||' ' || VLV_CR2COMP || ' ' ||VLI_CR2REG ||' THEN ' ||
'INSERT INTO SESSION.TEMP_REGLASNUME VALUES(0);'||
'ELSE ' ||
'INSERT INTO SESSION.TEMP_REGLASNUME VALUES(1);' ||
'END IF; END;');
EXECUTE IMMEDIATE VLV_QUERY;
|
(1) Why did you declared VLV_QUERY inside set the value to it?
(2) I thought that combining two insert statement into one was possible and better, like
Code:
DECLARE VLV_QUERY VARCHAR(1000);
SET VLV_QUERY
= 'INSERT INTO SESSION.TEMP_REGLASNUME VALUES('
|| ' CASE WHEN ' || VLI_CR2REG || ' ' || VLV_CR1COMP || ' ' || VLI_CR1REG
|| ' AND ' || VLI_CR1REG || ' ' || VLV_CR2COMP || ' ' || VLI_CR2REG
|| ' THEN 0 ELSE 1 END )';
(3) SESSION.TEMP_REGLASNUME looks one column temporary table.
And you inserted 0 or 1.
Why did you used temporary table rather than a declared variable?
If you want pass the value to another stored procedure,
you can pass the value as a parameter for the procedure.
And I thought that passing as a parameter is better for debugging/maintenance,
because it make clear the procedures using the value.
If passed as a temporary table,
you might influence unexpectedly to a procedure which is using the value outside your knowledge,
at the time of modifying this procedure.