sql >> データベース >  >> RDS >> Oracle

不要な空のXMLタグを取り除くにはどうすればよいですか?

    ネストされたXMLForest(.. as "recordingInfo")を使用できます XMLElement("recordingInfo")の代わりに呼び出す :

    SELECT XMLAGG(XMLElement("Cue"  -- start level 5 tag for cue
      ,XMLFOREST( rownum as "cueId"
      ,cc.dn_ccst_status as "cueStatusType"
      ,decode(cc.dn_ccst_status,'5',cc.cup_code,NULL) as  "cueCupType" )
      ,XMLElement("musicWork"  -- start level 6 tag for music title
        ,XMLFOREST(cc.title as "musicTitle")
        ,XMLFOREST(
          XMLFOREST(cc.source_album_title as "albumTitle"
            ,cc.product_album_promo_title as "promoTitle"
            ,cc.label as  "label"
            ,cc.catalogue_no as "catalogNumber"
            ,cc.isrc as "isrc") as "recordingInfo"  -- start level 7 tag for music title
          )
        )  -- end level 6 tag for music title
      )  -- end level 5 tag cue
    )
    FROM creation_components cc
    WHERE cc.prod_cre_surr_id = 22736214;
    

    サンプル出力に一致するダミーデータとXMLSerialise 出力を美しくするためのラッパー:

    WITH creation_components (prod_cre_surr_id, dn_ccst_status, cup_code, title,
      source_album_title, product_album_promo_title, label, catalogue_no, isrc) as
    (
      SELECT 22736214, 5, 'W', '[email protected]',
        null, null, null, null, null from dual
    )
    SELECT XMLSERIALIZE(Document
      XMLAGG(XMLElement("Cue"  -- start level 5 tag for cue
        ,XMLFOREST( rownum as "cueId"
        ,cc.dn_ccst_status as "cueStatusType"
        ,decode(cc.dn_ccst_status,'5',cc.cup_code,NULL) as  "cueCupType" )
        ,XMLElement("musicWork"  -- start level 6 tag for music title
          ,XMLFOREST(cc.title as "musicTitle")
          ,XMLFOREST(
            XMLFOREST(cc.source_album_title as "albumTitle"
              ,cc.product_album_promo_title as "promoTitle"
              ,cc.label as  "label"
              ,cc.catalogue_no as "catalogNumber"
              ,cc.isrc as "isrc") as "recordingInfo"  -- start level 7 tag for music title
            )
          )  -- end level 6 tag for music title 
        )  -- end level 5 tag cue
      )
      as CLOB INDENT SIZE = 2
    )
    FROM creation_components cc
    WHERE cc.prod_cre_surr_id = 22736214;
    

    取得

    XMLSERIALIZE(DOCUMENTXMLAGG(XMLELEMENT("CUE"--STARTLEVEL5TAGFORCUE,XMLFOREST(ROW
    --------------------------------------------------------------------------------
    <Cue>
      <cueId>1</cueId>
      <cueStatusType>5</cueStatusType>
      <cueCupType>W</cueCupType>
      <musicWork>
        <musicTitle>[email protected]</musicTitle>
      </musicWork>
    </Cue>
    

    後の列にnull以外のデータがある場合:

    WITH creation_components (prod_cre_surr_id, dn_ccst_status, cup_code, title,
      source_album_title, product_album_promo_title, label, catalogue_no, isrc) as
    (
      SELECT 22736214, 5, 'W', '[email protected]',
        null, null, 'RadioWorks', null, null from dual
    )
    SELECT XMLSERIALIZE(Document
      XMLAGG(XMLElement("Cue"  -- start level 5 tag for cue
        ,XMLFOREST( rownum as "cueId"
        ,cc.dn_ccst_status as "cueStatusType"
        ,decode(cc.dn_ccst_status,'5',cc.cup_code,NULL) as  "cueCupType" )
        ,XMLElement("musicWork"  -- start level 6 tag for music title
          ,XMLFOREST(cc.title as "musicTitle")
          ,XMLFOREST(
            XMLFOREST(cc.source_album_title as "albumTitle"
              ,cc.product_album_promo_title as "promoTitle"
              ,cc.label as  "label"
              ,cc.catalogue_no as "catalogNumber"
              ,cc.isrc as "isrc") as "recordingInfo"  -- start level 7 tag for music title
            )
          )  -- end level 6 tag for music title
        )  -- end level 5 tag cue
      )
      as CLOB INDENT SIZE = 2
    )
    FROM creation_components cc
    WHERE cc.prod_cre_surr_id = 22736214;
    

    余分なタグは引き続き表示されます:

    XMLSERIALIZE(DOCUMENTXMLAGG(XMLELEMENT("CUE"--STARTLEVEL5TAGFORCUE,XMLFOREST(ROW
    --------------------------------------------------------------------------------
    <Cue>
      <cueId>1</cueId>
      <cueStatusType>5</cueStatusType>
      <cueCupType>W</cueCupType>
      <musicWork>
        <musicTitle>[email protected]</musicTitle>
        <recordingInfo>
          <label>RadioWorks</label>
        </recordingInfo>
      </musicWork>
    </Cue>
    



    1. Laravelのデータベースに配列値を挿入します

    2. MySQLは主キー値を交換します

    3. SQL Server(T-SQL)でドイツ語形式で日付を表示する方法

    4. BQクエリの出力を変数に割り当てる