PLS-00306:从Spring JDBC调用时,调用中参数的数量或类型错误

问题描述 投票:0回答:2
org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar  
[{call pkg_name.procedure_name()}]; nested exception is java.sql.SQLException: ORA-06550: line 1,  column 7:
PLS-00306: wrong number or types of arguments in call to 'PROCEDURE_NAME'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

我有两个模式-OwnerSchema和AppSchema。我拥有从OwnerSchema到AppSchema的所有程序包的授予执行特权。当我尝试从AppSchema的后端执行任何过程时,便能够执行该过程。当我尝试从Java Spring JDBC执行相同的过程时,出现上述错误。我可以从Java的OwnerSchema执行此过程。

我能够使用AppSchema从Java Spring JDBC应用程序访问所有表。

我已使用以下触发器在登录时指向OwnerSchmea。

 CREATE OR REPLACE TRIGGER FINAL_APP_USER.AFTER_LOGON_TRG
    AFTER LOGON ON FINAL_APP_USER.SCHEMA
    BEGIN
      DBMS_APPLICATION_INFO.SET_MODULE(USER, 'Initialized');
    EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=TEST'; --enter owner
    END;
    /

这里是程序调用

SimpleJdbcCall simpleJdbcCall = getSimpleJdbcCall()
                    .withCatalogName("pkg_name").withProcedureName(
                            "procedure_name").returningResultSet(
                            "C_Srf_1", new RowMapper<FinalCountForQuestions>() {
                                public FinalCountForQuestions mapRow(
                                        ResultSet rs, int rowNum)
                                        throws SQLException {

                                    ...

                                    return finalCountForQuestions;
                                }
                            });

            Map<String, Object> mapOfOutputParams = simpleJdbcCall.execute();
spring jdbc procedure privileges
2个回答
5
投票

Spring JDBC模板在调用数据库过程时生成以下查询

SELECT PACKAGE_NAME AS PROCEDURE_CAT,
OWNER AS PROCEDURE_SCHEM,
OBJECT_NAME AS PROCEDURE_NAME,
ARGUMENT_NAME AS COLUMN_NAME,
DECODE(POSITION, 0, 5,
DECODE(IN_OUT, 'IN', 1,
'OUT', 4,
'IN/OUT', 2,
0)) AS COLUMN_TYPE,
DECODE (DATA_TYPE, 'CHAR', 1,
'VARCHAR2', 12,
'NUMBER', 3,
'LONG', -1,
'DATE', 91,
'RAW', -3,
'LONG RAW', -4,
'TIMESTAMP', 93, 
'TIMESTAMP WITH TIME ZONE', -101, 
'TIMESTAMP WITH LOCAL TIME ZONE', -102, 
'INTERVAL YEAR TO MONTH', -103, 
'INTERVAL DAY TO SECOND', -104, 
'BINARY_FLOAT', 100, 'BINARY_DOUBLE', 101, 1111) AS DATA_TYPE,
DECODE(DATA_TYPE, 'OBJECT', TYPE_OWNER || '.' || TYPE_NAME, DATA_TYPE) AS TYPE_NAME,
DECODE (DATA_PRECISION, NULL, DATA_LENGTH,
DATA_PRECISION) AS PRECISION,
DATA_LENGTH AS LENGTH,
DATA_SCALE AS SCALE,
10 AS RADIX,
1 AS NULLABLE,
NULL AS REMARKS,
SEQUENCE,
OVERLOAD,
DEFAULT_VALUE
from ALL_ARGUMENTS
where OWNER like '<USER>' escape  '/'
and OBJECT_NAME like '<PROCEDURE_NAME>' escape '/' 
and PACKAGE_NAME like '<PACKAGE_NAME>' ESCAPE '/'                   
AND (ARGUMENT_NAME LIKE 'C_SRF_1' ESCAPE '/'
OR (ARGUMENT_NAME IS NULL
and DATA_TYPE is not null))
--and
--other arguments
ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, OVERLOAD, SEQUENCE;

因此,当您使用ApplicationUser调用数据库过程时,它将使用您的ApplicationUser名称进入ALL_ARGUMENTS视图,并且找不到任何参数。因此,解决方案是,当您调用过程时,按以下方式传递所有者的架构名称。

SimpleJdbcCall simpleJdbcCall = getSimpleJdbcCall()
                    .withSchemaName(<OwnerSchema>)
                    .withCatalogName("pkg_name").withProcedureName(
                            "procedure_name").returningResultSet(
                            "C_Srf_1", new RowMapper<FinalCountForQuestions>() {

0
投票

浪费了一个小时,出现类似错误。我在目录名称中有架构名称。很好地找到了过程,但是得到了错误。我必须分别声明所有位(tt.payment_requests.start_process):

simpleJdbcCall = new SimpleJdbcCall(oracleDataSource())
  .withSchemaName("TT")
  .withCatalogName("PAYMENT_REQUESTS")
  .withProcedureName("START_PROCESS");
© www.soinside.com 2019 - 2024. All rights reserved.