खोज…


वाक्य - विन्यास

  1. लूप
  2. [बयान];
  3. बाहर निकलें [निकास पाश के लिए स्थिति];
  4. END LOOP;

सिंपल लूप

DECLARE
v_counter NUMBER(2);

BEGIN
  v_counter := 0;
  LOOP
    v_counter := v_counter + 1;
    dbms_output.put_line('Line number' || v_counter);
    
    EXIT WHEN v_counter = 10;
  END LOOP;
END;

घुमाव के दौरान

WHILE लूप को तब तक निष्पादित किया जाता है जब तक कि समाप्ति की शर्त पूरी नहीं हो जाती। सरल उदाहरण:

DECLARE
v_counter NUMBER(2); --declaration of counter variable

BEGIN
  v_counter := 0; --point of start, first value of our iteration
 
  WHILE v_counter < 10 LOOP --exit condition
    
    dbms_output.put_line('Current iteration of loop is ' || v_counter); --show current iteration number in dbms script output
    v_counter := v_counter + 1; --incrementation of counter value, very important step

  END LOOP; --end of loop declaration
END;

इस लूप को क्रियान्वित किया जाएगा जब तक कि वेरिएबल v_counter का वर्तमान मूल्य दस से कम नहीं होगा।

परिणाम:

Current iteration of loop is 0
Current iteration of loop is 1
Current iteration of loop is 2
Current iteration of loop is 3
Current iteration of loop is 4
Current iteration of loop is 5
Current iteration of loop is 6
Current iteration of loop is 7
Current iteration of loop is 8
Current iteration of loop is 9

सबसे महत्वपूर्ण बात यह है, कि हमारा लूप value 0 ’मान से शुरू होता है, इसलिए परिणामों की पहली पंक्ति it लूप का वर्तमान पुनरावृत्ति 0’ है।

पाश के लिए

अन्य छोरों के समान नियमों पर काम करता है। लूप को कई बार सटीक संख्या में निष्पादित किया जाता है और यह संख्या शुरुआत में जानी जाती है - निचली और ऊपरी सीमाएं सीधे कोड में सेट की जाती हैं। इस उदाहरण में प्रत्येक चरण में, लूप 1 से बढ़ा है।

सरल उदाहरण:

DECLARE
v_counter NUMBER(2); --declaration of counter variable

BEGIN
  v_counter := 0; --point of start, first value of our iteration, execute of variable
 
  FOR v_counter IN 1..10 LOOP --The point, where lower and upper point of loop statement is declared - in this example, loop will be executed 10 times, start with value of 1
    
    dbms_output.put_line('Current iteration of loop is ' || v_counter); --show current iteration number in dbms script output
   
  END LOOP; --end of loop declaration
END;

और परिणाम है:

Current iteration of loop is 1
Current iteration of loop is 2
Current iteration of loop is 3
Current iteration of loop is 4
Current iteration of loop is 5
Current iteration of loop is 6
Current iteration of loop is 7
Current iteration of loop is 8
Current iteration of loop is 9
Current iteration of loop is 10

लूप फॉर में अतिरिक्त संपत्ति है, जो रिवर्स में काम कर रही है। लूप की निचली और ऊपरी सीमा की घोषणा में अतिरिक्त शब्द 'REVERSE' का उपयोग करना। 1 से v_counter के लूप घटाव मूल्य के हर निष्पादन।

उदाहरण:

DECLARE
v_counter NUMBER(2); --declaration of counter variable

BEGIN
  v_counter := 0; --point of start
 
  FOR v_counter IN REVERSE 1..10 LOOP
    
    dbms_output.put_line('Current iteration of loop is ' || v_counter); --show current iteration number in dbms script output
   
  END LOOP; --end of loop declaration
END;

और परिणाम:

Current iteration of loop is 10
Current iteration of loop is 9
Current iteration of loop is 8
Current iteration of loop is 7
Current iteration of loop is 6
Current iteration of loop is 5
Current iteration of loop is 4
Current iteration of loop is 3
Current iteration of loop is 2
Current iteration of loop is 1


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow