How to check a procedure/view/table exists or not before dropping it in db2 9.1?

后端 未结 1 1871
[愿得一人]
[愿得一人] 2021-01-23 10:46

How do we write below pseudo code in db2,

If (Proc exists)
  Drop Proc
  Create Proc
Else
 Create Proc

One solution I found, after googling is

相关标签:
1条回答
  • 2021-01-23 11:40

    this query:

    SELECT DISTINCT ROUTINENAME, RESULT_SETS, REMARKS 
    FROM SYSIBM.SYSROUTINES 
    WHERE ROUTINESCHEMA='<schema>' AND FUNCTION_TYPE NOT IN ('S', 'T')
    

    (where you specify your schema name at the placeholder) gives you all procs in a schema. So the Proc exists part is simply an EXISTS query on that view with the proper proc name.

    0 讨论(0)
提交回复
热议问题