Pular para o conteúdo

Fóruns Banco de dados Oracle Update capo Descrição + Caracteres de outro Campo Update capo Descrição + Caracteres de outro Campo

#87874
Rodrigo Almeida
Participante

    Olha essa “workarround” que fiz. hehehehe…

    SQL> conn system@pel_dist_hom
    Informe a senha:
    Conectado.
    SQL>
    SQL>
    SQL>
    SQL>
    SQL> create table PRODUTO (prodid number(5), descricao varchar2(255), embalagem varchar2(30));

    Tabela criada.

    SQL> create sequence SEQ_PRODUTO start with 1 increment by 1 maxvalue 99999 nocache nocycle;

    Seq³Ûncia criada.

    SQL> declare
    2 contador integer;
    3 begin
    4 contador := 1;
    5 while contador col descricao format a30
    SQL> select * from produto;

    PRODID DESCRICAO                      EMBALAGEM
    

         1 AJINOMOTO CARNE                CX-10x20UN
         2 AJINOMOTO CARNE                CX-10x20UN
         3 AJINOMOTO CARNE                CX-10x20UN
         4 AJINOMOTO CARNE                CX-10x20UN
         5 AJINOMOTO CARNE                CX-10x20UN
         6 AJINOMOTO CARNE                CX-10x20UN
         7 AJINOMOTO CARNE                CX-10x20UN
         8 AJINOMOTO CARNE                CX-10x20UN
         9 AJINOMOTO CARNE                CX-10x20UN
        10 AJINOMOTO CARNE                CX-10x20UN
    

    10 linhas selecionadas.

    1 declare
    2 cursor curPRODUTO is (select prodid, descricao, embalagem from produto);
    3 type tpID is table of number;
    4 type tpDESCRICAO is table of varchar2(255);
    5 type tpEMBALAGEM is table of varchar2(60);
    6 regID tpID;
    7 regDESCRICAO tpDESCRICAO;
    8 regEMBALAGEM tpEMBALAGEM;
    9 begin
    10 open curPRODUTO;
    11 fetch curPRODUTO bulk collect into regID, regDESCRICAO, regEMBALAGEM;
    12 close curPRODUTO;
    13 if nvl(regID.COUNT,0) > 0 then
    14 for counter in regID.FIRST..regID.LAST loop
    15 update PRODUTO set descricao = CONCAT(descricao || ' ',SUBSTR(embalagem,4,66)) where prodid = counter;
    16 end loop;
    17 end if;
    18* end;
    SQL> /

    Procedimento PL/SQL concluÝdo com sucesso.

    SQL> select * from PRODUTO;

    PRODID DESCRICAO                      EMBALAGEM
    

         1 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         2 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         3 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         4 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         5 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         6 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         7 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         8 AJINOMOTO CARNE 10x20UN        CX-10x20UN
         9 AJINOMOTO CARNE 10x20UN        CX-10x20UN
        10 AJINOMOTO CARNE 10x20UN        CX-10x20UN
    

    10 linhas selecionadas.

    SQL>

    Vai que vai…

    Abraços,
    Rodrigo Almeida