English 中文(简体)
PL/SQL 非现有增长的最新情况/删除的例外
原标题:PL/SQL Exceptions on Update/Delete of non-existing row
  • 时间:2012-01-12 20:33:44
  •  标签:
  • oracle
  • plsql

我正在学习PL/SQL这些日子,目前正在使用人权专册的程序与例外。

这里是我的简单程序。

create or replace
PROCEDURE DEL_JOB
(p_jobid jobs.job_id%TYPE)
AS 
sqle NUMBER; 
sqlm VARCHAR2(300);
BEGIN
DELETE FROM JOBS 
WHERE JOB_ID = UPPER(p_jobid);
IF SQL%NOTFOUND THEN
  DBMS_OUTPUT.PUT_LINE( No such record );
END IF;
EXCEPTION
 WHEN OTHERS THEN
  sqle := SQLCODE;
  sqlm := SQLERRM;
  DBMS_OUTPUT.PUT_LINE( There is no job with this id that could be deleted );
  DBMS_OUTPUT.PUT_LINE( Error Code = ||sqle||  Error message =  ||sqlm);
END;

当我执行这一程序时,产出是

  No such record
  PL/SQL procedure successfully complete. 

然而,根据Oracle PDF,它应当放弃一个例外,我应该真正获得我作为例外所传递的信息。

Same thing happened with the Update on non existing record. Please advise. Thanks

最佳回答

页: 1 没有记录。 您的<代码>IF将对这一案例作出评价,并因此写上您的行文。 卡福尔克声明成功执行。 如果你自己从指挥线执行该表,你将获得更新/删除的0行,而不是甲骨质的错误。

如果你想要放弃一个例外,请在您的<条码>内使用,并注明你想要投的例外情况。

问题回答

There is no "exception" - the sql executed successfully. It successfully deleted every record that matched the criteria...which was 0 records. Same thing if a similar update statement was executed. You used the SQL%NOTFOUND to determine there were no records that were affected, but this does not mean there was an "exception".

也许,你会重新思考一下N_DATA_FOUND 如果你尝试“选择”条款,则提出例外,没有找到任何对应的记录。

为此,你需要使用

IF SQL%ROWCOUNT = 0 THEN
    RAISE no_delete;
END IF;

目 录





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签