source

Oracle SQL, 여러 열 연결 + 텍스트 추가

bestscript 2023. 3. 16. 21:36

Oracle SQL, 여러 열 연결 + 텍스트 추가

기본적으로 다음과 같이 표시합니다(전체 행은 ONE 열).

저는 [얼음 기둥]과 [과일 기둥]이 있는 [타이프 기둥] 케이크를 좋아합니다.

결과는 다음과 같습니다.

Cake_Column
----------------

I like chocolate cake with whipped_cream and a cherry.

I like strawberry cake with vanilla_cream and a lemon_slice.

etc.

etc.

다음과 같은 TO_CHAR 문([컬럼] "일부 텍스트" [컬럼])이 필요합니다."new_column_name";

내가 뭘 알아?

Oracle에서 문자열을 연결하기 위한 두 가지 옵션이 있습니다.

CONCAT의 예:

CONCAT(
  CONCAT(
    CONCAT(
      CONCAT(
        CONCAT('I like ', t.type_desc_column), 
        ' cake with '), 
      t.icing_desc_column),
    ' and a '),
  t.fruit_desc_column)

사용.||예:

'I like ' || t.type_desc_column || ' cake with ' || t.icing_desc_column || ' and a ' || t.fruit_desc_column

오퍼레이터를 시험해 보셨나요?

Oracle의 연결 오퍼레이터 매뉴얼>>>>

select 'i like' || type_column || ' with' ect....

아래 쿼리는 Oracle 10G ----에 유효합니다.

select PHONE, CONTACT, (ADDR1 ||  '-' || ADDR2 || '-' || ADDR3) as Address
from CUSTOMER_DETAILS
where Code='341'; 

O/P -

1111 abc@gmail.com 4th street-capetown-sa

Oracle/PLSQL CONCAT함수를 사용하면 두 문자열을 연결할 수 있습니다.

CONCAT( string1, string2 )

문자열 1

연결할 첫 번째 문자열입니다.

스트링2

연결할 두 번째 문자열입니다.

예.

SELECT 'I like ' || type_column_name || ' cake with ' || 
icing_column_name || ' and a ' fruit_column_name || '.' 
AS Cake FROM table;

이것을 시험해 보세요.

SELECT 'I like ' || type_column_name || ' cake with ' || 
icing_column_name || ' and a ' fruit_column_name || '.' 
AS Cake_Column FROM your_table_name;

모든 데이터를 "Cake_Column"이라는 이름의 단일 열 엔트리로 연결해야 합니다.

언급URL : https://stackoverflow.com/questions/1619259/oracle-sql-concatenate-multiple-columns-add-text