如何在oracle中执行此存储过程?

时间:2017-06-19 07:31:25

标签: oracle stored-procedures exec calling-convention

   EXEC USP_USER_INSERT (P_ID = '2', P_FIRST_NAME = 'A', P_LAST_NAME = 'BALAJI', P_SALARY = '50000', P_CITY = 'CHENNAI');

EXEC USP_USER_INSERT @P_ID = '2', @P_FIRST_NAME = 'A', @P_LAST_NAME = 'BALAJI', @P_SALARY = '50000', @P_CITY = 'CHENNAI';

Both are showing error, how to call this SP.








create or replace procedure USP_USER_INSERT 
    ( 
      P_FIRST_NAME in varchar default null,
      P_LAST_NAME  in varchar default null, 
      P_SALARY   in   number default null, 
      P_CITY      in  varchar default null, 
      P_EMAIL_ID  in  varchar default null, 
      P_EMP_ID   in   number default null, 
      P_ADDED_BY  in  number default null, 
      P_WINDOWS_ID in varchar2 default null, 
      P_USER_TYPE  in number default null, 
      P_PASSWORD  in  varchar2 default null, 
      P_ROLE     in   varchar2 default null,
      RES OUT SYS_REFCURSOR
    ) 
    as 
    P_ID NUMBER;
      begin 

      select NVL(max(ID),0)+1 into P_ID from USER_MASTER ;

          insert into USER_MASTER 
                      (
                        ID,FIRST_NAME, 
                        LAST_NAME, 
                        SALARY, 
                        CITY, 
                        EMAIL_ID, 
                        EMP_ID, 
                        ADDED_ON, 
                        ADDED_BY, 
                        WINDOWS_ID, 
                        IS_ACTIVE, 
                        USER_TYPE, 
                        PASSWORD, 
                        role
                       ) 
          values      ( 
                        P_ID,P_FIRST_NAME, 
                        P_LAST_NAME, 
                        P_SALARY, 
                        P_CITY, 
                        P_EMAIL_ID, 
                        P_EMP_ID, 
                        Systimestamp, 
                        P_ADDED_BY, 
                        P_WINDOWS_ID, 
                        1, 
                        P_USER_TYPE, 
                        P_PASSWORD, 
                        P_ROLE
                      );

      open RES for
      SELECT P_ID "P_ID" FROM DUAL;                    

      END;

3 个答案:

答案 0 :(得分:0)

试试这个

  

程序没有返回值,如果需要,可以使用函数

exec USP_USER_INSERT ( par1,par2,....)

答案 1 :(得分:0)

如果你在命令行上运行它,你应该/在sql代码的末尾。

尝试使用单引号,如果2是varchar,则保持原样, EXEC USP_USER_INSERT'2','A','BALAJI','50000','CHENNAI'

答案 2 :(得分:0)

定义游标绑定变量,然后将过程调用包装在匿名PL / SQL块中:

VARIABLE cur REFCURSOR;

BEGIN
  USP_USER_INSERT (
    P_EMP_ID     => '2',      -- P_ID is not an argument to the procedure
    P_FIRST_NAME => 'A',
    P_LAST_NAME  => 'BALAJI',
    P_SALARY     => '50000',
    P_CITY       => 'CHENNAI',
    RES          => :cur
  );
END;
/

PRINT cur;