Site icon IT Tutorial

PL/SQL Programing -2

Hi, I continue to PL / SQL articles. If you have not read the previous article, I recommend you to start there first. In this article we will introduce PL / SQL a little more closely.

PL/SQL Programing -1 Introduction to PL/SQL

Simple (Anonymous) Block Structure:

We also use this block structure in general one-time code execution. As we will see in other block structures, they are not stored in the database as an object.

DECLARE

BEGIN

EXCEPTION(optional)

END;

DECLARE: Definitions of temporary fields that we will keep in Ram

BEGIN-END: This is the field where SQL and PL / SQL codes work, operators and loops are used in this field.

EXCEPTION: Any error conditions that may occur are captured and actions to be taken are written.

 

Let’s make a example ,

 

SQL> DECLARE
sayi NUMBER;
isim varchar2(30);
BEGIN
sayi:=1;
isim:='Deniz Parlak';
DBMS_OUTPUT.PUT_LINE(isim ||' '||sayi);
END;
/

As you can see, the DBMS_OUTPUT.PUT_LINE function (the hello world of this language) is able to print the contents of our variables on the screen.

Let’s make a nesting example,

SQL> DECLARE

 isim varchar(20); 

BEGIN 

isim:='Yasar Kemal'; 

DECLARE 

eser varchar2(20); 

BEGIN 

eser:='Ince Memed'; 

DBMS_OUTPUT.PUT_LINE(isim ||' '|| eser);

 END; 

END; 

/

I’ve written a PL / SQL code in an easy way. I will conclude this article here, and next article I will continue from the Function and Procedure block.

 

Exit mobile version