我想在另一个表中插入记录,从另一个表中添加额外的参数。以下是表
我想将project_access作为用户名作为param插入,将Project访问作为硬代码值插入" Y"并从项目表中休息所有值。我是sql的新手。 有人可以帮助我
在项目访问中 User_ID-应该是程序的参数 Project_object_id作为项目ID或项目表 Project_access_id由序列生成 所有行中的Project_access为Y. 项目名称应为项目的项目名称。
答案 0 :(得分:1)
您可能需要以下内容:
insert into tableTarget( column1, column2, column3)
select column1, column2, 'hardcoded value'
from tableSource
在程序中:
create or replace procedure yourProc(x in number) as
begin
insert into tableTarget( column1, column2, column3)
select column1, column2, x
from tableSource;
end;
答案 1 :(得分:0)
CREATE OR REPLACE PROCEDURE grantUserProjectAccess(
in_user_id IN PROJECT_ACCESS.USER_ID%TYPE,
in_project_object_id IN PROJECT_ACCESS.PROJECT_OBJECT_ID%TYPE,
out_error OUT VARCHAR2
)
AS
v_project_name PROJECT_ACCESS.PROJECT_NAME%TYPE;
BEGIN
SELECT project_name
INTO v_project_name
FROM project
WHERE project_object_id = in_project_object_id;
INSERT INTO project_access (
user_id,
project_object_id,
project_access_id,
project_access,
project_name
) VALUES (
in_user_id,
in_project_object_id,
PROJECT_ACCESS_SEQ.NEXTVAL,
'Y',
v_project_name
);
out_error := NULL;
EXCEPTION
WHEN NO_DATA_FOUND THEN
out_error := 'Project Not Found';
WHEN DUP_VAL_ON_INDEX THEN
out_error := 'Duplicate Entry';
END;
/
(注意:除非你有充分的理由,否则不要在程序内部调用commit - 在最外面的块中调用数据来调用该过程 - 这将允许您嵌入对过程的调用,并在必要时发出一个关于整个过程序列的ROLLBACK
。如果您只想进行部分回滚,请考虑使用SAVEPOINT
s。)