Skip to content

Commit 80e2997

Browse files
committed
3
1 parent 5cd764a commit 80e2997

File tree

2 files changed

+88
-86
lines changed

2 files changed

+88
-86
lines changed

CN/modules/ROOT/pages/master/6.3.2.adoc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ IvorySQL提供了兼容Oracle的out参数功能,包括含有out参数的函数
5050
1. SQL端:在服务器端实现系统函数 get_parameter_description,该函数根据SQL语句,返回变量名字与位置的关系。这个函数被用在libpq接口函数中。
5151
返回的第一行name显示SQL类型,后面行依次显示占位符名字、位置信息。
5252

53-
```
54-
ivorysql=# select * from get_parameter_description('insert into t values(:x, :y);');
55-
name | position
56-
-------+----------
57-
false | 0
58-
:x | 1
59-
:y | 2
60-
(3 rows)
61-
```
62-
对于匿名块语句,尚不支持。
53+
```
54+
ivorysql=# select * from get_parameter_description('insert into t values(:x, :y);');
55+
name | position
56+
-------+----------
57+
false | 0
58+
:x | 1
59+
:y | 2
60+
(3 rows)
61+
```
62+
对于匿名块语句,尚不支持。
6363

6464
2. PLiSQL端:主要是PL/iSQL块根据参数位置或参数名称调整参数内部标识。
6565

66-
执行函数需要从绑定句柄中获取参数的值与类型的信息;
66+
执行函数需要从绑定句柄中获取参数的值与类型的信息;
6767

68-
对out参数的返回列名称做一个特殊处理。如果是out参数,那么其列名称为_column_xxx,其中xxx是out参数的位置,从而根据绑定位置与返回的位置从结果集中给out参数赋值;
68+
对out参数的返回列名称做一个特殊处理。如果是out参数,那么其列名称为_column_xxx,其中xxx是out参数的位置,从而根据绑定位置与返回的位置从结果集中给out参数赋值;
6969

70-
在PLiSQL执行端,根据参数名字出现的位置,调整名字转换成内部标识的变量,如$number。在返回到客户端的时候,发送描述信息给libpq, 从而达到返回的列名是由参数名字构造,LIBPQ端根据列名来给out参数赋值。
70+
在PLiSQL执行端,根据参数名字出现的位置,调整名字转换成内部标识的变量,如$number。在返回到客户端的时候,发送描述信息给libpq, 从而达到返回的列名是由参数名字构造,LIBPQ端根据列名来给out参数赋值。
7171

7272
3. libpq接口端:提供准备、绑定、执行函数,这些函数与OCI接口相应函数类似。
7373

74-
一般调用流程如下:
75-
使用IvyHandleAlloc分配语句句柄和错误句柄。
76-
调用IvyStmtPrepare准备语句。
77-
调用IvyBindByPos或IvyBindByName 绑定参数。
78-
调用IvyStmtExecute 执行,可重复执行。
79-
调用IvyFreeHandle 释放语句句柄和错误句柄。
74+
一般调用流程如下:
75+
使用IvyHandleAlloc分配语句句柄和错误句柄。
76+
调用IvyStmtPrepare准备语句。
77+
调用IvyBindByPos或IvyBindByName 绑定参数。
78+
调用IvyStmtExecute 执行,可重复执行。
79+
调用IvyFreeHandle 释放语句句柄和错误句柄。
8080

81-
另外还实现了Ivyconnectdb,Ivystatus,Ivyexec,IvyresultStatus,IvyCreatePreparedStatement,IvybindOutParameterByPos,IvyexecPreparedStatement,IvyexecPreparedStatement2,Ivynfields,Ivyntuples,Ivyclear等一系列接口函数。
81+
另外还实现了Ivyconnectdb,Ivystatus,Ivyexec,IvyresultStatus,IvyCreatePreparedStatement,IvybindOutParameterByPos,IvyexecPreparedStatement,IvyexecPreparedStatement2,Ivynfields,Ivyntuples,Ivyclear等一系列接口函数。

CN/modules/ROOT/pages/master/7.15.adoc

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -73,81 +73,83 @@ libpq接口端提供准备、绑定、执行函数,这些函数与OCI相应函
7373

7474
1. 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

8888
2. 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

102102
3. 如果有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

129129
1. 支持冒号占位符形式的绑定变量,新增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

144145
2. 系统函数 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

Comments
 (0)