You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# G-7125: Always use CREATE OR REPLACE instead of CREATE alone.
2
+
3
+
!!! tip "Minor"
4
+
Maintainability
5
+
6
+
## Reason
7
+
8
+
Using `create` alone makes your scripts give an error if the program unit already exists, which makes the script not repeatable. It is good practice to use `create or replace` to avoid such errors.
9
+
10
+
## Example (bad)
11
+
12
+
```sql
13
+
create package body employee_api is
14
+
function employee_by_id (in_employee_id inemployees.employee_id%type)
15
+
return employees%rowtype is
16
+
r_employee employees%rowtype;
17
+
begin
18
+
select*
19
+
into r_employee
20
+
from employees
21
+
where employee_id = in_employee_id;
22
+
23
+
return r_employee;
24
+
exception
25
+
when no_data_found then
26
+
null;
27
+
when too_many_rows then
28
+
raise;
29
+
end employee_by_id;
30
+
end employee_api;
31
+
/
32
+
```
33
+
34
+
## Example (good)
35
+
36
+
```sql
37
+
create or replace package body employee_api is
38
+
function employee_by_id (in_employee_id inemployees.employee_id%type)
0 commit comments