Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/4-language-usage/3-dml-and-sql/1-general/g-3160.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ alter table employees

declare
r_employee employees%rowtype;
l_id employees.employee_id%type := 107;
l_id employees.employee_id%type := 107;
begin
r_employee := employee_api.employee_by_id(l_id);
r_employee := employee_api.employee_by_id(l_id);
r_employee.salary := r_employee.salary * constants_up.small_increase();

update employees
set row = r_employee
where employee_id = l_id;
end;
/

```
```
Error report -
ORA-54017: update operation disallowed on virtual columns
ORA-06512: at line 9
Expand Down
18 changes: 10 additions & 8 deletions docs/4-language-usage/3-dml-and-sql/1-general/g-3170.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ create table null_test (
test_case number(2) not null
,column_defaulted varchar2(10 char) default 'Default')
/
insert into null_test(test_case, column_defaulted) values (1,'Value');
insert into null_test(test_case, column_defaulted) values (2,default);
insert into null_test(test_case, column_defaulted) values (3,null);
insert into null_test(test_case,column_defaulted) values (1,'Value');
insert into null_test(test_case,column_defaulted) values (2,default);
insert into null_test(test_case,column_defaulted) values (3,null);

select * from null_test;

```
```
TEST_CASE COLUMN_DEF
--------- -----------
1 Value
Expand All @@ -41,12 +42,13 @@ create table null_test (
test_case number(2) not null
,column_defaulted varchar2(10 char) default on null 'Default')
/
insert into null_test(test_case, column_defaulted) values (1,'Value');
insert into null_test(test_case, column_defaulted) values (2,default);
insert into null_test(test_case, column_defaulted) values (3,null);
insert into null_test(test_case,column_defaulted) values (1,'Value');
insert into null_test(test_case,column_defaulted) values (2,default);
insert into null_test(test_case,column_defaulted) values (3,null);

select * from null_test;

```
```
TEST_CASE COLUMN_DEF
---------- ----------
1 Value
Expand Down
53 changes: 30 additions & 23 deletions docs/4-language-usage/3-dml-and-sql/1-general/g-3190.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,50 @@ A `natural join` joins tables on equally named columns. This may comfortably fit
## Example (bad)

``` sql
select department_name
,last_name
,first_name
from employees natural join departments
order by department_name
,last_name;

select department_name
,last_name
,first_name
from employees
natural join departments
order by department_name
,last_name;
```
```
DEPARTMENT_NAME LAST_NAME FIRST_NAME
------------------------------ ------------------------- --------------------
Accounting Gietz William
Executive De Haan Lex
...

```
``` sql
alter table departments add modified_at date default on null sysdate;
alter table employees add modified_at date default on null sysdate;

select department_name
,last_name
,first_name
from employees natural join departments
order by department_name
,last_name;

select department_name
,last_name
,first_name
from employees
natural join departments
order by department_name
,last_name;
```
```
No data found
```

## Example (good)

``` sql
select d.department_name
,e.last_name
,e.first_name
from employees e
join departments d on (e.department_id = d.department_id)
order by d.department_name
,e.last_name;

select d.department_name
,e.last_name
,e.first_name
from employees e
join departments d
on (e.department_id = d.department_id)
order by d.department_name
,e.last_name;
```
```
DEPARTMENT_NAME LAST_NAME FIRST_NAME
------------------------------ ------------------------- --------------------
Accounting Gietz William
Expand Down
10 changes: 5 additions & 5 deletions docs/4-language-usage/5-exception-handling/g-5030.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Using the code below, we are not able to handle the `no_data_found` exception ra

``` sql
declare
l_dummy dual.dummy%type;
l_dummy dual.dummy%type;
no_data_found exception;
co_rownum constant simple_integer := 0;
co_no_data_found constant types_up.short_text_type := 'no_data_found';
Expand All @@ -22,23 +22,23 @@ begin
into l_dummy
from dual
where rownum = co_rownum;
if l_dummy is null then

if l_dummy is null then
raise no_data_found;
end if;
exception
when no_data_found then
sys.dbms_output.put_line(co_no_data_found);
end;
/

```
```
Error report -
ORA-01403: no data found
ORA-06512: at line 5
01403. 00000 - "no data found"
*Cause: No data was found from the objects.
*Action: There was no data from the objects which may be due to end of fetch.

```

## Example (good)
Expand Down
21 changes: 12 additions & 9 deletions docs/4-language-usage/5-exception-handling/g-5080.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ If you use `sqlerrm` or `format_error_stack` to log/display error, you should al
``` sql
create or replace package body order_api as
procedure discount_and_recalculate(
in_customer_id customer.id%type
, in_discount customer.discount_percentage%type
)
in_customer_id customer.id%type
,in_discount customer.discount_percentage%type
) is
begin
customer_api.apply_discount(in_customer_id, in_discount);
customer_api.apply_discount(in_customer_id,in_discount);
customer_api.in_customer_id(10293847);
exception
when zero_divide then
Expand All @@ -36,18 +36,21 @@ end order_api;
``` sql
create or replace package body order_api as
procedure discount_and_recalculate(
in_customer_id customer.id%type
, in_discount customer.discount_percentage%type
)
in_customer_id customer.id%type
,in_discount customer.discount_percentage%type
) is
begin
customer_api.apply_discount(in_customer_id, in_discount);
customer_api.apply_discount(in_customer_id,in_discount);
customer_api.in_customer_id(10293847);
exception
when zero_divide then
null; -- ignore
when others then
logging_package.log_error(
'Error: ' || sqlerrm || ' - Backtrace: ' || dbms_utility.format_error_backtrace
'Error: '
|| sqlerrm
|| ' - Backtrace: '
|| dbms_utility.format_error_backtrace
);
raise;
end discount_and_recalculate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ end department_api;
The exception should be handled where the function is called, like this:

``` sql
...
begin
pre_processing;
r_department := department_api.dept_by_name('Far to long name of a department');
...
post_processing;
exception
when value_error then ...
when value_error then
handle_error;
end;
/
```
2 changes: 1 addition & 1 deletion formatter/install-pre-commit-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ GIT_HOOK_DIR="$FORMATTER_DIR/../.git/hooks"
mkdir -p $GIT_HOOK_DIR
cp $FORMATTER_DIR/pre-commit $GIT_HOOK_DIR/pre-commit
chmod +x $GIT_HOOK_DIR/pre-commit
curl -o $GIT_HOOK_DIR/tvdformat.jar -L https://github.com/Trivadis/plsql-formatter-settings/releases/download/sqldev-22.2.0/tvdformat.jar
curl -o $GIT_HOOK_DIR/tvdformat.jar -L https://github.com/Trivadis/plsql-formatter-settings/releases/download/sqlcl-22.2.1/tvdformat.jar
echo "pre-commit hook installed in $GIT_HOOK_DIR/pre-commit."
2 changes: 1 addition & 1 deletion formatter/trivadis_custom_format.arbori
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
include "std.arbori"

/**
* Lightweight Formatter for SQL Developer and SQLcl, version 22.2.1-SNAPSHOT
* Lightweight Formatter for SQL Developer and SQLcl, version 22.2.1
* The idea is to keep the code formatted "as is" and apply chosen formatting rules only.
*
* The Arbori program is processed from top to bottom.
Expand Down