First contact with Oracle stored procedures

Source: Internet
Author: User
Tags stored procedure example

CREATE TABLE STUDENT (
ID Number (Ten) is not NULL,
NAME VARCHAR2 (10),
SEX CHAR (1),
Age Number (3),
CreationDate DATE,
MODIFIEDDATE DATE,
PRIMARY KEY (ID));

--Querying data
SELECT * from student;



--Inserting data
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107001, ' Liu ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107002, ' Jack ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107003, ' Robin ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107004, ' fuck ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107005, ' Duck ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107006, ' God ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107007, ' Dog ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107008, ' Bike ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107009, ' Ella ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107010, ' make ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107011, ' Cela ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107012, ' MeLe ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107013, ' look ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107014, ' Jack ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107015, ' Ekk ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));
INSERT into student (id,name,sex,age,creationdate,modifieddate)
VALUES (7023107016, ' Jack ', ' B ', 19,to_date (' 20160322 ', ' YYMMDD '), to_date (' 20160322 ', ' YYMMDD '));

SELECT * from User_procedures where procedure_name= ' pro_student ';

--Stored Procedure example (total number of students calculated)

CREATE OR REPLACE PROCEDURE pro_student
As
S_total number (10);
BEGIN
SELECT COUNT (*) into s_total from STUDENT;
Dbms_output. Put_Line (' Number of students: ' | | S_total);
END;

EXECUTE pro_student;

--statistics on the number of girls (with input parameters)
--Note that variable definitions cannot be the same as variables in a table
CREATE OR REPLACE PROCEDURE pro_girl_student (student_sex in CHAR)
As
S_total number (10);
BEGIN
SELECT COUNT (*) into s_total from STUDENT S WHERE s.sex=student_sex;
Dbms_output. Put_Line (' Number of students: ' | | S_total);
END;

EXECUTE pro_student;

First contact with Oracle stored procedures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.