Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. CREATE TABLE EMPLOYEE
  2. (
  3. "EMPLOYEE_NUMBER" VARCHAR2(20 BYTE),
  4. "EMPLOYEE_NAME" VARCHAR2(80 BYTE),
  5. "EMPLOYEE_DEPT" VARCHAR2(40 BYTE)
  6. );
  7.  
  8. create or replace PACKAGE PKG_SP_EMPLOYEE
  9. AS
  10. TYPE tbl_employees_in
  11. IS
  12. TABLE OF EMPLOYEE%ROWTYPE INDEX BY PLS_INTEGER;
  13.  
  14. PROCEDURE main(
  15. p_employee IN PKG_SP_EMPLOYEE.tbl_employees_in,
  16. x_status OUT VARCHAR
  17. );
  18. END PKG_SP_EMPLOYEE;
  19.  
  20. create or replace PACKAGE BODY PKG_SP_EMPLOYEE
  21. AS
  22.  
  23. PROCEDURE main(
  24. p_employee IN PKG_SP_EMPLOYEE.tbl_employees_in,
  25. x_status OUT VARCHAR
  26. )
  27. IS
  28. BEGIN
  29. FOR i in 1..p_employee.count
  30.  
  31. loop
  32. INSERT INTO "EMPLOYEE"
  33. (
  34. EMPLOYEE_NUMBER,
  35. EMPLOYEE_NAME,
  36. EMPLOYEE_DEPT
  37. )
  38. VALUES (
  39. p_employee(i).EMPLOYEE_NUMBER,
  40. p_employee(i).EMPLOYEE_NAME,
  41. p_employee(i).EMPLOYEE_DEPT
  42. );
  43.  
  44. end loop;
  45.  
  46. dbms_output.put_line('Success');
  47. x_status := 'Success';
  48.  
  49. EXCEPTION
  50. WHEN OTHERS THEN
  51. dbms_output.put_line('Failure');
  52. x_status := 'Failure';
  53.  
  54. END main;
  55. END PKG_SP_EMPLOYEE;
  56.  
  57. Connection con= null;
  58. OracleCallableStatement cstmt = null;
  59.  
  60. try {
  61.  
  62. Class.forName("oracle.jdbc.driver.OracleDriver");
  63. con=DriverManager.getConnection("jdbc:oracle:thin:@test.com:1521:TESTAD",
  64. "user","password");
  65.  
  66. cstmt = (OracleCallableStatement)con.prepareCall (
  67. "begin PKG_SP_EMPLOYEE.MAIN (?,?); end;");
  68.  
  69. String[] values = { "1", "John Doe", "HR" };
  70.  
  71. cstmt.setPlsqlIndexTable (1, values, values.length, values.length, OracleTypes.VARCHAR, 3);
  72.  
  73. cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
  74.  
  75. cstmt.execute ();
  76.  
  77. //...
  78.  
  79. java.sql.SQLException: ORA-06550: line 1, column 7:
  80. PLS-00306: wrong number or types of arguments in call to 'MAIN'
  81. ORA-06550: line 1, column 43:
  82. **PLS-00418: array bind type must match PL/SQL table row type**
  83. ORA-06550: line 1, column 7:
  84. PL/SQL: Statement ignored
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement