永发信息网

sql的关键语法,,如创建 存储过程,触发器,等代码怎么写?

答案:3  悬赏:60  手机版
解决时间 2021-08-22 09:43
  • 提问者网友:我的未来我做主
  • 2021-08-22 00:23
不会 请高手指教
最佳答案
  • 五星知识达人网友:摆渡翁
  • 2021-08-22 00:35
我给你一个简单的CREATE OR REPLACE PROCEDURE PRO_TEACHERS (NAME IN VARCHAR2,CLASS IN VARCHAR2,TYPE IN NUMBER) AS BEGIN INSERT INTO TEACHERS VALUES(SE_TEACHERS.NEXTVAL,NAME,CLASS,TYPE); END; / EXEC PRO_TEACHERS('大家好','耍耍课',2); 这是一个简单的存储过程 在一个触发器这个问题你就直接进我们寝室来救ok了撒
全部回答
  • 1楼网友:鱼芗
  • 2021-08-22 01:05

我就把上面的写的解释一片给你听:

存储过程:DELIMITER $$

DROp PROCEDURE IF EXISTS `shopping`.`getfreight`$$    //如果存在存储过程shopping`.`getfreight就删除

CREATE PROCEDURE `shopping`.`getfreight`(INorderitemsid int)  //创建存储过程shopping`.`getfreight

    BEGIN
 DECLARE productid int;  //DECLARE 关键声明变量
DECLARE number int;
DECLARE weight double;
DECLARE price double; 
DECLARE freightmoney double;
DECLARE freightmeikg double;

    select goodsid into productid from orderformitems where orderformitemsid=INorderitemsid;

    select goodsnumber into number from orderformitems where orderformitemsid=INorderitemsid;

    select freighteverykg into freightmeikg from orderformitems where orderformitemsid=INorderitemsid;
    
    select goodsweight into weight from goods where goodsid=productid;
    
    select goodsprice into price from goods where goodsid=productid;  
    
    update orderformitems set freight=number*weight*freightmeikg where orderformitemsid=INorderitemsid;

    select freight into freightmoney from orderformitems where orderformitemsid=INorderitemsid;
    
    update orderformitems set goodsallprice=number*price+freightmoney where orderformitemsid=INorderitemsid;

//上面都是一些sql语句....
END$$

DELIMITER ;

触发器:

DELIMITER $$

//如果存在触发器shopping`.`deleteorderformitemstrigger就删除

DROP TRIGGER `shopping`.`deleteorderformitemstrigger`$$

//TRIGGER 关键字创建触发器,他这里创建的是删除的触发器

CREATE TRIGGER `shopping`.`deleteorderformitemstrigger` AFTER DELETE on `shopping`.`orderform`
FOR EACH ROW BEGIN
 delete from orderformitems where orderformid=old.orderformid;
 delete from orderformindex where orderformid=old.orderformid;
END$$

DELIMITER ;

  • 2楼网友:过活
  • 2021-08-22 00:45

存储过程:DELIMITER $$

DROp PROCEDURE IF EXISTS `shopping`.`getfreight`$$

CREATE PROCEDURE `shopping`.`getfreight`(INorderitemsid int)

    BEGIN  DECLARE productid int; DECLARE number int; DECLARE weight double; DECLARE price double;  DECLARE freightmoney double; DECLARE freightmeikg double;

    select goodsid into productid from orderformitems where orderformitemsid=INorderitemsid;

    select goodsnumber into number from orderformitems where orderformitemsid=INorderitemsid;

    select freighteverykg into freightmeikg from orderformitems where orderformitemsid=INorderitemsid;          select goodsweight into weight from goods where goodsid=productid;          select goodsprice into price from goods where goodsid=productid;            update orderformitems set freight=number*weight*freightmeikg where orderformitemsid=INorderitemsid;

    select freight into freightmoney from orderformitems where orderformitemsid=INorderitemsid;          update orderformitems set goodsallprice=number*price+freightmoney where orderformitemsid=INorderitemsid; END$$

DELIMITER ;

触发器:

DELIMITER $$

DROP TRIGGER `shopping`.`deleteorderformitemstrigger`$$

CREATE TRIGGER `shopping`.`deleteorderformitemstrigger` AFTER DELETE on `shopping`.`orderform` FOR EACH ROW BEGIN  delete from orderformitems where orderformid=old.orderformid;  delete from orderformindex where orderformid=old.orderformid; END$$

DELIMITER ;

以上是我做的一个项目的存储过程与触发器的书写,希望对你有帮助

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯