我有兩列:URL 和名稱。我需要連接到一個變數中的列,但在輸出中我想洗掉雙引號和逗號。
id | url | name | description | last_update
---- ------------------------ ---------------- ------------- -------------
18 | http://www.oreilly.com | O'Reilly Media | |
19 | https://www.google.com | Google | | 2013-06-01
(2 rows)
create or replace Function hello_world()
RETURNS text AS
$$
DECLARE
v_name_url VARCHAR;
BEGIN
select (name, url) INTO v_name_url from links e where id = 18;
RETURN v_name_url;
END
$$ LANGUAGE plpgsql;
輸出
hello_world
----------------------------------------------
("O'Reilly Media",http://www.oreilly.com)
(1 row)
如何從輸出中洗掉雙引號和逗號?
hello_world
--------------------------------------
O'Reilly Media http://www.oreilly.com
(1 row)
uj5u.com熱心網友回復:
您可以將存盤程序更改為以下內容:
drop function hello_world();
create or replace function hello_world()
RETURNS text AS
$$
DECLARE
v_name_url VARCHAR;
BEGIN
select concat(name, ' ', url) INTO v_name_url from links e where id = 18;
RETURN v_name_url;
END
$$ LANGUAGE plpgsql;
你的結果將是這樣的:
select hello_world();
hello_world
---------------------------------------
O'Reilly Media http://www.oreilly.com
(1 row)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/444778.html
標籤:PostgreSQL 功能
