SP call does not work

E

Eugene A

Hello.

In this call from a Java prog to a Oracle SP I am trying to pass along some
varchars and a cursor, but apperently the syntax of the call to the stor
proc is incorrect. What am I doing wrong?

Please help.

Thanks,

Eugene.

/****************************** PL\SQL Stored Proc.
*************************/
PROCEDURE sp_get_all_descr
( PV_dm_c IN VARCHAR2,
PV_dm_x IN VARCHAR2,
pv_flag IN VARCHAR2,
CURR OUT RESULTSETCURSORPKG.RC )
IS
BEGIN
IF pv_flag = 'L' THEN
V_LIKE_STR := PV_dm_x || '%';
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x LIKE V_LIKE_STR;
ELSIF pv_flag = 'E' THEN
V_LIKE_STR := PV_dm_x;
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x = V_LIKE_STR;
END IF;
END sp_get_all_descr;
/***************************************************************************
*/

/*************************** Java
Appl***************************************/
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Types;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleTypes;

public class callsp
{
public static void getData() {
try
{
final String driverClass = "oracle.jdbc.driver.OracleDriver";
final String connectionURL =
"jdbc:eek:racle:thin:mad:hostname.com:1521:INSTANCE002";
final String userID = "user";
final String userPassword = "passwd";
Connection con = null;
String var1 = "PWS";
String var2 = "MF31";
String var3 = "E";
Class.forName(driverClass).newInstance();
System.out.print("---------------------------------------" + "\n");
System.out.print(" Connecting to -> " + connectionURL + "\n");
System.out.print("---------------------------------------" + "\n");
con = DriverManager.getConnection(connectionURL, userID, userPassword);
CallableStatement cs = con.prepareCall("{call
schtru.sp_get_all_descr ?, ?, ?, ?}");
cs.setString(1, var1);
cs.setString(2, var2);
cs.setString(3, var2);
cs.registerOutParameter(1, Types.VARCHAR);
cs.registerOutParameter(2, Types.VARCHAR);
cs.registerOutParameter(3, Types.VARCHAR);
cs.registerOutParameter(4, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = (ResultSet) cs.getResultSet();
while (rs.next()) {
String s = rs.getString(1);
System.out.println(s + " pounds of " + s + " sold to date.");
}
}
catch(Exception e)
{
System.out.println(" Exception is "+ e);
}
}
public static void main(String args[])
{
getData();
}
}
/***************************************************************************
*/


Exception is java.sql.SQLException: ORA-06550: line 1, column 41:
PLS-00103: Encountered the symbol "" when expecting one of the following:

:= . ( @ % ;
The symbol ":=" was substituted for "" to continue.
 
S

Sudsy

Eugene A wrote:
Exception is java.sql.SQLException: ORA-06550: line 1, column 41:
PLS-00103: Encountered the symbol "" when expecting one of the following:

Sorry, but this has nothing whatsoever to do with Java. From the
documentation:
ORA-06550 line string, column string:string

Cause: A PL/SQL compilation error has occurred. The numbers given for line and column are the location in the PL/SQL block where the error occurred.

Action: Refer to the following PL/SQL messages for more information about the error.

Over and out.
 
V

Virgil Green

Eugene A said:
Hello.

In this call from a Java prog to a Oracle SP I am trying to pass along some
varchars and a cursor, but apperently the syntax of the call to the stor
proc is incorrect. What am I doing wrong?

Please help.

Thanks,

Eugene.

/****************************** PL\SQL Stored Proc.
*************************/
PROCEDURE sp_get_all_descr
( PV_dm_c IN VARCHAR2,
PV_dm_x IN VARCHAR2,
pv_flag IN VARCHAR2,
CURR OUT RESULTSETCURSORPKG.RC )
IS
BEGIN
IF pv_flag = 'L' THEN
V_LIKE_STR := PV_dm_x || '%';
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x LIKE V_LIKE_STR;
ELSIF pv_flag = 'E' THEN
V_LIKE_STR := PV_dm_x;
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x = V_LIKE_STR;
END IF;
END sp_get_all_descr;
/***************************************************************************
*/

/*************************** Java
Appl***************************************/
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Types;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleTypes;

public class callsp
{
public static void getData() {
try
{
final String driverClass = "oracle.jdbc.driver.OracleDriver";
final String connectionURL =
"jdbc:eek:racle:thin:mad:hostname.com:1521:INSTANCE002";
final String userID = "user";
final String userPassword = "passwd";
Connection con = null;
String var1 = "PWS";
String var2 = "MF31";
String var3 = "E";
Class.forName(driverClass).newInstance();
System.out.print("---------------------------------------" + "\n");
System.out.print(" Connecting to -> " + connectionURL + "\n");
System.out.print("---------------------------------------" + "\n");
con = DriverManager.getConnection(connectionURL, userID, userPassword);
CallableStatement cs = con.prepareCall("{call
schtru.sp_get_all_descr ?, ?, ?, ?}");
cs.setString(1, var1);
cs.setString(2, var2);
cs.setString(3, var2);
cs.registerOutParameter(1, Types.VARCHAR);
cs.registerOutParameter(2, Types.VARCHAR);
cs.registerOutParameter(3, Types.VARCHAR);

I wouldn't register the first three parameters as output parameters since
your sp only defines them as input parameters.
cs.registerOutParameter(4, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = (ResultSet) cs.getResultSet();
while (rs.next()) {
String s = rs.getString(1);
System.out.println(s + " pounds of " + s + " sold to date.");
}
}
catch(Exception e)
{
System.out.println(" Exception is "+ e);
}
}
public static void main(String args[])
{
getData();
}
}
/***************************************************************************
*/


Exception is java.sql.SQLException: ORA-06550: line 1, column 41:
PLS-00103: Encountered the symbol "" when expecting one of the following:

:= . ( @ % ;
The symbol ":=" was substituted for "" to continue.

This would seem to indicate that the error is in the stored procedure
itself. However, I don't see a single " in the sp, so it's hard to say. Have
you executed the sp from within oracle itself?

- Virgil
 
J

Joe Weinstein

Eugene said:
Hello.

In this call from a Java prog to a Oracle SP I am trying to pass along some
varchars and a cursor, but apperently the syntax of the call to the stor
proc is incorrect. What am I doing wrong?

You missed one '(' in the SQL. It should be:

CallableStatement cs = con.prepareCall("{call schtru.sp_get_all_descr ( ?, ?, ?, ?}");

Please help.

Thanks,

Eugene.

/****************************** PL\SQL Stored Proc.
*************************/
PROCEDURE sp_get_all_descr
( PV_dm_c IN VARCHAR2,
PV_dm_x IN VARCHAR2,
pv_flag IN VARCHAR2,
CURR OUT RESULTSETCURSORPKG.RC )
IS
BEGIN
IF pv_flag = 'L' THEN
V_LIKE_STR := PV_dm_x || '%';
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x LIKE V_LIKE_STR;
ELSIF pv_flag = 'E' THEN
V_LIKE_STR := PV_dm_x;
OPEN CURR FOR
SELECT dm_c, dm_x
FROM dm_row_ss
WHERE dm_c = PV_dm_c
AND dm_x = V_LIKE_STR;
END IF;
END sp_get_all_descr;
/***************************************************************************
*/

/*************************** Java
Appl***************************************/
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Types;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleTypes;

public class callsp
{
public static void getData() {
try
{
final String driverClass = "oracle.jdbc.driver.OracleDriver";
final String connectionURL =
"jdbc:eek:racle:thin:mad:hostname.com:1521:INSTANCE002";
final String userID = "user";
final String userPassword = "passwd";
Connection con = null;
String var1 = "PWS";
String var2 = "MF31";
String var3 = "E";
Class.forName(driverClass).newInstance();
System.out.print("---------------------------------------" + "\n");
System.out.print(" Connecting to -> " + connectionURL + "\n");
System.out.print("---------------------------------------" + "\n");
con = DriverManager.getConnection(connectionURL, userID, userPassword);
CallableStatement cs = con.prepareCall("{call
schtru.sp_get_all_descr ?, ?, ?, ?}");
cs.setString(1, var1);
cs.setString(2, var2);
cs.setString(3, var2);
cs.registerOutParameter(1, Types.VARCHAR);
cs.registerOutParameter(2, Types.VARCHAR);
cs.registerOutParameter(3, Types.VARCHAR);
cs.registerOutParameter(4, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = (ResultSet) cs.getResultSet();
while (rs.next()) {
String s = rs.getString(1);
System.out.println(s + " pounds of " + s + " sold to date.");
}
}
catch(Exception e)
{
System.out.println(" Exception is "+ e);
}
}
public static void main(String args[])
{
getData();
}
}
/***************************************************************************
*/


Exception is java.sql.SQLException: ORA-06550: line 1, column 41:
PLS-00103: Encountered the symbol "" when expecting one of the following:

:= . ( @ % ;
The symbol ":=" was substituted for "" to continue.
 
B

Bjorn Abelli

...
You missed one '(' in the SQL. It should be:

CallableStatement cs =
con.prepareCall
("{call schtru.sp_get_all_descr ( ?, ?, ?, ?}");

Shouldn't that actually be "two" misses?
One in the end of the argument list as well... ;-)

CallableStatement cs =
con.prepareCall
("{call schtru.sp_get_all_descr (?, ?, ?, ?)}");


// Bjorn A
 
J

Joe Weinstein

Bjorn said:
...




Shouldn't that actually be "two" misses?
One in the end of the argument list as well... ;-)

CallableStatement cs =
con.prepareCall
("{call schtru.sp_get_all_descr (?, ?, ?, ?)}");

Yep.


// Bjorn A
 
V

Virgil Green

Joe Weinstein said:

Are these opening/closing parentheses required by Oracle? I never use them
with SQL Server. A review of the CallableStatement interface docs gives no
indication that the parentheses are needed.

- Virgil
 
B

Bjorn Abelli

...
Bjorn Abelli wrote:
Are these opening/closing parentheses required by Oracle?

Yes.

AFAIK, that's the standard syntax "inherited" from the similar constructions
in ODBC.
I never use them with SQL Server. A review of the CallableStatement
interface docs gives no indication that the parentheses are needed.

That's because it's up to the vendor how they have implemented it. If you
have an OracleConnection, the CallableStatement is actually an
OracleCallableStatement.

If you're familiar with PL/SQL in Oracle, you also know how local variables
are used. That syntax is also allowed for the SQL-string as an alternative
for the questionmarks.

http://database.sarang.net/database/oracle/jdbc/jdbc_faq.html


// Bjorn A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top