表a:
PROTOCOL VARCHAR2(20)
表b:
YEAR NUMBER(4)
MONTH VARCHAR2(20)
PROTOCOL VARCHAR2(20)
DATE1 DATE
我的程序代码:
CREATE PROCEDURE his
@Year NUMBER(4),
@Month VARCHAR2(20)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRANSACTION trninsert
DECLARE @@date DATE
SET @@date = sysdate;
INSERT INTO b (Year, month, date1, protocol)
(select @Year, @Month, @@date,* from a)
COMMIT TRANSACTION trninsert
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION trninsert
END CATCH
END
我正在使用plsql开发人员,它在程序中显示错误。
答案 0 :(得分:3)
你已经写了这个mysql类型的语法。
oracle将是:CREATE PROCEDURE his(p_year b.year%type,
p_month b.month%type)
AS
BEGIN
INSERT INTO b (Year, month, date1, protocol)
select p_year, p_month, sysdate, a.protocol
from a;
commit;
END;
虽然它在程序中提交的形式不好。
例如:
SQL> CREATE PROCEDURE his(p_year b.year%type,
2 p_month b.month%type)
3 AS
4 BEGIN
5 INSERT INTO b (Year, month, date1, protocol)
6 select p_year, p_month, sysdate, a.protocol
7 from a;
8 commit;
9 END;
10 /
Procedure created.
SQL> insert into a values('prot a');
1 row created.
SQL> exec his(2012, 10)
PL/SQL procedure successfully completed.
SQL> select * from b;
YEAR MONTH PROTOCOL DATE1
---------- -------------------- -------------------- ---------
2012 10 prot a 06-FEB-13
SQL>
答案 1 :(得分:0)
您的程序格式无效:使用
更改整个结构 CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
有关更多参数:点击here
答案 2 :(得分:0)
是的,你还没有使用plsql语法:
代码将是:
CREATE OR REPLACE PROCEDURE his
(Year b.year%type,
Month b.month%type)
AS
BEGIN
INSERT INTO b (Year, month, date1, protocol)
VALUES select Year, Month, sysdate,a.protocol from a ;
COMMIT;
END;