PostgreSQL Stored Procedure
What is a Stored Procedure, which is defined by Baidu Encyclopedia: A Stored Procedure (Stored Procedure) is a set of SQL statements in a large database system to complete specific functions, after the first compilation, the stored procedure does not need to be re-compiled. You can specify the name of the stored procedure and provide parameters (if the stored procedure has parameters) to execute it. Stored procedures are an important object in databases. Any well-designed database application should use stored procedures.
The syntax structure of Postgresql stored procedure is as follows:
Create or replace function name (parameter 1, [integer int4, integer array _ int4,…])
RETURNS return value type
$ BODY $
DECLARE
Variable Declaration
BEGIN
Function body
END;
$ BODY $
LANGUAGE 'plpgsql' VOLATILE;
The following example calls a stored procedure to automatically create a series of tables:
Create or replace function create_table_for_client (id int)
RETURNS integer
$ BODY $
DECLARE
Num int4: = 0;
SQL "varchar ";
BEGIN
SQL: = 'create table _ '| id |' _ company (id int, name text )';
EXECUTE SQL;
SQL: = 'create table _ '| id |' _ employee (id int, name text )';
EXECUTE SQL;
SQL: = 'create table _ '| id |' _ sale_bill (id int, name text )';
EXECUTE SQL;
.......
Return num;
END;
$ BODY $ LANGUAGE plpgsql VOLATILE
------------------------------------ Lili split line ------------------------------------
Install PostgreSQL 6.3 on yum in CentOS 9.3
PostgreSQL cache details
Compiling PostgreSQL on Windows
Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu
Install and configure phppgAdmin on Ubuntu
Install PostgreSQL9.3 on CentOS
Configure a Streaming Replication cluster in PostgreSQL
How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4
------------------------------------ Lili split line ------------------------------------
PostgreSQL details: click here
PostgreSQL: click here
This article permanently updates the link address: