PostgreSQL/Postgre SQL/String Calculation — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 13:13, 26 мая 2010

Assigning a concatenated value to a string

   <source lang="sql">

postgres=# postgres=# postgres=# -- Assigning a concatenated value to a string postgres=# postgres=# CREATE FUNCTION title_and_author (text, text) RETURNS text AS " postgres"# DECLARE postgres"# -- Declare aliases for the two function arguments. postgres"# title ALIAS for $1; postgres"# author ALIAS for $2; postgres"# result text; postgres"# postgres"# BEGIN postgres"# result := title || "", by "" || author; postgres"# -- Return the resulting string. postgres"# return result; postgres"# postgres"# END; postgres"# " language "plpgsql"; CREATE FUNCTION postgres=# postgres=# select title_and_author("a","b");

title_and_author

a, by b

(1 row) postgres=# postgres=#

      </source>
   
  


Joined words

   <source lang="sql">

postgres=# CREATE FUNCTION "compound_word" (text,text) RETURNS text AS " postgres"# DECLARE postgres"# -- defines an alias name for the two input values postgres"# word1 ALIAS FOR $1; postgres"# word2 ALIAS FOR $2; postgres"# BEGIN postgres"# -- displays the resulting joined words postgres"# RETURN word1 || word2; postgres"# END; postgres"# " LANGUAGE "plpgsql"; CREATE FUNCTION postgres=# postgres=# select compound_word("www.sqle.ru"," Postgre SQL");

      compound_word

www.sqle.ru Postgre SQL

(1 row) postgres=# postgres=#

      </source>