CONCAT (MySQL): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 61: Regel 61:
 
select concat  
 
select concat  
 
(
 
(
4,
+
    4,
 
     5,
 
     5,
 
     6
 
     6
Regel 69: Regel 69:
 
select concat  
 
select concat  
 
(
 
(
# Eerste argument
+
    # Eerste argument
 
     #################
 
     #################
 
     #
 
     #
7,
+
    7,
 
     # Tweede argument
 
     # Tweede argument
 
     #################
 
     #################

Versie van 13 mrt 2018 11:45

Voorbeeld

concat(
   Dim1NL,
   "x",
   Dim2NL,
   "x",
   Dim3NL,
   "mm"
)

Syntaxis - In scripts

Bij sommige commando's moet het openingshaakje direct achter het keywoord staan. Dat is hier niet het geval - Dit werkt:

select 
concat
(
   1,
   2,
   3
)
as blub;

Commentaarregels zijn ook geen probleem:

select concat
(
    # Nu komt het eerste argument
    #############################
    #
    1,
    
    # Nu komt het tweede argument
    #############################
    #
    2,
    
    # Nu komt het derde argument
    ############################
    #
    3
) as blub;

Syntaxis - In sprocs

Syntaxis lijkt voor sprocs niet anders te zijn:

CREATE DEFINER=`root`@`localhost` PROCEDURE `concat_test`()
BEGIN

select concat (1,2,3) as blub_01;

select concat 
(
    4,
    5,
    6
) 
as blub_02;

select concat 
(
    # Eerste argument
    #################
    #
    7,
    # Tweede argument
    #################
    #
    8,
    # Derde argument
    ################
    #
    9
) 
as blub_03;

END

concat_ws

ws staat voor with separator. Bv.:

select concat_ws(" - ",1,2,3)

1 - 2 - 3