Forum Stats

  • 3,828,128 Users
  • 2,260,865 Discussions
  • 7,897,487 Comments

Discussions

Create Trigger to Insert Row Automatically

MAFinanceDev-Oracle
MAFinanceDev-Oracle Member Posts: 13
edited Aug 13, 2015 4:45PM in APEX Discussions

Hi Apex'ers

I'm trying to write some SQL code to create a trigger that will do the following: When a row is created on Table A, I want it to create a blank row on Table B.

I'm new and learning SQL, so here's what I've pieced together so far (which I'm sure is far from complete).  I'm hoping to get some help finishing this code to create a trigger.

<span class="kwd" style="color: #00008b;">CREATE</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">TRIGGER</span><span class="pln" style="color: #000000;"> trigger_table_a </span><span class="kwd" style="color: #00008b;">ON</span><span class="pln" style="color: #000000;"> table_b<br/></span><span style="color: #00008b;">BEFORE</span><span class="pln" style="color: #000000;"><br/><br/></span><span class="kwd" style="color: #00008b;">INSERT</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">INTO</span><span class="pln" style="color: #000000;"> <br/>table_b<br/></span><span class="pun" style="color: #000000;">(column1,column2,column3</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"><br/></span>

Thanks for the help!<br/>

Tagged:
MAFinanceDev-OracleKiran Pawar

Answers

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,981 Red Diamond
    edited Aug 13, 2015 2:53PM
    FinanceM&amp;amp;amp;ADeveloper-Oracle wrote:
    
    I'm trying to write some SQL code to create a trigger that will do the following: When a row is created on Table A, I want it to create a blank row on Table B.
    
    I'm new and learning SQL, so here's what I've pieced together so far (which I'm sure is far from complete).  I'm hoping to get some help finishing this code to create a trigger.
    
    <span class="kwd" style="color: #00008b;">CREATE</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">TRIGGER</span><span class="pln" style="color: #000000;"> trigger_table_a </span><span class="kwd" style="color: #00008b;">ON</span><span class="pln" style="color: #000000;"> table_b<br/></span><span style="color: #00008b;">BEFORE</span><span class="pln" style="color: #000000;"><br/><br/></span><span class="kwd" style="color: #00008b;">INSERT</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">INTO</span><span class="pln" style="color: #000000;"> <br/>table_b<br/></span><span class="pun" style="color: #000000;">(column1,column2,column3</span><span class="pun" style="color: #000000;">)</span>
    

    Sounds like an XY question.

    What is the point of this? What are you going to do with the blank rows? How do you propose to tell them apart?

  • Brett Ch
    Brett Ch Member Posts: 40
    edited Aug 13, 2015 2:56PM
    CREATE OR REPLACE TRIGGER (Triggername) BEFORE
      INSERT ON "TABLE_A" FOR EACH row BEGIN
      INSERT INTO table_b
        (column1,column2,column3
        ) VALUES
        (NULL,NULL,NULL
        );
    END;
    

    Let me know if this does what you want.

    Brett

    MAFinanceDev-Oracle
  • MAFinanceDev-Oracle
    MAFinanceDev-Oracle Member Posts: 13
    edited Aug 13, 2015 4:34PM

    Hi Brett,

    Thank you very much that worked perfectly! I greatly appreciate the help.

    Best,

    Robert

  • MAFinanceDev-Oracle
    MAFinanceDev-Oracle Member Posts: 13
    edited Aug 13, 2015 4:40PM

    Hi Fac586,

    It would be a long essay to explain what I'm trying to have my APEX app do so I asked a more targeted question. Brett (below) was able to help me out.


    Thanks,

    Robert

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,981 Red Diamond
    edited Aug 13, 2015 4:45PM
    MAFinanceDev-Oracle wrote:
     
    It would be a long essay to explain what I'm trying to have my APEX app do so I asked a more targeted question. Brett (below) was able to help me out.
    

    Give us the Twitter version. I have been using Oracle since before triggers existed and I have never seen anyone create one to generate empty rows. That should set alarm bells ringing...

    Kiran Pawar
This discussion has been closed.