@@ -73,81 +73,83 @@ libpq接口端提供准备、绑定、执行函数,这些函数与OCI相应函
7373
74741. out参数和返回值数据类型没有关联
7575
76- ```
77- ivorysql=# create or replace function test_return_out(id integer,price out integer,name out varchar) return varchar
78- ivorysql-# as
79- ivorysql-# begin
80- ivorysql-# price := 20000;
81- ivorysql-# name := 'test a char out';
82- ivorysql-# return 'welcome to QingDao';
83- ivorysql-# end;
84- ivorysql-# /
85- CREATE FUNCTION
86- ```
76+ ```
77+ ivorysql=# create or replace function test_return_out(id integer,price out integer,name out varchar) return varchar
78+ ivorysql-# as
79+ ivorysql-# begin
80+ ivorysql-# price := 20000;
81+ ivorysql-# name := 'test a char out';
82+ ivorysql-# return 'welcome to QingDao';
83+ ivorysql-# end;
84+ ivorysql-# /
85+ CREATE FUNCTION
86+ ```
8787
88882. IN OUT模式和OUT模式都不能有默认值
8989
90- ```
91- ivorysql=# create or replace function test_return_inout(id integer,price in out integer default 100,name out varchar) return varchar
92- ivorysql-# as
93- ivorysql-# begin
94- ivorysql-# price := 20000 + price;
95- ivorysql-# name := 'this is a test';
96- ivorysql-# return 'welcome to QingDao';
97- ivorysql-# end;
98- ivorysql-# /
99- ERROR: IN OUT formal parameters may have no default expressions
100- ```
90+ ```
91+ ivorysql=# create or replace function test_return_inout(id integer,price in out integer default 100,name out varchar) return varchar
92+ ivorysql-# as
93+ ivorysql-# begin
94+ ivorysql-# price := 20000 + price;
95+ ivorysql-# name := 'this is a test';
96+ ivorysql-# return 'welcome to QingDao';
97+ ivorysql-# end;
98+ ivorysql-# /
99+ ERROR: IN OUT formal parameters may have no default expressions
100+ ```
101101
1021023. 如果有out参数,并且函数返回类型不是void,则函数体中必须有RETURN语句
103103
104- ```
105- --if function's return type is non-void, the function body must has RETURN statement
106- --if there is no RETURN statement, the function can be created, but when it is called,
107- --an error is raised
108- ivorysql=# create or replace function f2(id integer,price out integer) return varchar
109- ivorysql-# as
110- ivorysql-# begin
111- ivorysql-# price := 2;
112- ivorysql-# end;
113- ivorysql-# /
114- CREATE FUNCTION
115- ivorysql=# declare
116- ivorysql-# a varchar(20);
117- ivorysql-# b int;
118- ivorysql-# begin
119- ivorysql-# a := f2(1, b);
120- ivorysql-# end;
121- ivorysql-# /
122- ERROR: Function returned without value
123- CONTEXT: PL/iSQL function f2(pg_catalog.int4,pg_catalog.int4) line 0 at RETURN
124- PL/iSQL function inline_code_block line 5 at assignment
125- ```
104+ ```
105+ --if function's return type is non-void, the function body must has RETURN statement
106+ --if there is no RETURN statement, the function can be created, but when it is called,
107+ --an error is raised
108+ ivorysql=# create or replace function f2(id integer,price out integer) return varchar
109+ ivorysql-# as
110+ ivorysql-# begin
111+ ivorysql-# price := 2;
112+ ivorysql-# end;
113+ ivorysql-# /
114+ CREATE FUNCTION
115+ ivorysql=# declare
116+ ivorysql-# a varchar(20);
117+ ivorysql-# b int;
118+ ivorysql-# begin
119+ ivorysql-# a := f2(1, b);
120+ ivorysql-# end;
121+ ivorysql-# /
122+ ERROR: Function returned without value
123+ CONTEXT: PL/iSQL function f2(pg_catalog.int4,pg_catalog.int4) line 0 at RETURN
124+ PL/iSQL function inline_code_block line 5 at assignment
125+ ```
126126
127127=== 匿名块支持out参数
128128
1291291. 支持冒号占位符形式的绑定变量,新增DO+USING语法
130- ```
131- ivorysql=# do $$
132- ivorysql$# declare
133- ivorysql$# a int;
134- ivorysql$# begin
135- ivorysql$# :x := 1;
136- ivorysql$# :y := 2;
137- ivorysql$# end; $$ using out, out;
138- $1 | $2
139- ----+----
140- 1 | 2
141- (1 row)
142- ```
130+
131+ ```
132+ ivorysql=# do $$
133+ ivorysql$# declare
134+ ivorysql$# a int;
135+ ivorysql$# begin
136+ ivorysql$# :x := 1;
137+ ivorysql$# :y := 2;
138+ ivorysql$# end; $$ using out, out;
139+ $1 | $2
140+ ----+----
141+ 1 | 2
142+ (1 row)
143+ ```
143144
1441452. 系统函数 get_parameter_descr
145- ```
146- ivorysql=# select * from get_parameter_description('insert into t values(:x,:y)');
147- name | position
148- -------+----------
149- false | 0
150- :x | 1
151- :y | 2
152- (3 rows)
153- ```
146+
147+ ```
148+ ivorysql=# select * from get_parameter_description('insert into t values(:x,:y)');
149+ name | position
150+ -------+----------
151+ false | 0
152+ :x | 1
153+ :y | 2
154+ (3 rows)
155+ ```
0 commit comments