Fazer um “pivot” permite reestruturar dados de uma estrutura de dados tipicamente normalizada para um formato diferente, e assim formatar as informações que você precisa de uma maneira muito mais legível aos olhos do usuário que requisita as informações.

As cláusulas PIVOT e UNPIVOT fazem parte das novas features da versão 11g. Nas versões anteriores era necessário uma codificação mais elaborada e complicda, usando CASE. Agora, além de facilitar na codificação, esta operação foi otimizada (segundo a documentação oficial do Oracle) – e assim a operação ganhou uma boa melhora de desempenho em relação a codificação com CASE, considerando obviamente SELECT’s equivalentes.

PIVOT

Permite “nivelar” uma tabela normalizada. Muito útil para formatar visualmente os dados para o seu aplicativo ou para um relatório. A melhor maneira de entender tanto o funcionamento do PIVOT quanto o seu resultado é mostrar um exemplo.
Vamos imaginar que temos uma tabela de VENDAS, em uma empresa que distribui chocolates – e nós queremos relatórios sumarizados, mostrando totais de cada chocolate em colunas separadas, e também agrupando por cliente.
Vamos ao que interessa!

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”Q1JFQVRFIFRBQkxFIHZlbmRhcyAoCiAgaWQgICAgICAgICAgICBOVU1CRVIsCiAgY2xpZW50ZSAgIE5VTUJFUiwKICBwcm9kdXRvICBWQVJDSEFSMigyMCksCiAgcXRkZSAgICAgIE5VTUJFUgopOw==” hover_enabled=”0″]Q1JFQVRFIFRBQkxFIHZlbmRhcyAoCiAgaWQgICAgICAgICAgICBOVU1CRVIsCiAgY2xpZW50ZSAgIE5VTUJFUiwKICBwcm9kdXRvICBWQVJDSEFSMigyMCksCiAgcXRkZSAgICAgIE5VTUJFUgopOw==[/et_pb_dmb_code_snippet]

Tabela criada, agora vamos popular a tabela:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”SU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgxLDEwLCdDaGFyZ2UnLDUwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgyLDExLCdCaXMnLDQwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgzLDEyLCdDaGFyZ2UnLDgwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg0LDEzLCdUb2JsZXJvbmUnLDMwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg1LDEwLCdUb2JsZXJvbmUnLDQwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg2LDExLCdBbHBpbm8nLDEwMCk7CklOU0VSVCBJTlRPIFZFTkRBUyAoSUQsQ0xJRU5URSxQUk9EVVRPLFFUREUpIHZhbHVlcyAoNywxMywnQmlzJywyMDApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDgsMTIsJ0FscGlubycsODApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDksMTAsJ0NoYXJnZScsMzApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDEwLDExLCdDaGFyZ2UnLDIwKTsKQ09NTUlUOwpTUUw+IFNFTEVDVCAqIGZyb20gdmVuZGFzOwoKSUQgICAgQ0xJRU5URSBQUk9EVVRPICAgICAgICAgICAgICAgICAgICBRVERFCiAtLS0tLS0tLS0tIC0tLS0tLS0tLS0gLS0tLS0tLS0tLS0tLS0tLS0tLS0gLS0tLS0tLS0tLQogMSAgICAgICAgIDEwIENoYXJnZSAgICAgICAgICAgICAgICAgICAgICAgNTAKIDIgICAgICAgICAxMSBCaXMgICAgICAgICAgICAgICAgICAgICAgICAgIDQwCiAzICAgICAgICAgMTIgQ2hhcmdlICAgICAgICAgICAgICAgICAgICAgICA4MAogNCAgICAgICAgIDEzIFRvYmxlcm9uZSAgICAgICAgICAgICAgICAgICAgMzAKIDUgICAgICAgICAxMCBUb2JsZXJvbmUgICAgICAgICAgICAgICAgICAgIDQwCiA2ICAgICAgICAgMTEgQWxwaW5vICAgICAgICAgICAgICAgICAgICAgIDEwMAogNyAgICAgICAgIDEzIEJpcyAgICAgICAgICAgICAgICAgICAgICAgICAyMDAKIDggICAgICAgICAxMiBBbHBpbm8gICAgICAgICAgICAgICAgICAgICAgIDgwCiA5ICAgICAgICAgMTAgQ2hhcmdlICAgICAgICAgICAgICAgICAgICAgICAzMAogMTAgICAgICAgICAxMSBDaGFyZ2UgICAgICAgICAgICAgICAgICAgICAgIDIwCgoxMCBsaW5oYXMgc2VsZWNpb25hZGFzLg==” hover_enabled=”0″]SU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgxLDEwLCdDaGFyZ2UnLDUwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgyLDExLCdCaXMnLDQwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICgzLDEyLCdDaGFyZ2UnLDgwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg0LDEzLCdUb2JsZXJvbmUnLDMwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg1LDEwLCdUb2JsZXJvbmUnLDQwKTsKSU5TRVJUIElOVE8gVkVOREFTIChJRCxDTElFTlRFLFBST0RVVE8sUVRERSkgdmFsdWVzICg2LDExLCdBbHBpbm8nLDEwMCk7CklOU0VSVCBJTlRPIFZFTkRBUyAoSUQsQ0xJRU5URSxQUk9EVVRPLFFUREUpIHZhbHVlcyAoNywxMywnQmlzJywyMDApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDgsMTIsJ0FscGlubycsODApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDksMTAsJ0NoYXJnZScsMzApOwpJTlNFUlQgSU5UTyBWRU5EQVMgKElELENMSUVOVEUsUFJPRFVUTyxRVERFKSB2YWx1ZXMgKDEwLDExLCdDaGFyZ2UnLDIwKTsKQ09NTUlUOwpTUUw+IFNFTEVDVCAqIGZyb20gdmVuZGFzOwoKSUQgICAgQ0xJRU5URSBQUk9EVVRPICAgICAgICAgICAgICAgICAgICBRVERFCiAtLS0tLS0tLS0tIC0tLS0tLS0tLS0gLS0tLS0tLS0tLS0tLS0tLS0tLS0gLS0tLS0tLS0tLQogMSAgICAgICAgIDEwIENoYXJnZSAgICAgICAgICAgICAgICAgICAgICAgNTAKIDIgICAgICAgICAxMSBCaXMgICAgICAgICAgICAgICAgICAgICAgICAgIDQwCiAzICAgICAgICAgMTIgQ2hhcmdlICAgICAgICAgICAgICAgICAgICAgICA4MAogNCAgICAgICAgIDEzIFRvYmxlcm9uZSAgICAgICAgICAgICAgICAgICAgMzAKIDUgICAgICAgICAxMCBUb2JsZXJvbmUgICAgICAgICAgICAgICAgICAgIDQwCiA2ICAgICAgICAgMTEgQWxwaW5vICAgICAgICAgICAgICAgICAgICAgIDEwMAogNyAgICAgICAgIDEzIEJpcyAgICAgICAgICAgICAgICAgICAgICAgICAyMDAKIDggICAgICAgICAxMiBBbHBpbm8gICAgICAgICAgICAgICAgICAgICAgIDgwCiA5ICAgICAgICAgMTAgQ2hhcmdlICAgICAgICAgICAgICAgICAgICAgICAzMAogMTAgICAgICAgICAxMSBDaGFyZ2UgICAgICAgICAgICAgICAgICAgICAgIDIwCgoxMCBsaW5oYXMgc2VsZWNpb25hZGFzLg==[/et_pb_dmb_code_snippet]

Agora vamos usar o PIVOT para mostrar o total vendido de cada produto em apenas uma linha, com um produto por coluna.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBTRUxFQ1QgKgogIDIgIEZST00gICAoU0VMRUNUIHByb2R1dG8sIHF0ZGUKICAzICAgICAgICAgIEZST00gICB2ZW5kYXMpCiAgNCAgUElWT1QgIChTVU0ocXRkZSkgQVMgVG90YWwgRk9SIChQUk9EVVRPKQogICAgICAgICAgICBJTiAoJ0NoYXJnZScsICdCaXMnLCAnVG9ibGVyb25lJywgJ0FscGlubycpKTsKCidDaGFyZ2UnX1RPVEFMICdCaXMnX1RPVEFMICdUb2JsZXJvbmUnX1RPVEFMICdBbHBpbm8nX1RPVEFMCi0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tCiAgICAgICAgICAgMTgwICAgICAgICAgMjQwICAgICAgICAgICAgICAgIDcwICAgICAgICAgICAgMTgwCkFnb3JhLCBhZ3J1cGFuZG8gcG9yIGNsaWVudGU6CgpTUUw+IFNFTEVDVCAqCiAgMiAgRlJPTSAgIChTRUxFQ1QgY2xpZW50ZSwgcHJvZHV0bywgcXRkZQogIDMgICAgICAgICAgRlJPTSAgIHZlbmRhcykKICA0ICBQSVZPVCAgKFNVTShxdGRlKSBBUyBUb3RhbCBGT1IgKFBST0RVVE8pCiAgICAgICAgICAgICAgICAgICAgSU4gKCdDaGFyZ2UnLCAnQmlzJywgJ1RvYmxlcm9uZScsICdBbHBpbm8nKSkKICA1ICBPUkRFUiBCWSBjbGllbnRlOwoKICAgQ0xJRU5URSAnQ2hhcmdlJ19UT1RBTCAnQmlzJ19UT1RBTCAnVG9ibGVyb25lJ19UT1RBTCAnQWxwaW5vJ19UT1RBTAotLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tCiAgICAgICAgMTAgICAgICAgICAgICAgODAgICAgICAgICAgICAgICAgICAgICAgICAgICAgNDAKICAgICAgICAxMSAgICAgICAgICAgICAyMCAgICAgICAgICA0MCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwMAogICAgICAgIDEyICAgICAgICAgICAgIDgwICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDgwCiAgICAgICAgMTMgICAgICAgICAgICAgICAgICAgICAgICAyMDAgICAgICAgICAgICAgICAgMzA=” hover_enabled=”0″]U1FMPiBTRUxFQ1QgKgogIDIgIEZST00gICAoU0VMRUNUIHByb2R1dG8sIHF0ZGUKICAzICAgICAgICAgIEZST00gICB2ZW5kYXMpCiAgNCAgUElWT1QgIChTVU0ocXRkZSkgQVMgVG90YWwgRk9SIChQUk9EVVRPKQogICAgICAgICAgICBJTiAoJ0NoYXJnZScsICdCaXMnLCAnVG9ibGVyb25lJywgJ0FscGlubycpKTsKCidDaGFyZ2UnX1RPVEFMICdCaXMnX1RPVEFMICdUb2JsZXJvbmUnX1RPVEFMICdBbHBpbm8nX1RPVEFMCi0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tCiAgICAgICAgICAgMTgwICAgICAgICAgMjQwICAgICAgICAgICAgICAgIDcwICAgICAgICAgICAgMTgwCkFnb3JhLCBhZ3J1cGFuZG8gcG9yIGNsaWVudGU6CgpTUUw+IFNFTEVDVCAqCiAgMiAgRlJPTSAgIChTRUxFQ1QgY2xpZW50ZSwgcHJvZHV0bywgcXRkZQogIDMgICAgICAgICAgRlJPTSAgIHZlbmRhcykKICA0ICBQSVZPVCAgKFNVTShxdGRlKSBBUyBUb3RhbCBGT1IgKFBST0RVVE8pCiAgICAgICAgICAgICAgICAgICAgSU4gKCdDaGFyZ2UnLCAnQmlzJywgJ1RvYmxlcm9uZScsICdBbHBpbm8nKSkKICA1ICBPUkRFUiBCWSBjbGllbnRlOwoKICAgQ0xJRU5URSAnQ2hhcmdlJ19UT1RBTCAnQmlzJ19UT1RBTCAnVG9ibGVyb25lJ19UT1RBTCAnQWxwaW5vJ19UT1RBTAotLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tLS0tIC0tLS0tLS0tLS0tLS0tCiAgICAgICAgMTAgICAgICAgICAgICAgODAgICAgICAgICAgICAgICAgICAgICAgICAgICAgNDAKICAgICAgICAxMSAgICAgICAgICAgICAyMCAgICAgICAgICA0MCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwMAogICAgICAgIDEyICAgICAgICAgICAgIDgwICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDgwCiAgICAgICAgMTMgICAgICAgICAgICAgICAgICAgICAgICAyMDAgICAgICAgICAgICAgICAgMzA=[/et_pb_dmb_code_snippet]

UNPIVOT

A cláusula UNPIVOT faz o caminho inverso: pega uma tabela “pivoteada” e normaliza. Como exemplo, vou usar os mesmos dados para criar uma nova tabela.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBjcmVhdGUgdGFibGUgdmVuZGFzXzIgYXMKICAyICBTRUxFQ1QgKgogIDMgIEZST00gICAoU0VMRUNUIGNsaWVudGUsIHByb2R1dG8sIHF0ZGUKICA0ICAgICAgICAgIEZST00gICB2ZW5kYXMpCiAgNSAgUElWT1QgIChTVU0ocXRkZSkgQVMgVG90YWwgRk9SIChQUk9EVVRPKQogIDYgICAgICAgICAgSU4gKCdDaGFyZ2UnLCAnQmlzJywgJ1RvYmxlcm9uZScsICdBbHBpbm8nKSkKICA3ICBPUkRFUiBCWSBjbGllbnRlOwoKClRhYmVsYSBjcmlhZGEuClNRTD4gc2VsZWN0ICogZnJvbSB2ZW5kYXNfMjsKCkNMSUVOVEUgICAgJ0NoYXJnZSdfVE9UQUwgJ0JpcydfVE9UQUwgJ1RvYmxlcm9uZSdfVE9UQUwgJ0FscGlubydfVE9UQUwKLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLSAtLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLQoxMCAgICAgICAgIDgwICAgICAgICAgICAgICAgICAgICAgICAgIDQwCjExICAgICAgICAgMjAgICAgICAgICAgICAgNDAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAwCjEyICAgICAgICAgODAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgODAKMTMgICAgICAgICAgICAgICAgICAgICAgICAyMDAgICAgICAgICAzMA==” hover_enabled=”0″]U1FMPiBjcmVhdGUgdGFibGUgdmVuZGFzXzIgYXMKICAyICBTRUxFQ1QgKgogIDMgIEZST00gICAoU0VMRUNUIGNsaWVudGUsIHByb2R1dG8sIHF0ZGUKICA0ICAgICAgICAgIEZST00gICB2ZW5kYXMpCiAgNSAgUElWT1QgIChTVU0ocXRkZSkgQVMgVG90YWwgRk9SIChQUk9EVVRPKQogIDYgICAgICAgICAgSU4gKCdDaGFyZ2UnLCAnQmlzJywgJ1RvYmxlcm9uZScsICdBbHBpbm8nKSkKICA3ICBPUkRFUiBCWSBjbGllbnRlOwoKClRhYmVsYSBjcmlhZGEuClNRTD4gc2VsZWN0ICogZnJvbSB2ZW5kYXNfMjsKCkNMSUVOVEUgICAgJ0NoYXJnZSdfVE9UQUwgJ0JpcydfVE9UQUwgJ1RvYmxlcm9uZSdfVE9UQUwgJ0FscGlubydfVE9UQUwKLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLSAtLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLS0tLSAtLS0tLS0tLS0tLS0tLQoxMCAgICAgICAgIDgwICAgICAgICAgICAgICAgICAgICAgICAgIDQwCjExICAgICAgICAgMjAgICAgICAgICAgICAgNDAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTAwCjEyICAgICAgICAgODAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgODAKMTMgICAgICAgICAgICAgICAgICAgICAgICAyMDAgICAgICAgICAzMA==[/et_pb_dmb_code_snippet]

E finalmente o uso do UNPIVOT!

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBTRUxFQ1QgKgogIDIgIEZST00gICB2ZW5kYXNfMgogIDMgIFVOUElWT1QgKHF0ZGUgRk9SIHByb2R1dG8gSU4gKCInQ2hhcmdlJ19UT1RBTCIgQVMgJ0NoYXJnZScsCiAgNCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIidCaXMnX1RPVEFMIiBBUyAnQmlzJywKICA1ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiJ1RvYmxlcm9uZSdfVE9UQUwiIEFTICdUb2JsZXJvbmUnLAogIDYgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICInQWxwaW5vJ19UT1RBTCIgQVMgJ0FscGlubycpKTsKCiAgIENMSUVOVEUgUFJPRFVUTyAgICAgICAgIFFUREUKLS0tLS0tLS0tLSAtLS0tLS0tLS0gLS0tLS0tLS0tLQogICAgICAgIDEwIENoYXJnZSAgICAgICAgICAgIDgwCiAgICAgICAgMTAgVG9ibGVyb25lICAgICAgICAgNDAKICAgICAgICAxMSBDaGFyZ2UgICAgICAgICAgICAyMAogICAgICAgIDExIEJpcyAgICAgICAgICAgICAgIDQwCiAgICAgICAgMTEgQWxwaW5vICAgICAgICAgICAxMDAKICAgICAgICAxMiBDaGFyZ2UgICAgICAgICAgICA4MAogICAgICAgIDEyIEFscGlubyAgICAgICAgICAgIDgwCiAgICAgICAgMTMgQmlzICAgICAgICAgICAgICAyMDAKICAgICAgICAxMyBUb2JsZXJvbmUgICAgICAgICAzMAoKOSBsaW5oYXMgc2VsZWNpb25hZGFzLg==” hover_enabled=”0″]U1FMPiBTRUxFQ1QgKgogIDIgIEZST00gICB2ZW5kYXNfMgogIDMgIFVOUElWT1QgKHF0ZGUgRk9SIHByb2R1dG8gSU4gKCInQ2hhcmdlJ19UT1RBTCIgQVMgJ0NoYXJnZScsCiAgNCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIidCaXMnX1RPVEFMIiBBUyAnQmlzJywKICA1ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiJ1RvYmxlcm9uZSdfVE9UQUwiIEFTICdUb2JsZXJvbmUnLAogIDYgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICInQWxwaW5vJ19UT1RBTCIgQVMgJ0FscGlubycpKTsKCiAgIENMSUVOVEUgUFJPRFVUTyAgICAgICAgIFFUREUKLS0tLS0tLS0tLSAtLS0tLS0tLS0gLS0tLS0tLS0tLQogICAgICAgIDEwIENoYXJnZSAgICAgICAgICAgIDgwCiAgICAgICAgMTAgVG9ibGVyb25lICAgICAgICAgNDAKICAgICAgICAxMSBDaGFyZ2UgICAgICAgICAgICAyMAogICAgICAgIDExIEJpcyAgICAgICAgICAgICAgIDQwCiAgICAgICAgMTEgQWxwaW5vICAgICAgICAgICAxMDAKICAgICAgICAxMiBDaGFyZ2UgICAgICAgICAgICA4MAogICAgICAgIDEyIEFscGlubyAgICAgICAgICAgIDgwCiAgICAgICAgMTMgQmlzICAgICAgICAgICAgICAyMDAKICAgICAgICAxMyBUb2JsZXJvbmUgICAgICAgICAzMAoKOSBsaW5oYXMgc2VsZWNpb25hZGFzLg==[/et_pb_dmb_code_snippet]

Opa! Peraí Milton, mas no primeiro exemplo eram 10 registros. E agora ficaram apenas 9 registros. Por que?

Muito simples. Reparem que no conjunto inicial de registros, o mesmo cliente (10) comprou o mesmo produto (Charge) por duas vezes. Após agrupar os registros em outra tabela, como fizemos na vendas_2, fica impossível o Oracle adivinhar que essa quantidade veio de 2 registros diferentes. Na prática, ou melhor dizendo, em um sistema do mundo real, esta tabela teria mais algum campo para diferenciar essas vendas (um campo com a data da venda, por exemplo), e caso o agrupamento fosse feito por este campo, aí sim seria possível a quebra mais detalhada dos registros.