Oracle Custom Functions

Source: Internet
Author: User

CREATE TABLE STUDENT (--Creating student tables
ID Number (TEN) PRIMARY key,--primary Key ID
SNAME VARCHAR2 (20),
CLASSNAME VARCHAR2 (20)--Class
);

INSERT into STUDENT VALUES (1, ' Tom ', ' Svse ');
INSERT into STUDENT VALUES (2, ' Jack ', ' GIS ');
INSERT into STUDENT VALUES (3, ' Bay ', ' 3G ');
INSERT into STUDENT VALUES (4, ' John ', ' Svse ');
INSERT into STUDENT VALUES (5, ' Dld ', ' 3G ');

--Create function return total number of 3G classes

CREATE OR REPLACE FUNCTION fun_num
(In_cname in Classtab. Cname%type)--parameters received by the function
Return number each function must return a value
As
Out_num number; --Define the returned variable Out_num receive the value of the query
BEGIN
IF in_cname = ' 3G ' Then
SELECT COUNT (CNAME) into Out_num from STUDENT WHERE cname= ' 3G ';
elsif in_cname= ' Svse ' then
SELECT COUNT (CNAME) into Out_num from STUDENT WHERE cname= ' Svse ';
ELSE in_cname = ' GIS ' Then
SELECT COUNT (CNAME) into Out_num from STUDENT WHERE cname= ' GIS ';
END IF; --End condition
RETURN Out_num; Return the value out
End fun_num;--function
--Call function
SELECT DISTINCT fun_num (' 3G ') as number from STUDENT;

Oracle Custom Functions

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.