SQL Server Functions

Source: Internet
Author: User

Create table student (id varchar2 (5) primary key, name varchar2 (20) not null, sex char (2) check (sex = 'male' or sex = 'female ')) -- insert a piece of data into student and use a function to verify whether the insertion is correct. create or replace function student_insert_check (f_id in varchar2, f_name in varchar2, sex in varchar2) return varchar2 isc_id number; beginif f_id is null thenreturn ('student ID cannot be blank, records are not inserted successfully '); end if; if f_name is null return ('name cannot be blank, the record is not inserted successfully. '); end if; if sex! = 'Male' or sex! = 'Femal' return ('gender is limited to male or female, records are not inserted successfully. ') end if; insert into student values (f_id, f_name, sex); commit; -- SQL control transaction: The commit command is used to save the modifications made by the transaction to the database. It saves all the transactions after the previous COMMIT or ROLLBACK command to the database. Return ('record inserted successfully'); end dd; ========================================================== ========================================================== = create function average1 (@ cnum char (20 )) -- create a returns int function with parameters -- return an integer of the int type as begin declare @ aver int -- declare a @ aver variable select @ aver = -- query this variable (-- variable assignment select AVG (score) from xs_kc where course No. = @ cnumgroup by course No.) return @ aver -- return variable end go select dbo. average1 (101) -- use the previously created function average1

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.