Another way to do this is error handling:
declare v_sql varchar(1000); declare col_missing integer default 0; declare col_does_not_exist condition for sqlstate '42703'; declare continue handler for col_does_not_exist set col_missing = 1; set v_sql = 'select table.foo from table'; execute immediate v_sql; if col_missing = 1 then
This method will work with session tables, and you can also use it on an object, even if you donβt know if it is a table, view, alias, etc.
It is important to specify table.foo , not just the column name, because otherwise the existence of another object (such as a variable) called foo will break the test.
This handler will continue to mask any other errors for columns that are not in scope, so it's best to limit the scope to just the test you want to do.
user1919238
source share