代码之家  ›  专栏  ›  技术社区  ›  Miguel NoTeimporta

ORA-29531:没有方法%s(在类%s中)调用oracle PLSQL中的java源

  •  1
  • Miguel NoTeimporta  · 技术社区  · 6 年前

    我在PLSQL中的代码如下:

        CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "ConversorSQL" AS
      package test;
      import java.util.Calendar;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
    
      import java.io.FileReader;
      import java.io.IOException;
    
      public class ConversorSQL {  
        public static String runConversor(String tipoOperacion, String nombreTabla, String queryOpcional) {
          return "Hola";
        }
      }
    

    然后:

    CREATE OR REPLACE FUNCTION f_conversorSQL(p_tipo VARCHAR2,
                                          p_tabla VARCHAR2,
                                          p_query VARCHAR2) RETURN VARCHAR2 IS LANGUAGE JAVA NAME 'test.ConversorSQL.runConversor(String, String, String) return String';
    

      SELECT f_conversorSQL( 'Hello there!',
                           'General Kenobi',
                           'You are a bold one')
     FROM DUAL;
    

    我得到了标题中的错误:

    Error que empieza en la línea 1 del comando:
    SELECT f_conversorSQL( 'Hello there!',
                           'General Kenobi',
                           'You are a bold one')
    FROM DUAL;
    Informe de error -
    Error SQL: ORA-29531: ningún método runConversor en la clase ConversorSQL
    29531. 00000 - "no method %s in class %s"
    *Cause: An attempt was made to execute a non_existent method in a Java class.
    *Action: Adjust the call or créate the specified method.
    

    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "JavaDate" AS
      package pruebas;
      import java.util.Calendar;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Statement;
    
      import java.io.FileReader;
      import java.io.IOException;
    
      public class JavaDate {  
        public static String getString(int anho, int mes, int dia, int hora, int minuto, int segundo) {
          return "hola";
        }
      }
    

    同上:

        CREATE OR REPLACE FUNCTION f_javadate(p_anho NUMBER,
                                          p_mes NUMBER,
                                          p_dia NUMBER,
                                          p_hora NUMBER,
                                          p_minuto NUMBER,
                                          p_segundo NUMBER) RETURN VARCHAR2 IS LANGUAGE JAVA
     NAME 'pruebas.JavaDate.getString(int, int, int, int, int, int) return String';
    

    SELECT f_javadate(TO_NUMBER(TO_CHAR(SYSDATE, 'YYYY')),
                      TO_NUMBER(TO_CHAR(SYSDATE, 'MM')),
                      TO_NUMBER(TO_CHAR(SYSDATE, 'DD')),
                      TO_NUMBER(TO_CHAR(SYSDATE, 'HH24')),
                      TO_NUMBER(TO_CHAR(SYSDATE, 'MI')),
                      TO_NUMBER(TO_CHAR(SYSDATE, 'SS')))
     FROM DUAL;
    

    它们看起来几乎一样,我只更改了包名、函数名和参数数。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Ori Marko    6 年前

    调用java源函数使用 CALL :

     VARIABLE myString VARCHAR2(20);
     CALL f_conversorSQL( 'Hello there!',
                       'General Kenobi',
                       'You are a bold one') 
     INTO :myString;
    

    SQL> VARIABLE myString VARCHAR2(20);
    
    SQL> CALL helloworld() INTO :myString;
    

    定义函数 java.lang.String :

    CREATE OR REPLACE FUNCTION f_conversorSQL(p_tipo VARCHAR2,
                                      p_tabla VARCHAR2,
                                      p_query VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'test.ConversorSQL.runConversor(java.lang.String, java.lang.String, java.lang.String) return java.lang.String';