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.

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

  • Variables
  • Constants
  • Cursor
  • Error Status

BEGIN

  • SQL Code
  • PL/SQL Code

EXCEPTION(optional)

  • Error Status

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.

 

Deniz Parlak

Hi, I'm a Computer Engineering student in Dumlupınar University.I will graduate next year. I did an internship TurkNet Telecominication Company in 2018 June- 2018 September. I had experience Linux/Unix system, SQL Server Management , SSRS, Mysql Database Management,Troubleshooting performance issues in Linux. I also interested Oracle database and technologies. I want to work as Oracle DBA after my University. I am practicing Unix, Exadata, Orace Cloud, Oracle RAC, Dataguard, EBS, Oracle BI and etc and i hope the articles will be helpful. Any questions, or support please write email deniz.parlak@yahoo.com

Leave a Reply

Your email address will not be published. Required fields are marked *