这是我的oracle存储过程。我想将数据传递给过程时删除某些id,但是当我执行此过程时。我删除了我的trable所拥有的一切。
有人可以查看吗
CREATE OR REPLACE PROCEDURE Delete(
id IN number)
AS
BEGIN
DELETE FROM Users WHERE Users.id_user= id;
END;
/
我试图把:
DELETE FROM Users WHERE Users.id_user == id;
然后我收到编译错误。
答案 0 :(得分:1)
你试过DELETE FROM Users WHERE id_user = id;
吗?
使用==
不是用于等式检查的有效SQL。
我仍然不明白为什么要删除所有行。 DELETE FROM Users WHERE Users.id_user = id
应该正常工作。
有关DELETE STATEMENT语法的更多信息。
答案 1 :(得分:1)
我有同样的问题。当我传递表中不存在的Id时,一切都会被删除。
如果表中存在id,则该过程将按照我希望它运行的方式运行。
PROCEDURE tests
( jobnr IN varchar2,
x IN number,
menu in varchar2 default '1')
IS
counter number := 0;
BEGIN
delete from table_test where jobnr = jobnr;
if sql%notfound or sql%rowcount=0 then
rollback;
end if;
WHILE counter < x
LOOP
insert into table_test ( cskey, telnr, seq, jobnr, menu ) values ('Test'||counter, counter, counter, jobnr, menu );
counter := counter + 1;
END LOOP;
commit;
END;
答案 2 :(得分:1)
尝试以下操作:将输入存储到本地变量中,然后在查询中使用此变量。这对我有用。
CREATE OR REPLACE PROCEDURE Delete(
id IN number)
AS
v_id Number;
BEGIN
v_id := id;
DELETE FROM Users WHERE Users.id_user= v_id;
END;
答案 3 :(得分:0)
CREATE TABLE USERS(ID NUMBER);
TABLE CREATED.
CREATE OR REPLACE PROCEDURE DeleteIDS(
id IN number)
AS
BEGIN
DELETE FROM Users WHERE id= id;
END;
/
PROCEDURE CREATED.
此处,在表中,用户ID存在,如果在过程声明中指定了id,则该过程将删除所有数据。 所以,
CREATE OR REPLACE PROCEDURE DeleteIDS(
idS IN number)
AS
BEGIN
DELETE FROM Users WHERE id= idS;
END;
/
PROCEDURE CREATED.
现在,
INSERT INTO USERS VALUES(10);
1 ROW INSERTED.
INSERT INTO USER VALUES(20);
1 ROW INSERTED.
COMMIT;
现在,执行程序
SQL>EXEC DELETEIDS(10);
PL/SQL PROGRAM SUCCESSFULLY COMPLETED.
SELECT * FROM USERS;
ID
---
2