Learning Series
Home Database Learn SQL

SQL Programming

Category: SQL | Comments (1)

SQL Programming

Page 1 of 2

SQL Programming Overview

Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s algebra curriculum. SQL lets you change how things work, too, with stored procedures.


Essentially, a procedure is a set of instructions used to carry out some specific task. The SQL CREATE FUNCTION instruction allows a database user to create a procedure (also called a function, a user-defined function (UDF), or a routine). While developing functions, the CREATE FUNCTION instruction is used as CREATE OR REPLACE FUNCTION, to prevent the “function already exists” error from appearing. Further, ALTER FUNCTION is used to modify a function, and DROP FUNCTION is used to remove a function.


Perhaps the most popular SQL programming language (sometimes called a procedural extension) is PL/SQL, a language developed by and proprietary to Oracle. PostgreSQL has a similar language called PL/pgSQL, and Sybase and Microsoft SQL Server have Transact-SQL. MySQL also has a procedural SQL language, but it does not have a specific name. Other, similar extensions exist for most modern SQL databases.


In this article, we explore the fundamentals of the procedural languages of PostgreSQL, MySQL, and Oracle.


“Hello, World!”


Every concerted programming effort traditionally starts with the “Hello, World!” program. Originally conceived in an internal Bell Laboratories memorandum by Brian Kernighan, “Hello, World!” has become a customary way to begin one’s adventure into a new programming language. Figure 1 shows the creation and execution of “Hello, World!” in PostgreSQL’s PL/pgSQL language.



 


The natural thing to do now is dissect the procedure and explain its constituent parts.


Next Page: Function Creation and Execution


Next: SQL Functions


Comments

select Name_first, Name_last, sum (qty), sum (value) from Details1 where purpose="New Sale" and value<>0 group by product order by product;


Can i run this code
Comment posted by: krishan on 2008-08-11T05:49:49
I want to learn SQL programming
Comment posted by: taiwo abiola on 2008-08-01T14:22:50


Post Comment


Members Please Login

Name:


Email:
 
(Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)
Subscribe





Google Sponsored Links

 

Daily Email Updates

Get Latest Learning Series Updates delivered directly to your Inbox...

Enter your email address:

Latest Learning Series Updates

Learn SQL Tutorials

Related Tutorials