728x90

๋ฐ์ดํ„ฐ์ฒ˜๋ฆฌ 10

[MySQL] ๋‚ด์žฅํ•จ์ˆ˜ - ๋ฌธ์ž์—ด ํ•จ์ˆ˜

ASCII(์•„์Šคํ‚ค์ฝ”๋“œ), CHAR(์ˆซ์ž) SELECT ASCII('A'), CHAR(65); --> 65, A๋ฐ˜ํ™˜ BIT_LENGTH, CHAR_LENGHT, LENGTH BIT_LENGTH(): ํ• ๋‹น๋œ ๋น„ํŠธํฌ๊ธฐ ๋ฐ˜ํ™˜ CHAR_LENGTH(): ๋ฌธ์ž ๊ฐœ์ˆ˜ ๋ฐ˜ํ™˜ LENGTH(): ํ• ๋‹น๋œ ๋ฐ”์ดํŠธ ์ˆ˜ ๋ฐ˜ํ™˜ ์˜๋ฌธ: ๋ฌธ์ž๋‹น 1๋ฐ”์ดํŠธ, ํ•œ๊ธ€: ๋ฌธ์ž๋‹น 3๋ฐ”์ดํŠธ SELECT BIT_LENGTH('ABC'), CHAR_LENGTH('ABC), LENGTH('ABC); --24, 3, 3๋ฐ˜ํ™˜ SELECT BIT_LENGTH('๊ฐ€๋‚˜๋‹ค'), CHAR_LENGTH('๊ฐ€๋‚˜๋‹ค'), LENGTH('๊ฐ€๋‚˜๋‹ค'); -- 72, 3, 9 ๋ฐ˜ํ™˜ CONCAT(๋ฌธ์ž์—ด1, ๋ฌธ์ž์—ด2, ...), CONCAT_WS(๋ฌธ์ž์—ด1, ๋ฌธ์ž์—ด2, ...) CO..

DB(Database)/MySQL 2021.01.20

[MySQL] MySQL ๋ณ€์ˆ˜ ์‚ฌ์šฉ๋ฐฉ๋ฒ•(SET, PREPARE, EXECUTE)๊ณผ ๋ฐ์ดํ„ฐ ํ˜•์‹ ๋ณ€ํ™˜ ํ•จ์ˆ˜(CAST, CONVERT,CONCAT), ๋‚ด์žฅํ•จ์ˆ˜(์ œ์–ดํ•จ์ˆ˜ IF, IFNULL, NULLIF, CASE WHEN ELSE END)

๋ณ€์ˆ˜ ์‚ฌ์šฉ ํ˜•์‹ SET @๋ณ€์ˆ˜๋ช… = ๋ณ€์ˆ˜๊ฐ’; -- ๋ณ€์ˆ˜ ์„ ์–ธ, ๊ฐ’ ๋Œ€์ž… SELECT @๋ณ€์ˆ˜์ด๋ฆ„; -- ๋ณ€์ˆ˜ ์ถœ๋ ฅ ์˜ˆ์ œ SET @VAR1 = 1; SET @VAR2 = 2; SELECT @VAR1; -- ๊ฒฐ๊ณผ 1 SELECT @VAR1 + @VAR2; -- ๊ฒฐ๊ณผ 2 SET, PREPARE, EXECUTE ๋ฌธ SET @VAR1 = 1; PREPARE Query FROM 'SELECT * FROM [ํ…Œ์ด๋ธ”๋ช…] ORDER BY [์ •๋ ฌ๊ธฐ์ค€] LIMIT ?'; -- '?'์œ„์น˜์— ๋ณ€์ˆ˜ ์‚ฌ์šฉํ•ด ์ฟผ๋ฆฌ๋ฌธ PREPARE EXECUTE Query USING @VAR1; -- ๋ณ€์ˆ˜ ์‹คํ–‰๋ฌธ ๋ฐ์ดํ„ฐ ํ˜•์‹ ๋ณ€ํ™˜ ํ•จ์ˆ˜ CONVERT(), CAST(): ๊ฐ•์ œ๋กœ ๋ฐ์ดํ„ฐํ˜•์„ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ -- ๋ฐ์ดํ„ฐ๋ฅผ ์ •์ˆ˜๋กœ ์ถœ๋ ฅ SELECT CAST([..

DB(Database)/MySQL 2021.01.20
728x90