4.2.2. Positional Parameters

4.2.2. Positional Parameters
4.2.2. 位置参数
A positional parameter reference is used to indicate a value that is supplied externally to an SQL statement. Parameters are used in SQL function definitions and in prepared queries. Some client libraries  also support specifying data values separately from the SQL command string, in which case parameters  are used to refer to the out-of-line data values. The form of a parameter reference is:
引用位置参数用于指示从外部给SQL语句提供值。参数用于SQL函数定义和准备好的查询中。 一些客户端库还支持与SQL命令字符串分开指定数据值,在这种情况下,参数用于引用离线数据值。 参数引用的形式为:
 
$number
 
For example, consider the definition of a function, dept , as:
例如,假设定义函数dept:
 
CREATE FUNCTION dept(text) RETURNS dept
AS $$ SELECT * FROM dept WHERE name = $1 $$
LANGUAGE SQL;
 
Here the $1 references the value of the first function argument whenever the function is invoked.
每当调用函数时,此处的$1均指定为指定的第一个参数值。
 
示例:
1)创建dept表,表结构:
2)创建函数:
3)插入测试数据:
4)调用函数,传入$1为one:
 
 
发布了341 篇原创文章 · 获赞 53 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/ghostliming/article/details/104237827