温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

第一次接触Oracle存储过程

发布时间:2020-06-17 18:15:18 来源:网络 阅读:462 作者:flyinglxr 栏目:关系型数据库

CREATE TABLE STUDENT(
    ID NUMBER(10)  NOT NULL ,
    NAME VARCHAR2(10) ,
    SEX CHAR(1),
    AGE Number(3),
    CREATIONDATE  DATE,
    MODIFIEDDATE DATE,
    PRIMARY KEY (ID));
    
 --查询数据
select * from student;



 --插入数据
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';  

--存储过程例子(计算学生总人数)

    CREATE OR REPLACE PROCEDURE PRO_STUDENT   
    AS  
    S_TOTAL NUMBER(10);   
    BEGIN  
     SELECT COUNT(*) INTO S_TOTAL FROM STUDENT;   
     DBMS_OUTPUT.PUT_LINE('学生人数:'||S_TOTAL);   
    END;  
    
    EXECUTE PRO_STUDENT;  

--统计女孩人数(带输入参数)
     --注意变量定义不能与表中变量相同
    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('学生人数:'||S_TOTAL);   
    END;  
    
    EXECUTE PRO_STUDENT;  
   

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI