鑒于下表
CREATE TABLE dt_test.dt_integer (
id serial NOT NULL,
test_col integer,
test_comment varchar,
CONSTRAINT dt_integer_pk PRIMARY KEY ( id ) ) ;
和插入資料的程序
CREATE PROCEDURE dt_test.integer_insert (
a_id inout int,
a_integer in integer,
a_comment in varchar,
a_err inout varchar ( 200 ) )
SECURITY DEFINER
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
WITH inserted AS (
INSERT INTO dt_test.dt_integer (
test_col,
test_comment )
VALUES (
a_integer,
a_comment )
RETURNING id
)
SELECT id
INTO a_id
FROM inserted ;
END ;
$$ ;
可以/如何從 psql 呼叫該程序?在 Oracle 中,使用 sql-plus 這看起來像:
DECLARE
a_err varchar2 ( 200 ) ;
a_id number ;
BEGIN
dt_test.integer_insert ( a_id, 13, 'A prime example', a_err ) ;
dbms_output.put_line ( 'The new ID is: ' || a_id ) ;
END ;
(我不想認為 sql-plus 可以做 psql 不能做的事情)
uj5u.com熱心網友回復:
好吧,你會在 PL/pgSQL 中做同樣的事情:
set client_min_messages=notice;
do
$$
declare
a_err text;
a_id int;
begin
call dt_test.integer_insert(a_id, 13, 'A prime example', a_err);
raise notice 'The new ID is: %', a_id;
end;
$$
;
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/341479.html
標籤:PostgreSQL 查询语句
