Data Insertion by loop - Steem Dev Community.

in Steem Devlast month

Hello Everyone,


20240326_153057_0000.png

Good afternoon to all.
how are you. I hope you all friends will be well and good. By the grace of God, i am also good. Today i am explaining the loop structure in PLSQL and use the loop statement for data insertion.

In PLSQL, the LOOP statement provides the key control structure to run a block of code to execute multiple times to meet the particular condition.

Syntax of basic loop:

LOOP   
   statements;   
   EXIT;   
END LOOP; 



Above is the syntax of executable body loop. The part of code between LOOP and END LOOP is called the body of the loop. In this part, we will write valid PL/SQL commands like assigning values, making decisions, calling functions and so on.

The loop keeps running until the exit condition is satisfied, we explicitly define this condition using an IF statement with an EXIT keyword within the loop. The LOOP statement offers a method to manage how PL/SQL programs run. It help us to run a block of code several times without writing the repeated code.

Now We write a small code to print 1 to 10 number on screen then we will insert these number into a table.

DECLARE 
   x NUMBER := 1; 
BEGIN 
   LOOP 
      DBMS_OUTPUT.PUT_LINE(x); 
      INSERT INTO TEST (A) VALUES (x);   
      x := x + 1;  
    IF x > 10 THEN      
         EXIT; 
    END IF; 
  END LOOP; 
END;



The above PLSQL code initializes a variable x with the value 1 and enters a loop. Within each iteration of the loop it will prints the value of x and inserts the current value of x into a table named TEST by increment of 1. Once x reaches a value greater than 10, the loop stops. Before that, it inserts numbers from 1 to 10 into a table called TEST and shows each number on the screen using DBMS_OUTPUT.

It would be my pleasure if you will share your opinion and reviews on this topic.

Please cast witness vote to @bangla.Witness or set proxy to @rme.

_
Vote @bangla.witness as witness
Set Proxy @rme as proxy

Special Thanks.

Cc: @rme
Cc: @hungry-griffin
Cc: @pennsif

Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram

🆃🅷🅰️🅽🅺 🆈🅾️🆄

Sort:  

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.034
BTC 63914.94
ETH 3312.82
USDT 1.00
SBD 3.92