database.sarang.net
UserID
Passwd
Database
DBMS
ㆍMySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MySQL Q&A 27625 게시물 읽기
No. 27625
함수가 생각이 안나네요.. 도와주세요 ㅠㅠ
작성자
신기해(t6742)
작성일
2008-06-24 15:58ⓒ
2008-06-24 15:59ⓜ
조회수
3,923

  A필드      |     B필드
12022022
33394000
====================
-> update table01 set B필드=concat(substring(A필드,2,3),"-",substring(A필드,5,3));

  A필드      |     B필드
12022022        022-022
33394000        394-000
=====================
이렇게 나오는데.. 저는 


  A필드      |     B필드
12022022          22-22
33394000           394
=====================
이런 결과를 보고 싶거든요..
substring 대신 저런 결과를 
볼 수 있는 함수가 무엇인지 알려주세요..

이 글에 대한 댓글이 총 2건 있습니다.
select concat(
case convert( substring( '12022022', 3, 3 ), unsigned ) when 0 then '' else convert( substring( '12022022', 3, 3 ), unsigned ) end
, case when 0 = convert( substring( '12022022', 3, 3 ), unsigned ) or 0 = convert( substring( '12022022', 6, 3 ), unsigned ) then '' else '-' end
, case convert( substring( '12022022', 6, 3 ), unsigned ) when 0 then '' else convert( substring( '12022022', 6, 3 ), unsigned ) end
) AS result;


select concat(
case convert( substring( '33394000', 3, 3 ), unsigned ) when 0 then '' else convert( substring( '33394000', 3, 3 ), unsigned ) end
, case when 0 = convert( substring( '33394000', 3, 3 ), unsigned ) or 0 = convert( substring( '33394000', 6, 3 ), unsigned ) then '' else '-' end
, case convert( substring( '33394000', 6, 3 ), unsigned ) when 0 then '' else convert( substring( '33394000', 6, 3 ), unsigned ) end
) AS result;

가 잘 되는 걸로 봐서 답은

update table01 set B필드 = concat(
case convert( substring( A필드, 3, 3 ), unsigned ) when 0 then '' else convert( substring( A필드, 3, 3 ), unsigned ) end
, case when 0 = convert( substring( A필드, 3, 3 ), unsigned ) or 0 = convert( substring( A필드, 6, 3 ), unsigned ) then '' else '-' end
, case convert( substring( A필드, 6, 3 ), unsigned ) when 0 then '' else convert( substring( A필드, 6, 3 ), unsigned ) end
);


스스로 생각해봐도 알맹이는 별로 없고 기럭지만 무지 긴.. -_-;;
우욱님이 2008-06-24 16:47에 작성한 댓글입니다. Edit

Rtirm만 하신다고 보고..^^

update table01 set B = to_char(to_number(substr(A, 3, 3)) || decode('-' || to_number(substr(A, 6,3)),'-0', '', '-' || to_number(substr(A, 6,3))));
anne님이 2008-06-25 11:11에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
2762911111
1111
2008-06-28
3123
27627INSERT 후 바로 SELECT 하였을 때 값을 가지고 오지 못합니다.
안중경
2008-06-26
3239
27626다중 primary key 관련 질문입니다. [1]
동쪽하늘
2008-06-25
3325
27625함수가 생각이 안나네요.. 도와주세요 ㅠㅠ [2]
신기해
2008-06-24
3923
27624mysql 에서 사용자 변경 방법은.
손님
2008-06-24
3203
27623mysql6.0에서 기존db연결이 안되요.. [1]
울라
2008-06-24
3474
27621한 행의 내용 제한 옵션? [2]
유승효
2008-06-24
3364
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.018초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다