CONCAT (MySQL): verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(10 tussenliggende versies door dezelfde gebruiker niet weergegeven) | |||
Regel 1: | Regel 1: | ||
− | + | == Voorbeeld == | |
<pre> | <pre> | ||
Regel 10: | Regel 10: | ||
"mm" | "mm" | ||
) | ) | ||
+ | </pre> | ||
+ | |||
+ | == Syntaxis - In scripts == | ||
+ | |||
+ | Bij sommige commando's moet het openingshaakje direct achter het keywoord staan. Dat is hier niet het geval - Dit werkt: | ||
+ | |||
+ | <pre> | ||
+ | select | ||
+ | concat | ||
+ | ( | ||
+ | 1, | ||
+ | 2, | ||
+ | 3 | ||
+ | ) | ||
+ | as blub; | ||
+ | </pre> | ||
+ | |||
+ | Commentaarregels zijn ook geen probleem: | ||
+ | |||
+ | <pre> | ||
+ | select concat | ||
+ | ( | ||
+ | # Nu komt het eerste argument | ||
+ | ############################# | ||
+ | # | ||
+ | 1, | ||
+ | |||
+ | # Nu komt het tweede argument | ||
+ | ############################# | ||
+ | # | ||
+ | 2, | ||
+ | |||
+ | # Nu komt het derde argument | ||
+ | ############################ | ||
+ | # | ||
+ | 3 | ||
+ | ) as blub; | ||
+ | </pre> | ||
+ | |||
+ | == Syntaxis - In sprocs == | ||
+ | |||
+ | Syntaxis lijkt voor sprocs niet anders te zijn: | ||
+ | |||
+ | <pre> | ||
+ | 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 | ||
+ | </pre> | ||
+ | |||
+ | == Incorrect column name 'concat'-foutmelding == | ||
+ | |||
+ | De complete foutmelding, die me in maart 2018 parten speelde: | ||
+ | |||
+ | <pre> | ||
+ | 14:47:35 call superquery_prepare_description() Error Code: 1166. | ||
+ | Incorrect column name 'concat ( "<b>Set von zwei xxxxxxxxxxx Yyyyüyyy</b>", | ||
+ | 1, 2, 3 )' 0,0059 sec | ||
+ | </pre> | ||
+ | |||
+ | Oorzaak: De resulterende kolom had geen eigen naam gekregen, en werd zodoende deze uitdrukking, en dat was blijkbaar te gortig voor MySQL. | ||
+ | |||
+ | Oplossing: Voeg <code>as xxx</code> toe. Bv.: | ||
+ | |||
+ | <pre> | ||
+ | select | ||
+ | |||
+ | concat | ||
+ | ( | ||
+ | "<b>Set von zwei xxxxx Yyyyüyyy</b>", | ||
+ | ifnull(concat(" für ", brands, " Handwerkzeuge"), " für Handwerkzeuge"), | ||
+ | ifnull(concat(" - Abmessungen: ",dim1,"x",dim2,"x",dim3,"mm"),""), | ||
+ | ifnull(concat(" - Ersatz für diese Original-abc: ",orgbrush_tmp5.orgbrush_id),""), | ||
+ | if(automatic_stop=0, ""," - Mit automatischer Abschaltung") | ||
+ | ) | ||
+ | as basis # DEZE REGEL MAAKT HET VERSCHIL | ||
+ | from root_tmp | ||
</pre> | </pre> |
Huidige versie van 13 mrt 2018 om 15:56
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
Incorrect column name 'concat'-foutmelding
De complete foutmelding, die me in maart 2018 parten speelde:
14:47:35 call superquery_prepare_description() Error Code: 1166. Incorrect column name 'concat ( "<b>Set von zwei xxxxxxxxxxx Yyyyüyyy</b>", 1, 2, 3 )' 0,0059 sec
Oorzaak: De resulterende kolom had geen eigen naam gekregen, en werd zodoende deze uitdrukking, en dat was blijkbaar te gortig voor MySQL.
Oplossing: Voeg as xxx
toe. Bv.:
select concat ( "<b>Set von zwei xxxxx Yyyyüyyy</b>", ifnull(concat(" für ", brands, " Handwerkzeuge"), " für Handwerkzeuge"), ifnull(concat(" - Abmessungen: ",dim1,"x",dim2,"x",dim3,"mm"),""), ifnull(concat(" - Ersatz für diese Original-abc: ",orgbrush_tmp5.orgbrush_id),""), if(automatic_stop=0, ""," - Mit automatischer Abschaltung") ) as basis # DEZE REGEL MAAKT HET VERSCHIL from root_tmp