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

How to execute this Stored Procedure in oracle?

   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;

试试这个

Procedure has not return value, if you need you can use function

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

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

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

定义游标绑定变量,然后将过程调用包装在匿名 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;