답변 4개
QA 제목에 의 거하여 특정문자라고 명시 되었기 때문에 해당 특정 문자는 고정으로 가정하고 작성했던 답변
----------------------------------------------
http://sir.co.kr/qa/?wr_id=35885&page=1&posting=ok&sca=&sfl=&stx=&sst=&sod=&spt=0&page=1&vsst=lastet&vpage=1#answer_35893">http://sir.co.kr/qa/?wr_id=35885&page=1&posting=ok&sca=&sfl=&stx=&sst=&sod=&spt=0&page=1&vsst=lastet&vpage=1#answer_35893
반대로 특정 문자가 고정 되있지 않고 유동적이며 자릿수는 고정일때의 답변
----------------------------------------------
자리 수 기준으로 데이터를 변형하는 방법입니다.
변경하고자 하는 데이터
abcdefg-1234567
에서
abcdefg-
의 글자수가 정해져 있다면 다음 같은 시도로 지정된 글자 수 만큼 문자열을 제거 할 수 있습니다.
</p><p>UPDATE 테이블 SET `check` = <span style="color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">substring</span><span style="font-family: 돋움, Dotum, Helvetica, sans-serif; font-size: 12px; line-height: 1.5;"></span><span style="font-family: 돋움, Dotum, Helvetica, sans-serif; font-size: 12px; line-height: 1.5;">(`check`, 9); </span></p><p>
위 처럼 쿼리를 날렸을 경우 check 문자열의 가장 앞자리 부터 8번째 자리 까지 지우고 9번째 부터의 문자열을 추출하여 업데이트가 가능합니다.
</span></font></p><p><font face="돋움, Dotum, Helvetica, sans-serif"><span style="font-size: 12px; line-height: 18px;">결과: 1234567</span></font></p><p><font face="돋움, Dotum, Helvetica, sans-serif"><span style="font-size: 12px; line-height: 18px;">
하지만 위조건으로 데이터를 변환 할 수있는 데이터(은)는
check의 데이터가 abcdefg-1234567 처럼 되있어야 한다는 점입니다.
무조건 앞자리부터 8자리를 지우기 때문이죠.
이를 커버 하기 위해서는 조건을 추가 하셔야 합니다.
예를 들어
</span></font></p><p><font face="돋움, Dotum, Helvetica, sans-serif"><span style="font-size: 12px; line-height: 18px;">UPDATE 테이블 SET `check` = </span></font><span style="color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">substring</span><span style="font-size: 12px; line-height: 18px; font-family: 돋움, Dotum, Helvetica, sans-serif;"></span><span style="font-size: 12px; line-height: 18px; font-family: 돋움, Dotum, Helvetica, sans-serif;">(`check`, 9) where `check` like '%-%'</span></p><p><font face="돋움, Dotum, Helvetica, sans-serif"><span style="font-size: 12px; line-height: 18px;">
처럼 말이죠.
</span></p><p><span style="font-size: 12px; line-height: 18px; font-family: 돋움, Dotum, Helvetica, sans-serif;"></span><span style="color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">- SUBSTRING(str, pos) 혹은 SUBSTRING(str FROM pos)</span></p><p style="margin: 2px; color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">- 문자열 str 에서 pos 위치부터 끝까지 문자를 잘라낸다.</p><p style="margin: 2px; color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;"> </p><p style="margin: 2px; color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">mysql> select substring('Quadratically',5);
+------------------------------+
| substring('Quadratically',5) |
+------------------------------+
| ratically |
+------------------------------+
1 row in set (0.00 sec)</p><p><span style="color: rgb(75, 99, 124); font-family: ����, Arial, Verdana; font-size: 12px; line-height: 16.799999237060547px; text-align: justify;">mysql></span><span style="font-size: 12px; line-height: 18px; font-family: 돋움, Dotum, Helvetica, sans-serif;"> </span></p><p><span style="font-size: 12px; line-height: 18px; font-family: 돋움, Dotum, Helvetica, sans-serif;">
참고: http://jlancer.net/board/article_view.jsp?article_no=6&board_no=4">http://jlancer.net/board/article_view.jsp?article_no=6&board_no=4
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
abcdefg- 이문자열이 고정화라는 기준하에 아래처럼 사용가능합니다.
UPDATE 테이블 SET `check` = REPLACE(`check`, 'abcdefg-', '');
UPDATE 테이블 SET 필드 = REPLACE(필드, '바꾸고 싶은말', '바꿀말');
ps. 정규식으로 바꾸는 것은 안해봤네요.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
이렇게 하면 abcdefg-만 지워 집니다.
단...abcdefg-가 고정이 아닐것 같은데...
해당 조건은 다음 댓글에 이어 작성 합니다.