0 0

trigger issue5

trigger codes:
  create or replace trigger limitinsertbefor
  before insert on student 
  for each row
  when((sysdate-old.birthday)/365<18)
  begin
       insert into trigger_table values('update',:old.studentid,:new.studentid,sysdate,'student');
  end limittinsertbefor;


// Table student structure
    Name        Type         Nullable Default Comments
    ----------- ------------ -------- ------- --------
    STUDENTID   VARCHAR2(8)                           
    STUDENTNAME VARCHAR2(8)                           
    BIRTHDAY    DATE         Y                        
    CLASSID     VARCHAR2(12) Y

execution statement;
  insert into student values('20053822','lanlan',to_date('19860825','yyyyhhdd'),'201001');
ERROR CODE:
  ORA-00932: inconsistent datatypes: expected NUMBER got DATE

But if i get rid of this condition:when((sysdate-old.birthday)/365<18) this execution statement will run succeed.

Maybe this condition which when((sysdate-old.birthday)/365<18) doesn't work. but i can't find reason about this issue .

feel free pls help me ! thans

i very sorry that i don't have enough score with me so that i can't prove more score for this question.

SORRY!!!


 

问题补充:谢谢你的答案,很满意。

But:

select sysdate-to_date('19861103','yyyymmdd') from dual;

SYSDATE-TO_DATE('19861103','YY
------------------------------
              8544.41739583333


上面是一个日期型-日期型,但是结果不是数字型吗.

thanks .


问题补充:
suziwen 写道


这样写

create or replace trigger limitinsertbefor 
  before insert on student  
  for each row 
  when((to_number(sysdate-new.birthday))/365<18) 
  begin 
       insert into trigger_table values('update',:old.studentid,:new.studentid,sysdate,'student'); 
  end limittinsertbefor; 

  insert into student values('20052422','lanlan',to_date('19960825','yyyyMMdd'),'201001'); 


日期相减后还是日期型,不能直接跟数字操作,得先转换成数字型

你代码里的when((sysdate-old.birthday)/365<18)
old.birthday应该是new.birthday
因为是插入的数据,没有老数据


insert into student values('20053822','lanlan',to_date('19860825','yyyyhhdd'),'201001');
里的yyyyhhdd应该为yyyyMMdd





谢谢你的答案,很满意。

But:

select sysdate-to_date('19861103','yyyymmdd') from dual;

SYSDATE-TO_DATE('19861103','YY
------------------------------
              8544.41739583333


上面是一个日期型-日期型,但是结果不是数字型吗.

thanks .
2010年3月25日 17:38

1个答案 按时间排序 按投票排序

0 0

采纳的答案



这样写

create or replace trigger limitinsertbefor 
  before insert on student  
  for each row 
  when((to_number(sysdate-new.birthday))/365<18) 
  begin 
       insert into trigger_table values('update',:old.studentid,:new.studentid,sysdate,'student'); 
  end limittinsertbefor; 

  insert into student values('20052422','lanlan',to_date('19960825','yyyyMMdd'),'201001'); 


日期相减后还是日期型,不能直接跟数字操作,得先转换成数字型

你代码里的when((sysdate-old.birthday)/365<18)
old.birthday应该是new.birthday
因为是插入的数据,没有老数据


insert into student values('20053822','lanlan',to_date('19860825','yyyyhhdd'),'201001');
里的yyyyhhdd应该为yyyyMMdd

2010年3月25日 21:56

相关推荐

    非常牛的Oracle数据库基础知识 ISSUE1.0

    4. **触发器(Trigger)**:在特定数据库事件发生时自动执行的PL/SQL代码。 5. **存储过程(Stored Procedure)**:预编译的PL/SQL代码块,可以封装复杂的业务逻辑并多次调用。 接下来,我们会学习如何使用SQL语句...

    jira-trigger-plugin:在JIRA中满足特定条件时触发构建

    JIRA触发插件 该插件通过。 请考虑为该项目加注星标以显示您的 :red_heart: 和支持。特征 将注释添加到JIRA时触发构建 在JIRA中更新问题时触发构建 将JIRA Webhook POST数据转换为Jenkins参数 将JIRA标准自定义字段...

    VTreeView 2014-02-09 v5.3.0

    - Fixed issue #401: OnNodeClick event doesn't trigger in some case, coFixed set for a column - Modified #316 (concerning r498). The fix for #316 will only be applied in case toMultiSelect is set. If ...

    微软内部资料-SQL性能优化3

    Contents Overview 1 Lesson 1: Concepts – Locks and Lock Manager 3 Lesson 2: Concepts – Batch and Transaction 31 Lesson 3: Concepts – Locks and Applications 51 Lesson 4: Information Collection and ...

    SQL Prompt_9.1.4.4532破解版

    SP-6675, SP-6851 : Fixed out of memory exception that could trigger when processing table hints. SP-6707 : Rule ST002 no longer detects issue on column_alias=expression syntax. SP-6847 : Added support...

    Notepad++ v6.7.5最新版20150326

    3. Fix the crash issue while user Ctrl + double click on an empty document. 4. Fix crash bug on loading dropbox settings. 5. Show progress window instead of a static window during FindInFiles and ...

    Jenkins 与GitLiab 集成Jira操作手册_20200903_v01.docx

    - **JIRA Trigger Plugin** - **JiraTestResultReporter plugin** 其中,仅需安装基础的JIRA和JIRA Pipeline Steps插件,即可实现Jenkins向Jira同步comment信息。 2. **系统管理员配置** 管理员需在Jenkins的...

    pr-comment-github-deployment:Github Action用PR注释触发GitHub部署

    on : issue_comment jobs : deploy : steps : - uses : alexjurkiewicz/pr-comment-github-deployment@master env : GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} 参量 参数 需要 描述 trigger_phrase 可选的...

    en.X-CUBE-MCSDK-FUL_5.5.1-5.Y.1.zip

    Running the motor in the negative direction on STM32F0 based designs with 1 shunt and Hall sensor configuration may trigger an overcurrent error. Fixed an issue found on ESC G4 and F3 inverter boards...

    Sublime.Text.Build.3078._Win_32bit破解主文件

    Build Systems: Renamed "keyfile" to "keyfiles", now accepting a list of files that can trigger the build system (e.g., ["Makefile", "makefile"]) Improved change detection for files that disappear and ...

    IBO v5.3.3 Build 1955(January 2, 2014) Full Source

    This may cause some extra overhead depending upon what you are trying to do but it should be negligable since during the execution of a script there isn't anything going on that will trigger repeated...

    英语写作同义词替换练习.doc

    3. **放入议程**:如果要表示某事被提上日程,可以使用"be put on the agenda",而"trigger"、"spark"、"arouse"等动词则表示引起或启动了某种讨论或行动。 4. **广泛的关注**:"arouse people’s wide concern"或...

    大学四六级写作30个最经典的替换词

    20. cause的替换词有give rise to、lead to、result in或trigger,如:"Air pollution gives rise to respiratory problems." 21. 解释原因时,"There are several reasons behind sth" 可以替代 "reasons for sth...

    基于python的开放领域事件抽取系统源码数据库论文.doc

    This choice ensures flexibility for future upgrades or issue resolution, considering Python's open-source nature. Moreover, the backend management adopts a client-server (B/S) architecture, allowing ...

    浅谈新能源汽车实训教学过程的安全控制.pdf

    However, due to differences in power systems and electrical systems compared to conventional cars, ensuring safety during practical training is a crucial issue. 1. Hazards in New Energy Automotive ...

    CE中文版-启点CE过NP中文.exe

    Fixed issue where memory blocks would get cut of before the page end Fixed some memory leaks Fixed some graphical issues in the addresslist Fixed rightclick on r8 and r9 in memoryview Fixed ...

    Android10自动连接WiFi问题的解决

    To solve the automatic WiFi connection problem in Android 10, we need to use the new `WifiNetworkSpecifier.Builder` class to build a `WifiNetworkSpecifier` object, which can be used to trigger a ...

Global site tag (gtag.js) - Google Analytics