<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikti Paul</title>
    <description>The latest articles on DEV Community by Nikti Paul (@niktipaul).</description>
    <link>https://dev.to/niktipaul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F878944%2Fae5d2fcc-ba63-426a-a0fa-1852833d5591.png</url>
      <title>DEV Community: Nikti Paul</title>
      <link>https://dev.to/niktipaul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/niktipaul"/>
    <language>en</language>
    <item>
      <title>Creating 1 way connection among Client and Server using c Lang.</title>
      <dc:creator>Nikti Paul</dc:creator>
      <pubDate>Sat, 18 Jun 2022 11:11:56 +0000</pubDate>
      <link>https://dev.to/niktipaul/creating-1-way-connection-among-client-and-server-using-c-lang-2n1d</link>
      <guid>https://dev.to/niktipaul/creating-1-way-connection-among-client-and-server-using-c-lang-2n1d</guid>
      <description>&lt;p&gt;Many of us have studied Computer Networks. It is the subject that provides us the main concepts regarding Data Communication and Networks.&lt;/p&gt;

&lt;p&gt;Computer Networks divides the whole system into some steps which are the layers of different model.&lt;/p&gt;

&lt;p&gt;The two main models of Computer Networks are OSI model (Open System Interconnection) and TCP/IP model (Transmission Control Protocol/Internet Protocol).&lt;/p&gt;

&lt;p&gt;To sum up we have basic knowledge about the networks,their topologies, LAN, WAN, MAN, different devices,how these devices works on different layers, different protocols and algorithms etc.&lt;/p&gt;

&lt;p&gt;But when it comes to socket programming many of us fear to write code.&lt;br&gt;
So here I am presenting how to set up one way connection among the client and server.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequistics
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;C Language.&lt;/li&gt;
&lt;li&gt;Computer Network Basics.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  System Requirement and Language
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Implementation will be on C Language.&lt;/li&gt;
&lt;li&gt;Linux System is required to perform the task.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Introduction to socket and socket programming
&lt;/h2&gt;

&lt;p&gt;What is a Socket actually? &lt;/p&gt;

&lt;p&gt;Socket in nothing but the combination of the IP address and the Port Number. In the transport Layer, process to process delivery is occured, and for this port number is also required along with the IP address of the system.&lt;/p&gt;

&lt;p&gt;In order to establish connection among the client and server, both the server and the client need to create socket.&lt;/p&gt;

&lt;p&gt;To write code for socket, we use a pre-built structure in C Language, &lt;code&gt;struct sockaddr&lt;/code&gt; and &lt;code&gt;struct sockaddr_in&lt;/code&gt; which comes under the header &lt;code&gt;&amp;lt;netinet/in.h&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;struct sockaddr contains,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct sockaddr {
  unsigned short sa_family; // address family, AF_xxx
  char sa_data[14]; // 14 bytes of protocol address
}; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and struct sockaddr_in contains,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct sockaddr_in {
  short int sin_family; // Address family
  unsigned short int sin_port; // Port number
  struct in_addr sin_addr; // Internet address
  unsigned char sin_zero[8]; // Same size as struct sockaddr
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above structure you could see different variables,&lt;br&gt;
so basically &lt;code&gt;sin_family&lt;/code&gt; stores the Address family of the IP Address like if it is IPv4 we use &lt;code&gt;AF_INET&lt;/code&gt; and if it is IPv6 we use &lt;code&gt;AF_INET6&lt;/code&gt;,&lt;br&gt;
&lt;code&gt;sin_port&lt;/code&gt; stores the port number,&lt;br&gt;
&lt;code&gt;sin_addr&lt;/code&gt; is a variable of another struct type &lt;code&gt;in_addr&lt;/code&gt; whic is defines as:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct in_addr {
  uint32_t s_addr; // that's a 32-bit int (4 bytes)
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Flowchart showing the connection.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sf3liI-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpgamk38leozooiamo6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sf3liI-l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpgamk38leozooiamo6p.png" alt="Image description" width="330" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image Source: GFG&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As shown in the above message first we need to create socket for both client and server side.&lt;/p&gt;

&lt;p&gt;To create socket, &lt;code&gt;socket()&lt;/code&gt; function is used. It comes under the header &lt;code&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Syntax of &lt;code&gt;socket()&lt;/code&gt; is:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int socket (int domain,int type,int protocol);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here, &lt;code&gt;domain&lt;/code&gt; is family of the network, for IPv4 it is &lt;code&gt;AF_INET&lt;/code&gt; and for IPv6 it is &lt;code&gt;AF_INET6&lt;/code&gt;,&lt;br&gt;
&lt;code&gt;type&lt;/code&gt; is the socket type, for UDP we use &lt;code&gt;SOCK_DGRAM&lt;/code&gt; and for TCP we use &lt;code&gt;SOCK_STREAM&lt;/code&gt;,&lt;br&gt;
and the third argument &lt;code&gt;protocol&lt;/code&gt; stores the protocol value used in the program. For default protocol we use 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now in server side,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need to bind the address, i.e we need to cast the &lt;code&gt;struct sockaddr_in&lt;/code&gt; to &lt;code&gt;struct sockaddr&lt;/code&gt; type or we can say that we have to associate the socket with the local address.&lt;br&gt;
and for this task &lt;code&gt;bind()&lt;/code&gt; function is used, which comes under the header &lt;code&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Syntax for &lt;code&gt;bind()&lt;/code&gt; is:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int bind(int s_fd,struct sockaddr *s_addr,int s_len);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;s_fd&lt;/code&gt; is the file descriptor returned by the socket of the server, &lt;code&gt;s_addr&lt;/code&gt; is the pointer to the &lt;code&gt;sockaddr&lt;/code&gt; and &lt;code&gt;s_len&lt;/code&gt; is the length of the &lt;code&gt;s_addr&lt;/code&gt;.If it returns -1 then that means binding process is unsuccessfull.&lt;/p&gt;

&lt;p&gt;Then we need to listen for the clients, and for this purpose we use &lt;code&gt;listen()&lt;/code&gt; function which also comes under the same header  &lt;code&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Syntax for &lt;code&gt;listen()&lt;/code&gt; is:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int listen(int s_fd, int backlog);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;s_fd&lt;/code&gt; is the file descriptor returned by the socket, and &lt;code&gt;backlog&lt;/code&gt; is the total client limit of the socket. If it returns -1 then that means listening process is unsuccessfull.&lt;/p&gt;

&lt;p&gt;The next step is to start accepting the clients, and for this &lt;code&gt;accept()&lt;/code&gt; function is used. This function also comes under the header &lt;code&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Syntax for accept():-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int accept(int s_fd, struct sockaddr *c_addr, int *c_len);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;s_fd&lt;/code&gt; is the file descriptor returned by the socket of the server, &lt;br&gt;
c_addr is the pointer to &lt;code&gt;sockaddr&lt;/code&gt; of the client file descriptor and &lt;code&gt;c_len&lt;/code&gt; is the pointer to the length of &lt;code&gt;c_addr&lt;/code&gt;. It return the socket file descriptor of the client. If it return -1 that mean the process is unsuccessfull.&lt;/p&gt;

&lt;p&gt;After these steps one can start writing message to the client using &lt;code&gt;write()&lt;/code&gt; function and vice-versa.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Client side&lt;/strong&gt;&lt;br&gt;
After creating sockect,a client starting connection with the server using &lt;code&gt;connect()&lt;/code&gt; function. It is belong to the same header &lt;code&gt;&amp;lt;sys/socket.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Syntax of &lt;code&gt;connect()&lt;/code&gt; is:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int connect(int cfd, const struct sockaddr *c_addr, c_len);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;code&gt;cfd&lt;/code&gt; is the file descriptor returned by the socket of the client, &lt;code&gt;c_addr&lt;/code&gt; is the pointer to the &lt;code&gt;sockaddr&lt;/code&gt; and &lt;code&gt;c_len&lt;/code&gt; is the size of &lt;code&gt;c_addr&lt;/code&gt;. If the function returns -1 then it means that the connection is not successfull.&lt;/p&gt;

&lt;p&gt;After this step client can connect with the server and can read data written by the server and vice-versa.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's begin with the code
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Server Code&lt;/strong&gt;&lt;br&gt;
Let us first try to implement the required headers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;unistd.h&amp;gt;
#include&amp;lt;netinet/in.h&amp;gt;
#include&amp;lt;sys/socket.h&amp;gt;
#include&amp;lt;string.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here,&lt;code&gt;&amp;lt;unistd.h&amp;gt;&lt;/code&gt; is used to make use of functions like read() and write().&lt;br&gt;
&lt;code&gt;&amp;lt;stdlib.h&amp;gt;&lt;/code&gt; is for exit() and&lt;br&gt;
&lt;code&gt;&amp;lt;string.h&amp;gt;&lt;/code&gt; is for strcmp() and other string functions.&lt;/p&gt;

&lt;p&gt;Now let's implement the &lt;code&gt;socket()&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct sockaddr_in s_addr;    

int s_fd,s_len;

if((s_fd = socket(AF_INET,SOCK_STREAM,0))==-1){             
    printf("[-]Error in Socket\n");
        exit(0);
}
printf("[+]Server Socket created\n");


s_addr.sin_family = AF_INET;                                  
s_addr.sin_port = 3452;                                       
s_len=sizeof(s_addr); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's implement the other functions i.e.&lt;br&gt;
&lt;code&gt;bind()&lt;/code&gt;,&lt;code&gt;listen()&lt;/code&gt; and &lt;code&gt;accept()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(bind(s_fd,(struct sockaddr*)&amp;amp; s_addr,s_len)==-1){           
        printf("[-]Error in binding\n");
        exit(0);
    }
    printf("[+]Binding successfull\n");

    if(listen(s_fd,5)==-1){                                     
        printf("[-]Error in listen\n");
        exit(0);
    }
    printf("[+]Listening... \n");


    c_len=sizeof(c_addr);                                   
    if((c_fd=accept(s_fd,(struct sockaddr*)&amp;amp;c_addr,&amp;amp;c_len))==-1){
        printf("\n[-]Error in accepting\n");
        exit(0);
    }
    printf("[+]New Client Connected!!!: \n\n");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final code will look like :-&lt;br&gt;
&lt;strong&gt;server.c&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;unistd.h&amp;gt;
#include&amp;lt;netinet/in.h&amp;gt;
#include&amp;lt;sys/socket.h&amp;gt;
#include&amp;lt;sys/types.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;

int main()
{
    struct sockaddr_in s_addr,c_addr;    

    int s_fd,c_fd,s_len,c_len;



    if((s_fd=socket(AF_INET,SOCK_STREAM,0))==-1){               
        printf("[-]Error in Socket\n");
        exit(0);
    }
    printf("[+]Server Socket created\n");

    s_addr.sin_family = AF_INET;                                  
    s_addr.sin_port = 4000;                                       
    s_len=sizeof(s_addr); 

    if(bind(s_fd,(struct sockaddr*)&amp;amp; s_addr,s_len)==-1){           
        printf("[-]Error in binding\n");
        exit(0);
    }
    printf("[+]Binding successfull\n");

    if(listen(s_fd,5)==-1){                                     
        printf("[-]Error in listen\n");
        exit(0);
    }
    printf("[+]Listening... \n");


    c_len=sizeof(c_addr);                                   
    if((c_fd=accept(s_fd,(struct sockaddr*)&amp;amp;c_addr,&amp;amp;c_len))==-1){
        printf("\n[-]Error in accepting\n");
        exit(0);
    }
    printf("[+]New Client Connected!!!: \n\n");

    char buff[100];

    while(1)
    {   
        read(c_fd,buff,100);                                      
        printf("From Client: %s\n",buff);           
        if (strcmp(buff, "Disconnected\n") == 0){
                printf("[-]Client Disconnected");
                break;
            }
    }
    close(c_fd);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly client code will be:-&lt;br&gt;
&lt;strong&gt;client.c&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;unistd.h&amp;gt;
#include&amp;lt;netinet/in.h&amp;gt;
#include&amp;lt;sys/socket.h&amp;gt;
#include&amp;lt;string.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;

int main()
{
        struct sockaddr_in c_addr;                                 
        int c_fd,c_len;
        char buff[100];
        char buff1[2]; 

        if((c_fd=socket(AF_INET,SOCK_STREAM,0))==-1){            
            printf("[-]Error in Socket\n");
            exit(0);
        }
        printf("[+]Client Socket created\n");

        c_addr.sin_family=AF_INET;                                    
        c_addr.sin_addr.s_addr=INADDR_ANY;                       
        c_addr.sin_port=4000;                                     
        c_len=sizeof(c_addr); 

        if(connect(c_fd,(struct sockaddr*)&amp;amp; c_addr,c_len)==-1) { 
            printf("[-]Error in Connect\n");
            exit(0);
        }
        printf("[+]Connected to the Server: \n\n");
        while(1)
        {
            printf("Enter your Message Mr.Client: ");
            fgets(buff,sizeof(buff),stdin);

            if (strcmp(buff, "Exit\n") == 0){
                printf("[-]Disconneted from Server");
                write(c_fd,"Disconnected\n",100);
                break;
            }
            else{
                write(c_fd,buff,100);
            }
        }       
        close(c_fd);                                              
        return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for going through this little blog. If you find any thing wrong please comment below. Don't hesitate to give feedbacks and suggestions.&lt;/p&gt;

</description>
      <category>socketprogramming</category>
      <category>c</category>
    </item>
    <item>
      <title>Printing the largest element from an array using PLSQL (in Oracle Application Express 11g)</title>
      <dc:creator>Nikti Paul</dc:creator>
      <pubDate>Sat, 18 Jun 2022 06:39:59 +0000</pubDate>
      <link>https://dev.to/niktipaul/printing-the-largest-element-from-an-array-using-plsql-in-oracle-application-express-11g-f4p</link>
      <guid>https://dev.to/niktipaul/printing-the-largest-element-from-an-array-using-plsql-in-oracle-application-express-11g-f4p</guid>
      <description>&lt;p&gt;Printing largest element from an array is a basic code. Most of us have done it using c,c++,Java,Python,etc.&lt;br&gt;
But have you thought of printing the same using PLSQL?&lt;/p&gt;

&lt;p&gt;Here I am going to show you how to print the largest element from an array using PLSQL in Oracle Application Express 11g.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequistics
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Oracle Application Express 11g should be installed in your system.&lt;/li&gt;
&lt;li&gt;Basic SQL knowledge is required.&lt;/li&gt;
&lt;li&gt;Basic coding knowledge is required.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Let's Begin with the Logic
&lt;/h2&gt;

&lt;p&gt;To print largest element, first we should assume that 0 is the largest element and declare a variable say maxnum and assign 0 to it like,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;int maxnum = 0;&lt;/code&gt; (where 0 may or may not belong to the array)&lt;/p&gt;

&lt;p&gt;In some cases people also declare the first element of the array as the largest element.&lt;br&gt;
Now,&lt;br&gt;
we will use loop and check whether maxnum is smaller than current element or not, if it is true then we will replace it with the current element and if it is false then we will skip it. Like,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (maxnum &amp;lt; current_element)
  maxnum = current_element;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the loop end, the value of maxnum will be the correct ans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Begin with PLSQL
&lt;/h2&gt;

&lt;p&gt;To write a the above code in PLSQL you should know about:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declaration of statement.&lt;/li&gt;
&lt;li&gt;Executable command.&lt;/li&gt;
&lt;li&gt;Variable,Operators and Datatypes.&lt;/li&gt;
&lt;li&gt;Conditions.&lt;/li&gt;
&lt;li&gt;Loops.&lt;/li&gt;
&lt;li&gt;Arrays and how to declare an array.&lt;/li&gt;
&lt;li&gt;Output Statement.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Declaration of statement.&lt;/strong&gt;&lt;br&gt;
It is an optional section in PLSQL and it is used to define variables, cursors, subprograms, etc.&lt;br&gt;
It starts with &lt;code&gt;DECLARE&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;e.g:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE
 num INTEGER := 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Executable Command.&lt;/strong&gt;&lt;br&gt;
Well, it is a mandatory section and all the statements enclosed in this blocks are executable statements.&lt;br&gt;
It is eclosed between &lt;code&gt;BEGIN&lt;/code&gt; and &lt;code&gt;END&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;e.g:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE
 num INTEGER := 20;
BEGIN
 dbms_output.put_line(num);
 num := num + 30;
 dbms_output.put_line(num);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Variable,Operators and Datatypes.&lt;/strong&gt;&lt;br&gt;
Naming a Variable in PLSQL is not much different from other programming languages.&lt;br&gt;
Even Operators are also same like +,-,*,/, but = is represented here as := and == is represented as =.&lt;br&gt;
Datatypes in PLSQL are different,&lt;br&gt;
Here strings are represented as VARCHAR2,int as INTEGER,NUMBER(Scale,Precision) and many more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7CDXAyYL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hj3vkhr1cypuo2pweuj.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7CDXAyYL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hj3vkhr1cypuo2pweuj.gif" alt="Image description" width="488" height="389"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image Source: Oracle Docs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Condition&lt;/strong&gt;&lt;br&gt;
Like other programming languages PLSQL also have condition statements.&lt;br&gt;
Here IF ELSE is implemented as:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IF &amp;lt;condition&amp;gt; THEN
 &amp;lt;statement 1&amp;gt;;
ELSE
 &amp;lt;statement 2&amp;gt;;
END IF;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for multiple IF statement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IF &amp;lt;condition 1&amp;gt; THEN
 &amp;lt;statement 1&amp;gt;;
ELSIF &amp;lt;condition 2&amp;gt; THEN
 &amp;lt;statement 2&amp;gt;;
ELSIF &amp;lt;condition 3&amp;gt; THEN
 &amp;lt;statement 3&amp;gt;
ELSE
 &amp;lt;statement 4&amp;gt;
END IF;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.Loops&lt;/strong&gt;&lt;br&gt;
There are three types of loops in PLSQL&lt;br&gt;
(a) Basic Loop&lt;br&gt;
(b) For Loop&lt;br&gt;
(c) While Loop&lt;/p&gt;

&lt;p&gt;Basic Loop Syntax:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LOOP 
 &amp;lt;statements&amp;gt;
 &amp;lt;exit condition&amp;gt;
END LOOP;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Loop Syntax:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FOR i IN &amp;lt;start&amp;gt;..&amp;lt;stop&amp;gt; LOOP
 &amp;lt;statements&amp;gt;
END LOOP;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While Loop Syntax:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WHILE &amp;lt;condition&amp;gt; LOOP
 &amp;lt;statements&amp;gt;
END LOOP;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: This Loop statements should be enclosed between the executable statements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Array&lt;/strong&gt;&lt;br&gt;
To declare an array in PLSQL we write the statement as:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type &amp;lt;array_datatype_name&amp;gt; IS VARRAY(&amp;lt;size&amp;gt;) OR &amp;lt;DATATYPE&amp;gt;;
&amp;lt;array_variable_name&amp;gt; &amp;lt;array_datatype_name&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for e.g:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE 
 type intarray is VARRAY(10) OF INTEGER;
 myarray intarray(10,20,30,40,50,60,70,80);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Output Statement&lt;/strong&gt;&lt;br&gt;
To print any statement in PLSQL we use:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dbms_output.put_line(&amp;lt;statement&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To concatenate to strings we use &lt;code&gt;||&lt;/code&gt; double pipes&lt;br&gt;
like,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dbms_output.put_line('Hello '||'World!');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Let's Begin with writing the code
&lt;/h2&gt;

&lt;p&gt;So here we are writing the code for largest element in an array.&lt;/p&gt;

&lt;p&gt;So first we need to declare the required variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE 
 type intarray is VARRAY(10) OF INTEGER;
 myarray intarray;
 total INTEGER;
 maxnum INTEGER;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now, let's use the logic inside the executable statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BEGIN
 myarray := intarray(12,43,56,32,88,46,67,50,66,74);
 total := myarray.count;
 maxnum := 0;
FOR i IN 1..total LOOP
 IF maxnum &amp;lt; myarray(i) THEN
  maxnum := myarray(i);
 END IF;
END LOOP;
dbms_output.put_line('Maximum number in the array is '|| maxnum);
END;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So final code becomes:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DECLARE 
 type intarray is VARRAY(10) OF INTEGER;
 myarray intarray;
 total INTEGER;
 maxnum INTEGER;
BEGIN
 myarray := intarray(12,43,56,32,88,46,67,50,66,74);
 total := myarray.count;
 maxnum := 0;
FOR i IN 1..total LOOP
 IF maxnum &amp;lt; myarray(i) THEN
  maxnum := myarray(i);
 END IF;
END LOOP;
dbms_output.put_line('Maximum number in the array is '|| maxnum);
END;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w8rCI-SA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovqv0v8rub71owhpy54y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w8rCI-SA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovqv0v8rub71owhpy54y.png" alt="Output of the above code" width="268" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Oracle Application Express 11g:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gATQ1kKN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3ubqplijvu7jo1g9xfb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gATQ1kKN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3ubqplijvu7jo1g9xfb.png" alt="Image description" width="880" height="617"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for going through this little blog. If you find any thing wrong please comment below. Don't hesitate to give feedbacks and suggestions.&lt;/p&gt;

</description>
      <category>oracle</category>
      <category>plsql</category>
      <category>arr</category>
    </item>
  </channel>
</rss>
