Skip to content

Commit 5ed7816

Browse files
Merge pull request #154 from Trivadis/feature/issue-130-valid-sql-code-blocks
Feature/issue 130 valid sql code blocks
2 parents d93df58 + 253b8ac commit 5ed7816

File tree

8 files changed

+70
-53
lines changed

8 files changed

+70
-53
lines changed

docs/4-language-usage/3-dml-and-sql/1-general/g-3160.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@ alter table employees
2525

2626
declare
2727
r_employee employees%rowtype;
28-
l_id employees.employee_id%type := 107;
28+
l_id employees.employee_id%type := 107;
2929
begin
30-
r_employee := employee_api.employee_by_id(l_id);
30+
r_employee := employee_api.employee_by_id(l_id);
3131
r_employee.salary := r_employee.salary * constants_up.small_increase();
3232

3333
update employees
3434
set row = r_employee
3535
where employee_id = l_id;
3636
end;
3737
/
38-
38+
```
39+
```
3940
Error report -
4041
ORA-54017: update operation disallowed on virtual columns
4142
ORA-06512: at line 9

docs/4-language-usage/3-dml-and-sql/1-general/g-3170.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ create table null_test (
2121
test_case number(2) not null
2222
,column_defaulted varchar2(10 char) default 'Default')
2323
/
24-
insert into null_test(test_case, column_defaulted) values (1,'Value');
25-
insert into null_test(test_case, column_defaulted) values (2,default);
26-
insert into null_test(test_case, column_defaulted) values (3,null);
24+
insert into null_test(test_case,column_defaulted) values (1,'Value');
25+
insert into null_test(test_case,column_defaulted) values (2,default);
26+
insert into null_test(test_case,column_defaulted) values (3,null);
2727

2828
select * from null_test;
29-
29+
```
30+
```
3031
TEST_CASE COLUMN_DEF
3132
--------- -----------
3233
1 Value
@@ -41,12 +42,13 @@ create table null_test (
4142
test_case number(2) not null
4243
,column_defaulted varchar2(10 char) default on null 'Default')
4344
/
44-
insert into null_test(test_case, column_defaulted) values (1,'Value');
45-
insert into null_test(test_case, column_defaulted) values (2,default);
46-
insert into null_test(test_case, column_defaulted) values (3,null);
45+
insert into null_test(test_case,column_defaulted) values (1,'Value');
46+
insert into null_test(test_case,column_defaulted) values (2,default);
47+
insert into null_test(test_case,column_defaulted) values (3,null);
4748

4849
select * from null_test;
49-
50+
```
51+
```
5052
TEST_CASE COLUMN_DEF
5153
---------- ----------
5254
1 Value

docs/4-language-usage/3-dml-and-sql/1-general/g-3190.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,50 @@ A `natural join` joins tables on equally named columns. This may comfortably fit
1010
## Example (bad)
1111

1212
``` sql
13-
select department_name
14-
,last_name
15-
,first_name
16-
from employees natural join departments
17-
order by department_name
18-
,last_name;
19-
13+
select department_name
14+
,last_name
15+
,first_name
16+
from employees
17+
natural join departments
18+
order by department_name
19+
,last_name;
20+
```
21+
```
2022
DEPARTMENT_NAME LAST_NAME FIRST_NAME
2123
------------------------------ ------------------------- --------------------
2224
Accounting Gietz William
2325
Executive De Haan Lex
2426
...
25-
27+
```
28+
``` sql
2629
alter table departments add modified_at date default on null sysdate;
2730
alter table employees add modified_at date default on null sysdate;
2831

29-
select department_name
30-
,last_name
31-
,first_name
32-
from employees natural join departments
33-
order by department_name
34-
,last_name;
35-
32+
select department_name
33+
,last_name
34+
,first_name
35+
from employees
36+
natural join departments
37+
order by department_name
38+
,last_name;
39+
```
40+
```
3641
No data found
3742
```
3843

3944
## Example (good)
4045

4146
``` sql
42-
select d.department_name
43-
,e.last_name
44-
,e.first_name
45-
from employees e
46-
join departments d on (e.department_id = d.department_id)
47-
order by d.department_name
48-
,e.last_name;
49-
47+
select d.department_name
48+
,e.last_name
49+
,e.first_name
50+
from employees e
51+
join departments d
52+
on (e.department_id = d.department_id)
53+
order by d.department_name
54+
,e.last_name;
55+
```
56+
```
5057
DEPARTMENT_NAME LAST_NAME FIRST_NAME
5158
------------------------------ ------------------------- --------------------
5259
Accounting Gietz William

docs/4-language-usage/5-exception-handling/g-5030.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Using the code below, we are not able to handle the `no_data_found` exception ra
1313

1414
``` sql
1515
declare
16-
l_dummy dual.dummy%type;
16+
l_dummy dual.dummy%type;
1717
no_data_found exception;
1818
co_rownum constant simple_integer := 0;
1919
co_no_data_found constant types_up.short_text_type := 'no_data_found';
@@ -22,23 +22,23 @@ begin
2222
into l_dummy
2323
from dual
2424
where rownum = co_rownum;
25-
26-
if l_dummy is null then
25+
26+
if l_dummy is null then
2727
raise no_data_found;
2828
end if;
2929
exception
3030
when no_data_found then
3131
sys.dbms_output.put_line(co_no_data_found);
3232
end;
3333
/
34-
34+
```
35+
```
3536
Error report -
3637
ORA-01403: no data found
3738
ORA-06512: at line 5
3839
01403. 00000 - "no data found"
3940
*Cause: No data was found from the objects.
4041
*Action: There was no data from the objects which may be due to end of fetch.
41-
4242
```
4343

4444
## Example (good)

docs/4-language-usage/5-exception-handling/g-5080.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ If you use `sqlerrm` or `format_error_stack` to log/display error, you should al
1414
``` sql
1515
create or replace package body order_api as
1616
procedure discount_and_recalculate(
17-
in_customer_id customer.id%type
18-
, in_discount customer.discount_percentage%type
19-
)
17+
in_customer_id customer.id%type
18+
,in_discount customer.discount_percentage%type
19+
) is
2020
begin
21-
customer_api.apply_discount(in_customer_id, in_discount);
21+
customer_api.apply_discount(in_customer_id,in_discount);
2222
customer_api.in_customer_id(10293847);
2323
exception
2424
when zero_divide then
@@ -36,18 +36,21 @@ end order_api;
3636
``` sql
3737
create or replace package body order_api as
3838
procedure discount_and_recalculate(
39-
in_customer_id customer.id%type
40-
, in_discount customer.discount_percentage%type
41-
)
39+
in_customer_id customer.id%type
40+
,in_discount customer.discount_percentage%type
41+
) is
4242
begin
43-
customer_api.apply_discount(in_customer_id, in_discount);
43+
customer_api.apply_discount(in_customer_id,in_discount);
4444
customer_api.in_customer_id(10293847);
4545
exception
4646
when zero_divide then
4747
null; -- ignore
4848
when others then
4949
logging_package.log_error(
50-
'Error: ' || sqlerrm || ' - Backtrace: ' || dbms_utility.format_error_backtrace
50+
'Error: '
51+
|| sqlerrm
52+
|| ' - Backtrace: '
53+
|| dbms_utility.format_error_backtrace
5154
);
5255
raise;
5356
end discount_and_recalculate;

docs/4-language-usage/8-patterns/3-validating-input-parameter-size/g-8310.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ end department_api;
5454
The exception should be handled where the function is called, like this:
5555

5656
``` sql
57-
...
57+
begin
58+
pre_processing;
5859
r_department := department_api.dept_by_name('Far to long name of a department');
59-
...
60+
post_processing;
6061
exception
61-
when value_error then ...
62+
when value_error then
63+
handle_error;
64+
end;
65+
/
6266
```

formatter/install-pre-commit-hook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ GIT_HOOK_DIR="$FORMATTER_DIR/../.git/hooks"
55
mkdir -p $GIT_HOOK_DIR
66
cp $FORMATTER_DIR/pre-commit $GIT_HOOK_DIR/pre-commit
77
chmod +x $GIT_HOOK_DIR/pre-commit
8-
curl -o $GIT_HOOK_DIR/tvdformat.jar -L https://github.com/Trivadis/plsql-formatter-settings/releases/download/sqldev-22.2.0/tvdformat.jar
8+
curl -o $GIT_HOOK_DIR/tvdformat.jar -L https://github.com/Trivadis/plsql-formatter-settings/releases/download/sqlcl-22.2.1/tvdformat.jar
99
echo "pre-commit hook installed in $GIT_HOOK_DIR/pre-commit."

formatter/trivadis_custom_format.arbori

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
include "std.arbori"
1818

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

0 commit comments

Comments
 (0)