Trending February 2024 # Leveraging Sql Server 7.0 Stored Procedures # Suggested March 2024 # Top 5 Popular

You are reading the article Leveraging Sql Server 7.0 Stored Procedures updated in February 2024 on the website Daihoichemgio.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Leveraging Sql Server 7.0 Stored Procedures

By Sanjiv Purba

Introduction

Last week I introduced you to stored procedures, database objects that the American National Standards Institute defines as part of the Transact-SQL extension. If you missed part one of this article, I suggest reading it over before you move forward. If you’re already familiar with stored procedures and get busy using them, let’s get started!

Creating and Dropping Stored Procedures

Stored procedures are database objects that include the name of the stored procedure, input parameters, local variables, control-of-flow statements, DML statements, DDL statements, some DCL statements, global variables and a return statement. Stored procedures are created with the CREATE PROCedure statement. A stored procedure must be dropped with the DROP PROCedure statement before it is re-created.

The syntax to create a stored procedure is as follows:

USE database_name CREATE PROCedure [owner.] name [@input_parm_list dtype =default OUTput] [options] AS Transact SQL Statements GO

The syntax to remove a stored procedure from a database is as follows:

USE database_name DROP PROCEDURE proc_name GO

Executing Stored Procedures

Stored procedures can be executed using the following syntax:

EXECute proc_name [optional_parameter_list]

This command can be executed at the SQL Server command prompt, inside the Query Analyzer, from inside another stored procedure, or from a client.

User-Defined Variables

Variables are defined in stored procedures using a DECLARE statement, and a mneumonic variable name that is prefaced with ‘@’. Some examples of this are as follows:

DECLARE @last_user_name char(30), @first_user_name char(30), @years_of_experience int, @promotion_date datetime

Global Variables

Global variables can also be inspected inside stored procedures, for example, with the SELECT or PRINT statements. Commonly used global variables are @@VERSION, @@CONNECTIONS, @@ERROR, @@FETCH_STATUS, @@IDENTITY, @@NESTLEVEL, @@ROWCOUNT, @@SERVERNAME, @@TOTAL_ERRORS, and @@TRANCOUNT.

Control-of-Flow Language

The control-of-flow extensions that are available in SQL Server to build sophisticated stored procedures include the following statements: chúng tôi IF..ELSE, IF EXISTS, CASE chúng tôi WAITFOR, GOTO LABEL [label:], COMPUTE, WHILE, CONTINUE, BREAK, and RETURN. These are described in more detail in this section.

chúng tôi

This command block is used to surround multiple Transact-SQL statements in stored procedures so that they are executed as a single statement. The syntax for this command is as follows:

BEGIN Statements Statements Statements END

IF..ELSE

The chúng tôi command block supported in the Control-of-flow dialect is the classical third-generation if-else construct. When the condition belonging to the IF evaluates to true, the statement immediately following the IF statement is executed and the statement belonging to the ELSE is skipped. If the condition belonging to the IF is false, then the statement corresponding to the ELSE is executed. chúng tôi constructs can also be nested. The syntax for this command block is as follows:

IF Condition Statements ELSE IF Condition Statements ELSE IF condition Statements ELSE Statements

IF EXISTS

The IF EXISTS test is used to determine if a specific object exists within a database. The statement can be used to inspect the sysobjects sytem table that contains a row for every object in the database. An example for doing this is as follows:

IF EXISTS (select name from sysobjects where name = 'value_of_name' AND type = 'INITIAL') drop table table_name go

chúng tôi

In this statement, a condition is evaluated at the start of the command block and a branch that matches the condition is then executed. Statements belonging to other conditions are skipped. Control is passed to the statement immediately following the chúng tôi block after the statement is executed. The syntax for this command is as follows:

CASE condition WHEN condition THEN statements WHEN condition THEN statements WHEN condition THEN statements ELSE statements END

GOTO LABEL [label:]

The first component of this construct consists of the GOTO LABEL code that forces an unconditional branch to the LABEL. The second component of this construct is a label: that marks a spot somewhere in the same stored procedure batch. Use of a GOTO is always controversial as a programming technique. It should be used consistently and clearly to avoid countless or untraceable branches. The syntax for this command is as follows:

GOTO label_name label_name:

WAITFOR

The WAITFOR statement pauses active processing of the batch until a specific statement is true. This command is generally used in conjunction with a timer that stops the processing for a specified time increment before continuing. The syntax for this command is as follows:

COMPUTE

The COMPUTE statement is used to calculate results and save them in a declared variable. The following example demonstrates use of the COMPUTE statement:

COMPUTE salary = base + bonus

WHILE

The WHILE statement is used to execute a set of statements until a condition is met. The condition can be a compound statement that combines multiple conditions using AND and OR. The syntax for this command is as follows:

WHILE condition BEGIN Statements END

CONTINUE

The CONTINUE statement is used to pass control to the start of a WHILE statement where the condition is evaluated again. The syntax for this command is the word itself:

CONTINUE

BREAK The BREAK statement is used to immediately and unconditionally exit a WHILE statement block. Control is passed to the statement immediately following the WHILE block. The syntax for this command is the word itself:

BREAK

RETURN

The RETURN statement is used to send a status back to the calling program and exit from the current program (e.g. RETURN 0).

GENERATING ERRORS

The Raiserror statement generates an error message from a stored procedure. An example of this is as follows:

raiserror 60200 'testing raiserror', 3 select @@error

or

sp_addmessage 60200, 11, 'this is a message' raiserror (60200, 11, 1)

ARITHMETIC AND BOOLEAN OPERATORS

Conclusion

Stored procedures have been critical to the growing popularity of SQL Server since 1987. Despite the availability of other techniques, stored procedures continue to be popular in application architecture due to their power, performance boosts, security augmentation, and support for n-tier architecture. Stored procedures support sophisticated language constructs including a rich control-of-flow language, DDL statements, DML statements, DCL statements, global variables, and functions.

About the author:

Sanjiv Purba is a Senior Manager with Deloitte Consulting. He is the author of five books published by John Wiley, the most recent of which is Building Microsoft SQL Server 7 Applications with COM.

You're reading Leveraging Sql Server 7.0 Stored Procedures

Different Types Of Sql Functions

SQL, or Structured Query Language, is a programming language used for managing and manipulating relational databases. One of the most powerful features of SQL is the ability to use functions to perform various operations on the data in a database. In this article, we’ll discuss the different categories of SQL functions and provide code examples to help illustrate their use.

Aggregate Functions

Aggregate functions are used to perform calculations on a set of values and return a single result. Some of the most commonly used aggregate functions in SQL include −

COUNT() – Returns the number of rows in a table or the number of non-NULL values in a column

SUM() – Returns the sum of all non-NULL values in a column

AVG() – Returns the average of all non-NULL values in a column

MIN() – Returns the minimum value in a column

MAX() – Returns the maximum value in a column

Here’s an example of using the COUNT() function to find the number of rows in a table called “orders” −

SELECT

COUNT

(

*

)

FROM

orders

;

And here’s an example of using the SUM() function to find the total cost of all orders in the table −

SELECT

SUM

(

total_cost

)

FROM

orders

;

Scalar Functions

Scalar functions are used to perform calculations on a single value and return a single result. Some examples of scalar functions in SQL include −

LENGTH() – Returns the number of characters in a string

UPPER() – Converts a string to uppercase

LOWER() – Converts a string to lowercase

CONCAT() – Concatenates two or more strings together

ROUND() – Rounds a number to a specified number of decimal places

Here’s an example of using the UPPER() function to display the names of all customers in uppercase −

SELECT

UPPER

(

customer_name

)

FROM

customers

;

And here’s an example of using the ROUND() function to round the total cost of an order to two decimal places −

SELECT

ROUND

(

total_cost

,

2

)

FROM

orders

;

Date and Time Functions

SQL also provides a number of functions for working with date and time values. Some examples of date and time functions in SQL include −

NOW() – Returns the current date and time

CURRENT_DATE() – Returns the current date

CURRENT_TIME() – Returns the current time

YEAR() – Returns the year of a date

MONTH() – Returns the month of a date

DAY() – Returns the day of a date

Here’s an example of using the NOW() function to find the current date and time −

SELECT

NOW

(

)

;

And here’s an example of using the MONTH() function to find the month of an order’s date −

SELECT

MONTH

(

order_date

)

FROM

orders

;

String Functions

SQL also provides a number of string manipulation function. Some examples of string functions in SQL include −

LTRIM() – Removes the leading whitespace of the string

RTRIM() – Removes the trailing whitespace of the string

TRIM() – Removes both leading and trailing whitespace of the string

SUBSTRING() – Extracts a specific portion of a string

REPLACE() – Replaces all occurrences of a specified string with another string

Conditional Functions

SQL also provides a number of functions that perform different actions based on certain conditions. Some examples of conditional functions in SQL include −

CASE – evaluates a list of conditions and returns a result for the first condition that is met

IF – return a specified value if the condition is met, otherwise return another specified value

COALESCE – return the first non-null expression among multiple expressions.

Here’s an example of using the CASE function to assign a label to each order based on the total cost −

SELECT

order_id

,

total_cost

,

CASE

ELSE

'inexpensive'

END

as

"price range"

FROM

orders

;

Here’s an example of using the IF function to check the availability of stock of a product

SELECT

product_name

,

"Availability"

FROM

products

;

Here’s an example of using the COALESCE function to display the primary phone number and the secondary phone number of a customer −

SELECT

customer_name

,

COALESCE

(

primary_phone

,

secondary_phone

)

as

"Phone Number"

FROM

customers

;

Logical Functions

SQL provides a set of logical functions that return a Boolean value, which can be either true or false. Some examples of logical functions in SQL include −

AND – Returns true if both the conditions are true

OR – Returns true if at least one of the conditions is true

NOT – Negates a boolean value

Here’s an example of using the AND function to find all customers who live in a specific city and have an account balance greater than a certain amount −

SELECT

customer_name

,

city

,

account_balance

FROM

customers

Conversion Functions

SQL provides a number of functions that can be used to convert data from one type to another. Some examples of conversion functions in SQL include −

CAST() – Converts a value from one data type to another

CONVERT() – Converts a value from one data type to another (This function is specific for some database vendors like SQL Server)

TO_DATE() – Converts a string to a date value

TO_TIME() – Converts a string to a time value

TO_TIMESTAMP() – Converts a string to a timestamp value

Here’s an example of using the CAST() function to convert a float value to an int −

SELECT

CAST

(

price

AS

INT

)

as

"Integer Price"

FROM

products

;

Here’s an example of using the TO_DATE() function to convert a string to a date value −

SELECT

TO_DATE

(

order_date

,

'yyyy-mm-dd'

)

as

"Formatted Order Date"

FROM

orders

;

Window Functions

SQL provides a set of functions that can be used to perform calculations across a set of rows that are related to the current row. These functions are known as window functions. Some examples of window functions in SQL include −

RANK() – Assigns a unique rank to each row within a result set, based on the values in one or more columns

DENSE_RANK() – Assigns a unique rank to each row within a result set, based on the values in one or more columns, but does not leave gaps in the ranking sequence when there are ties

ROW_NUMBER() – Assigns a unique number to each row within a result set, based on the order specified in the ORDER BY clause of the function

Here’s an example of using the RANK() function to find the rank of each customer based on their account balance −

SELECT

customer_name

,

account_balance

,

RANK

(

)

OVER

(

ORDER

BY

account_balance

DESC

)

as

"Rank"

FROM

customers

;

Here’s an example of using the ROW_NUMBER() function to find the row number of each customer in the table −

SELECT

customer_name

,

ROW_NUMBER

(

)

OVER

(

ORDER

BY

customer_id

)

as

"Row Number"

FROM

customers

;

These are just a few examples of the many functions that SQL provides for working with and manipulating data in a relational database. Each category of functions serves its own unique purpose, and understanding when and how to use them can help to make working with SQL and relational databases more efficient and effective.

Conclusion

SQL functions are an incredibly powerful tool for working with and manipulating data in a relational database. In this article, we’ve discussed the different categories of SQL functions, including aggregate functions, scalar functions, date and time functions, string functions, and conditional functions, and provided examples of how they can be used. Understanding and being proficient in the use of these functions is an essential part of working with SQL and relational databases.

Sql Foundation For Data Engineer

Do you want to learn a skill that can help you earn nearly $100,000 per year? If so, then this course is for you!

SQL (Structured Query Language) is the language we use to interact with databases that store data. This allows us to retrieve data with ease and simplicity. As terms like business intelligence and big data become more familiar, businesses will need more people to learn the SQL language.

This course will teach you how to use the SQL language.

You will have plenty of video lessons to teach you the majority of the content. Each section includes practice problems with proper explanations. On completion of the course, you will be able to query and extract insights from any dataset.

LEARN SQL WITH MySQL

In order to make intelligent business decisions you need the proper data. In order to get the proper data you will need to communicate with and query data within a database. This is where SQL comes into play. SQL stands for Structured Query Language. It’s the language used to communicate with a database and more importantly the data needed to make intelligent decisions that will save time and money.

WHY THIS COURSE

This SQL course starts with the absolute basic building blocks necessary to communicate effectively with any database. You’ll learn how to query and manage a database using MySQL. MySQL is a free open-source relational database management system (RDBMS), used by many of the world’s largest organizations.

Each section of the course will focus on a key topic of working with SQL. The video lectures have been created so you can follow along as the instructor demonstrates each concept. At the end of each section, you can test your understanding through a section quiz and exercise. Once you complete a section the next section will build on the topics of the previous section. This encourages your learning as you build upon the knowledge you learn as you move from one section to the next.

This course is not just a sit back and watching the instructor type on the screen kind of course. The lectures and course flow have been designed to help you engage in the topic and participate by writing your own SQL. TRUE LEARNING happens when you apply what you’re learning and try it yourself.

The course also contains downloadable resources you can use away from the course as you continue to learn SQL. The QA board found within the course offers you the opportunity to ask questions and get answers from the instructor and interact with the other students enrolled in the course.

Goals

Learn Proper SQL Syntax Using the MySQL Workbench

Learn Relational Database Design Concepts

Use the SQL SELECT Statement in Order to Query Data from a Database

Use Column Alias to Give additional Context and Meaning to the Data

Learn How to Filtering Database Query Results Using the SQL Where Clause

Create Advanced Queries by Using the Proper Filter Operators

Use the SQL ORDER BY Keyword to Sort the Results of a Query

Learn How to Properly Group Data and Create Calculations for Reporting

Use the SQL HAVING Clause to Filter within Data Groups

Create a MySQL Database from Scratch

Learn How to Create Tables and Manage Records within the Tables

And Much More…

Prerequisites

A PC (Windows or Linux) or Mac is required

No prior knowledge of Databases, SQL  is needed.

Governments Leveraging Big Data Innovations To Tackle Coronavirus

The outbreak of coronavirus has taken many countries under its hood. Most of them are suffering from economic loss and a higher mortality rate. Amid this, governments are in a great dilemma – how to handle the circumstances around the falling economy and upsurging coronavirus infections. In order to get better hold onto situations across their countries, they are moving towards innovative technology adoption. Out of all the new-age technologies, big data and data analytics can serve with a great opportunity, where governments across various nations can understand the outbreak analytics. In South Korea , where initially the infections spun out of control, the government has been able to slow down the pandemic by using aggressive tracking tools. For example, the government has released a smartphone app that can track self-quarantine subjects to ensure that they do not leave their homes and maintain strict separation from other people, including family members. Those under quarantine can use the app to report their symptoms, and provide status updates to officials. Similarly, Israel is using mobile phone data to track the movements of those who have tested positive for the virus and to identify those who need to be quarantined. Moreover, across Bangladesh, the government has initiated a process to draw a digital map to track coronavirus cases and find out areas susceptible to contamination by using mobile users’ information — a move that may help portray the real picture of a possible outbreak. Under a self-reporting method, mobile users will get a short message (SMS) from their operators and in reply, they will share some of their health information. All the 16.62 crore mobile phone users in the country will start getting SMS from this morning and they will be asked to make a call to *3332# free of charge. During the 90-second call in the form of interactive voice response (IVR), users will reply to five questions about their age; whether they have breathing problems; if they have fever or cough; whether they have come in contact with someone who returned from abroad recently; and if they have come close to any coronavirus-infected people. Furthermore, one of the countries that have efficiently harnessed big data analytics to contain the spread of the Coronavirus pandemic is Taiwan . The country reported only about 50 odd cases by mid-March, while its neighbor (South Korea) had clocked close to 8000 cases. Taiwanese officials have conducted a detailed mapping of people who were infected and from whom they caught the infection. They integrated the Taiwan National Health Insurance databases with immigration and customs databases. Using all of this data, the Taiwanese Government could trace the 14-days travel histories and symptoms of its citizens. Further, international travelers were asked to scan a QR code. This redirected them to an online health declaration, which was used to provide contact information and symptoms. The US government is in active talks with Facebook, Google and a wide array of tech companies and health experts about how they can use location data gleaned from Americans’ phones to combat the novel coronavirus, including tracking whether people are keeping one another at safe distances to stem the outbreak. Public-health experts are interested in the possibility that private-sector companies could compile the data in anonymous, aggregated form, which they could then use to map the spread of the infection, according to three people familiar with the effort, who spoke on the condition of anonymity because the project is in its early stages.

Samsung Galaxy Tab 2 7.0 Review: A Low

The Galaxy Tab 2, in contrast, runs Android 4.0. That means it can handle standard Android phone and tablet apps in the Google Play store. It also offers features that neither the Kindle Fire nor the Nook Tablet does, such as an infrared port and a rear-facing camera. Samsung sacrificed built-in storage capacity (just 8GB, same as the other two value tablets and half of the 16GB provided on the Tab 7.0 Plus) to achieve the Tab 2’s low price, but that doesn’t detract from the Tab 2’s widespread appeal.

Galaxy Tab 2: Design and Performance

The Galaxy Tab 2 7.0 is an evolutionary step over the extremely similar Galaxy Tab 7.0 Plus. Both models weigh 0.76 pound, and they feature a similar design and build quality, plus similar dimensions. Both measure 4.8 by 7.6 inches, but the Tab 2 is slightly thicker at 0.41 inch, versus the 7.0 Plus’s 0.39 inch. The balance and weight are such that this tablet isn’t onerous to hold one-handed, though I’d like to see the weight become lighter still.

Only subtle tweaks distinguish the two. For example, the Tab 2’s plastic bezel curves around to the front of the screen, giving the front face of the tablet a pleasing look. The Tab 2 also has a larger infrared port, located at the top edge of the tablet when you’re holding the slate in landscape mode; the port now wraps around the back of the device, presumably to improve communications between the tablet and your entertainment components. The power button and volume rocker, positioned along that same edge, have a more rounded, easier-to-press shape. The MicroSD Card slot door is slightly (by millimeters) wider, too, and just a bit easier to open, but you’ll still need to do so using a fingernail. You can add up to 32GB of storage via MicroSD, a big benefit over the Kindle Fire, which lacks any expansion slot for local storage.

The back of the Tab 2’s case is a light, “titanium”-hued plastic, as opposed to the darker brushed gray of the earlier model. And although the rear camera is the same at 3 megapixels, the Tab 2 lacks the flash found on the 7.0 Plus.

The flash is just one thing that the Tab 2 sacrificed to achieve its low price. Inside, the Tab 2 has a 1GHz dual-core processor, down from the Galaxy Tab 7.0 Plus’s 1.2GHz dual-core processor. The processor change might account for why, in PCWorld Labs tests, the Tab 2 took 14 seconds longer to boot up than the Tab 7.0 Plus did; it also turned in a noticeably slower frame rate on the two GL Benchmark tests we run.

Samsung’s Plane to Line Switching (PLS) display is 1024 by 600 pixels, the same as on the Galaxy Tab 7.0 Plus before it. These days, this display is merely average, as several 7-inch tablets with 1200-by-800-pixel resolution are now available. I noticed that colors were slightly off on the Tab 2 compared with how they appeared on the older 7.0 Plus model; detail in images I viewed in the native Google Gallery app seemed slightly worse, too, although the tablets still scored closely on our subjective tests of the displays. I’m currently investigating this issue. Some of the differences may be attributable to the display itself, or they may have some foundation in how Google has changed Android’s image handling between Android 3.2 (which shipped on the Tab 7.0 Plus) and Android 4.0.3 (which ships on the Galaxy Tab 2).

As a bonus over its Kindle Fire and Nook Tablet competition, the Galaxy Tab 2 adds Bluetooth and GPS, too. Overall, the Tab 2 is ahead of the Kindle Fire and Nook Tablet when it comes to features.

Galaxy Tab 2: Software

In addition to the Samsung-branded apps, the Galaxy Tab 2 comes with a handful of useful Android apps preinstalled. Among them are Dropbox (with a year of 50GB Dropbox service included), the Peel Smart Remote app for use with the infrared port, and Polaris Office. The Peel app is a mixed bag, though: While it allows you to discover content visually, configuring the settings can be frustrating, and browsability could be improved. Ultimately, Samsung would do far better to write its own, more basic remote-control app, as Sony has done on its Tablet S.

If you own a Samsung Wi-Fi camera or HDTV, you may be able to benefit from some additional capabilities of the Tab 2 that tie in to Samsung’s product stable. Remote Viewfinder, which works with Samsung’s Wi-Fi cameras, could have some interesting applications for group photos, for example; with this capability, you can use Wi-Fi Direct to form a connection between the tablet and the camera, and together with an app on the tablet, you can then use the tablet to control the viewfinder, shutter, zoom, and flash of the camera. Meanwhile, Smart View lets you mirror content from your TV on the tablet, but this function works only with Samsung 7000 series LED HDTVs, circa 2011 and later.

Bottom Line

Even though the Samsung Galaxy Tab 2 7.0 has some nifty features like the infrared port and Wi-Fi Direct, it is neither a premium tablet nor a pure budget tablet. The big question is whether full Android compatibility and those extras are worth paying $50–or 25 percent–more than what you’d pay for an Amazon Kindle Fire or a Barnes & Noble Nook Tablet. The answer: A resounding yes, but with a catch.

How Block Works In Pl/Sql?

Definition of PL/SQL Block

Basically, PL/SQL contains the different blocks to write a code, in another word we can say that the PL/SQL code we cannot execute in a single, so we need a group of code for a single element that we called the block. Normally the block contains the SQL instructions as well as PL/SQL statements. The PL/SQL block structure is predefined and in which we need to write the code in different blocks. The PL/SQL consists of three different types of blocks such as the Declaration section, Execution section, and Exception handling section. As per requirement, we can include the header section into a PL/SQL.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

DECLARATION SECTION BEGIN EXCEPTION END;

Explanation

In the above syntax, we use three different sections: the declaration section, execution section, and exception handling section. In the first section we can declare variables, in the second section that begins or we can say that execution section, here we write the executable statement as per requirement and the last section contains the exception handling statement and again it depends on the user requirement.

How block works in PL/SQL?

Now let’s see how PL/SQL works as follows.

Basically, there are three different sections as follows.

1. Declaration section

This is the first section in the PL/SQL block and it is an optional part in PL/SQL block. In this section, we can declare the variables, exceptions, subprograms, cursor, collections, and different instructions as per the requirement. The declaration section has some important characteristics as follows.

This section is optional, and if no declarations are required, it can be omitted.

If a PL/SQL block is present, this should be the first part.

For triggers and anonymous blocks, this section begins with the term ‘DECLARE.’ This keyword will not be present in other subprograms. Instead, the declaration portion begins after the subprogram name definition.

The execution section should always come after this part.

2. Execution Section

This is the second section of the PL/SQL block; the execution section always starts with the BEGIN keyword and ends with the END keyword. In this block, we just need to write at least one executable expression even if it is null, which means it is a mandatory section of the PL/SQL block. Some important characteristics of the execution section are as follows.

• The ‘END’ or the Exception-Handling section should come after this section (if present)

3. Exceptional handling section

Now let’s see some important characteristics of the exception handling section as follows.

There is no reference name given for these blocks.

The term ‘DECLARE’ or ‘BEGIN’ is used to start these blocks.

These blocks can’t be saved for subsequent use since they don’t have a reference name. They must be designed and implemented in the same session.

It can include nested blocks that are either named or anonymous. It may be nested in any block as well.

These blocks can include all three components, with the execution portion being required and the other two sections being optional.

Basically, there are two types of Block in PL/SQL as follows.

1. Anonymous Block: in this block, there is no need to specify the name that means we need to create and use it in the same section as per requirement because an anonymous block is not stored on the server.

Examples

Now let’s see the different examples of a block in PL/SQL for better understanding as follows.

Let’s see a very simple example of a block in PL/SQL as follows.

SET SERVEROUTPUT ON; BEGIN DBMS_OUTPUT.put_line('Welcome in first PLSQL Block'); END; /

Explanation

In the above example, we start to write the block with the BEGIN keyword and end with the END keyword as shown in the above block. Inside the block, we write the statement that contains the execution section of the block. The DBMS_OUTPUT.put_line statement used as an output statement that means here we display the message by using this procedure and execution of block we use forward-slash (/) that instructs SQL * Plus to execute the block. The final output of the above block or procedure we illustrated by using the following screenshot as follows.

Let’s see another example as follows.

SET SERVEROUTPUT ON; DECLARE test VARCHAR2(200) := 'Welcome in PLSQL Block'; BEGIN DBMS_OUTPUT.put_line(test); END; /

In this example we include the declaration section as shown, here we declare the test variable with varchar2 data type and it contains a string message as shown in the above procedure. The remaining code of this example is the same as the above example. The final output of the above block or procedure we illustrated by using the following screenshot as follows.

Now let’s see how we can include the exception section in the procedure as follows.

SET SERVEROUTPUT ON; DECLARE val_e number; BEGIN val_e := 10/0; EXCEPTION when zero_divide then dbms_output.put_line('Divide by zero error'); END; /

Explanation

By using the above example we try to handle the exception in the block. In the execution section, we write the expression for the divide by zero exception with the EXCEPTION keyword as shown in the above example. After execution of this block, it shows a message like Divide by zero error. The final output of the above block or procedure we illustrated by using the following screenshot as follows.

Conclusion

We hope from this article you learn PL/SQL blocks. From the above article, we have learned the basic syntax of block and we also see different examples of the block. From this article, we learned how and when we use PL/SQL blocks.

Recommended Articles

We hope that this EDUCBA information on “PL/SQL Block” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Leveraging Sql Server 7.0 Stored Procedures on the Daihoichemgio.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!