I’m using IBM DB2 9.7.2 on Debian GNU/Linux. I need a conditional DROP INDEX, only if it exists. As it’s not supported I wrote a procedure that accepts IN idx_name VARCHAR(128) as index name. In the procedure I check if index with that name exists in SYSCAT.INDEXES, and if yes I execute
DROP INDEX idx_name;
But apparently DROP INDEX does not accept string.
Alternatively I tried using SYSPROC.SYSTS_DROP() but it gave me an error:
SQL20427N An error occurred during a text search administration procedure or
command. The error message is “CIE00340 Cannot start executable program
“cieadmsv”. “. SQLSTATE=38H14
I probably could modify a procedure to do drop that index and catch an exception so that there is no error if that does not exist but I still don’t know: how can I make DROP INDEX to accept the variable?
DROP INDEX, like most of SQL, doesn’t accept parameters for identifiers (you can’t do this withSELECTstatements either). I expect this has to do with the optimizer attempting to validate/prepare the statement – you can only specify them for column contents, after all.You have two options: