SP call does not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eugene A

    SP call does not work

    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_desc r
    ( PV_dm_c IN VARCHAR2,
    PV_dm_x IN VARCHAR2,
    pv_flag IN VARCHAR2,
    CURR OUT RESULTSETCURSOR PKG.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_desc r;
    /*************** *************** *************** *************** ***************
    */

    /*************** ************ Java
    Appl*********** *************** *************/
    import java.sql.*;
    import java.sql.Driver Manager;
    import java.sql.Connec tion;
    import java.sql.Types;
    import java.sql.Callab leStatement;
    import java.sql.Result Set;
    import java.sql.SQLExc eption;
    import oracle.jdbc.dri ver.OracleTypes ;

    public class callsp
    {
    public static void getData() {
    try
    {
    final String driverClass = "oracle.jdbc.dr iver.OracleDriv er";
    final String connectionURL =
    "jdbc:oracle:th in:@hostname.co m:1521:INSTANCE 002";
    final String userID = "user";
    final String userPassword = "passwd";
    Connection con = null;
    String var1 = "PWS";
    String var2 = "MF31";
    String var3 = "E";
    Class.forName(d riverClass).new Instance();
    System.out.prin t("---------------------------------------" + "\n");
    System.out.prin t(" Connecting to -> " + connectionURL + "\n");
    System.out.prin t("---------------------------------------" + "\n");
    con = DriverManager.g etConnection(co nnectionURL, userID, userPassword);
    CallableStateme nt cs = con.prepareCall ("{call
    schtru.sp_get_a ll_descr ?, ?, ?, ?}");
    cs.setString(1, var1);
    cs.setString(2, var2);
    cs.setString(3, var2);
    cs.registerOutP arameter(1, Types.VARCHAR);
    cs.registerOutP arameter(2, Types.VARCHAR);
    cs.registerOutP arameter(3, Types.VARCHAR);
    cs.registerOutP arameter(4, OracleTypes.CUR SOR);
    cs.execute();
    ResultSet rs = (ResultSet) cs.getResultSet ();
    while (rs.next()) {
    String s = rs.getString(1) ;
    System.out.prin tln(s + " pounds of " + s + " sold to date.");
    }
    }
    catch(Exception e)
    {
    System.out.prin tln(" Exception is "+ e);
    }
    }
    public static void main(String args[])
    {
    getData();
    }
    }
    /*************** *************** *************** *************** ***************
    */


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

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


  • Virgil Green

    #2
    Re: SP call does not work

    "Eugene A" <lorus77@mailan dnews.com> wrote in message
    news:9f8b77f82e 987f9e1fba10a65 2b3211b@news.te ranews.com...[color=blue]
    > Hello.
    >
    > In this call from a Java prog to a Oracle SP I am trying to pass along[/color]
    some[color=blue]
    > 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_desc r
    > ( PV_dm_c IN VARCHAR2,
    > PV_dm_x IN VARCHAR2,
    > pv_flag IN VARCHAR2,
    > CURR OUT RESULTSETCURSOR PKG.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_desc r;
    >[/color]
    /*************** *************** *************** *************** ***************[color=blue]
    > */
    >
    > /*************** ************ Java
    > Appl*********** *************** *************/
    > import java.sql.*;
    > import java.sql.Driver Manager;
    > import java.sql.Connec tion;
    > import java.sql.Types;
    > import java.sql.Callab leStatement;
    > import java.sql.Result Set;
    > import java.sql.SQLExc eption;
    > import oracle.jdbc.dri ver.OracleTypes ;
    >
    > public class callsp
    > {
    > public static void getData() {
    > try
    > {
    > final String driverClass = "oracle.jdbc.dr iver.OracleDriv er";
    > final String connectionURL =
    > "jdbc:oracle:th in:@hostname.co m:1521:INSTANCE 002";
    > final String userID = "user";
    > final String userPassword = "passwd";
    > Connection con = null;
    > String var1 = "PWS";
    > String var2 = "MF31";
    > String var3 = "E";
    > Class.forName(d riverClass).new Instance();
    > System.out.prin t("---------------------------------------" + "\n");
    > System.out.prin t(" Connecting to -> " + connectionURL + "\n");
    > System.out.prin t("---------------------------------------" + "\n");
    > con = DriverManager.g etConnection(co nnectionURL, userID,[/color]
    userPassword);[color=blue]
    > CallableStateme nt cs = con.prepareCall ("{call
    > schtru.sp_get_a ll_descr ?, ?, ?, ?}");
    > cs.setString(1, var1);
    > cs.setString(2, var2);
    > cs.setString(3, var2);
    > cs.registerOutP arameter(1, Types.VARCHAR);
    > cs.registerOutP arameter(2, Types.VARCHAR);
    > cs.registerOutP arameter(3, Types.VARCHAR);[/color]

    I wouldn't register the first three parameters as output parameters since
    your sp only defines them as input parameters.
    [color=blue]
    > cs.registerOutP arameter(4, OracleTypes.CUR SOR);
    > cs.execute();
    > ResultSet rs = (ResultSet) cs.getResultSet ();
    > while (rs.next()) {
    > String s = rs.getString(1) ;
    > System.out.prin tln(s + " pounds of " + s + " sold to date.");
    > }
    > }
    > catch(Exception e)
    > {
    > System.out.prin tln(" Exception is "+ e);
    > }
    > }
    > public static void main(String args[])
    > {
    > getData();
    > }
    > }
    >[/color]
    /*************** *************** *************** *************** ***************[color=blue]
    > */
    >
    >
    > Exception is java.sql.SQLExc eption: ORA-06550: line 1, column 41:
    > PLS-00103: Encountered the symbol "" when expecting one of the following:
    >
    > := . ( @ % ;
    > The symbol ":=" was substituted for "" to continue.[/color]

    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


    Comment

    • Joe Weinstein

      #3
      Re: SP call does not work



      Eugene A wrote:
      [color=blue]
      > 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?[/color]

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

      CallableStateme nt cs = con.prepareCall ("{call schtru.sp_get_a ll_descr ( ?, ?, ?, ?}");

      [color=blue]
      >
      > Please help.
      >
      > Thanks,
      >
      > Eugene.
      >
      > /*************** *************** PL\SQL Stored Proc.
      > *************** **********/
      > PROCEDURE sp_get_all_desc r
      > ( PV_dm_c IN VARCHAR2,
      > PV_dm_x IN VARCHAR2,
      > pv_flag IN VARCHAR2,
      > CURR OUT RESULTSETCURSOR PKG.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_desc r;
      > /*************** *************** *************** *************** ***************
      > */
      >
      > /*************** ************ Java
      > Appl*********** *************** *************/
      > import java.sql.*;
      > import java.sql.Driver Manager;
      > import java.sql.Connec tion;
      > import java.sql.Types;
      > import java.sql.Callab leStatement;
      > import java.sql.Result Set;
      > import java.sql.SQLExc eption;
      > import oracle.jdbc.dri ver.OracleTypes ;
      >
      > public class callsp
      > {
      > public static void getData() {
      > try
      > {
      > final String driverClass = "oracle.jdbc.dr iver.OracleDriv er";
      > final String connectionURL =
      > "jdbc:oracle:th in:@hostname.co m:1521:INSTANCE 002";
      > final String userID = "user";
      > final String userPassword = "passwd";
      > Connection con = null;
      > String var1 = "PWS";
      > String var2 = "MF31";
      > String var3 = "E";
      > Class.forName(d riverClass).new Instance();
      > System.out.prin t("---------------------------------------" + "\n");
      > System.out.prin t(" Connecting to -> " + connectionURL + "\n");
      > System.out.prin t("---------------------------------------" + "\n");
      > con = DriverManager.g etConnection(co nnectionURL, userID, userPassword);
      > CallableStateme nt cs = con.prepareCall ("{call
      > schtru.sp_get_a ll_descr ?, ?, ?, ?}");
      > cs.setString(1, var1);
      > cs.setString(2, var2);
      > cs.setString(3, var2);
      > cs.registerOutP arameter(1, Types.VARCHAR);
      > cs.registerOutP arameter(2, Types.VARCHAR);
      > cs.registerOutP arameter(3, Types.VARCHAR);
      > cs.registerOutP arameter(4, OracleTypes.CUR SOR);
      > cs.execute();
      > ResultSet rs = (ResultSet) cs.getResultSet ();
      > while (rs.next()) {
      > String s = rs.getString(1) ;
      > System.out.prin tln(s + " pounds of " + s + " sold to date.");
      > }
      > }
      > catch(Exception e)
      > {
      > System.out.prin tln(" Exception is "+ e);
      > }
      > }
      > public static void main(String args[])
      > {
      > getData();
      > }
      > }
      > /*************** *************** *************** *************** ***************
      > */
      >
      >
      > Exception is java.sql.SQLExc eption: ORA-06550: line 1, column 41:
      > PLS-00103: Encountered the symbol "" when expecting one of the following:
      >
      > := . ( @ % ;
      > The symbol ":=" was substituted for "" to continue.
      >
      >[/color]

      Comment

      • Bjorn Abelli

        #4
        Re: SP call does not work


        "Joe Weinstein" wrote...
        [color=blue]
        > You missed one '(' in the SQL. It should be:
        >
        > CallableStateme nt cs =
        > con.prepareCall
        > ("{call schtru.sp_get_a ll_descr ( ?, ?, ?, ?}");[/color]

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

        CallableStateme nt cs =
        con.prepareCall
        ("{call schtru.sp_get_a ll_descr (?, ?, ?, ?)}");


        // Bjorn A


        Comment

        • Joe Weinstein

          #5
          Re: SP call does not work



          Bjorn Abelli wrote:
          [color=blue]
          > "Joe Weinstein" wrote...
          >
          >[color=green]
          >>You missed one '(' in the SQL. It should be:
          >>
          >>CallableState ment cs =
          >> con.prepareCall
          >>("{call schtru.sp_get_a ll_descr ( ?, ?, ?, ?}");[/color]
          >
          >
          > Shouldn't that actually be "two" misses?
          > One in the end of the argument list as well... ;-)
          >
          > CallableStateme nt cs =
          > con.prepareCall
          > ("{call schtru.sp_get_a ll_descr (?, ?, ?, ?)}");
          >[/color]

          Yep.
          [color=blue]
          >
          > // Bjorn A
          >
          >[/color]

          Comment

          • Virgil Green

            #6
            Re: SP call does not work

            "Joe Weinstein" <joeNOSPAM@bea. com> wrote in message
            news:40AF6937.6 020106@bea.com. ..[color=blue]
            >
            >
            > Bjorn Abelli wrote:
            >[color=green]
            > > "Joe Weinstein" wrote...
            > >
            > >[color=darkred]
            > >>You missed one '(' in the SQL. It should be:
            > >>
            > >>CallableState ment cs =
            > >> con.prepareCall
            > >>("{call schtru.sp_get_a ll_descr ( ?, ?, ?, ?}");[/color]
            > >
            > >
            > > Shouldn't that actually be "two" misses?
            > > One in the end of the argument list as well... ;-)
            > >
            > > CallableStateme nt cs =
            > > con.prepareCall
            > > ("{call schtru.sp_get_a ll_descr (?, ?, ?, ?)}");
            > >[/color]
            >
            > Yep.
            >[/color]

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

            - Virgil


            Comment

            • Bjorn Abelli

              #7
              Re: SP call does not work


              "Virgil Green" wrote...
              [color=blue]
              > Bjorn Abelli wrote:[/color]
              [color=blue][color=green]
              > > CallableStateme nt cs =
              > > con.prepareCall
              > > ("{call schtru.sp_get_a ll_descr (?, ?, ?, ?)}");[/color][/color]
              [color=blue]
              > Are these opening/closing parentheses required by Oracle?[/color]

              Yes.

              AFAIK, that's the standard syntax "inherited" from the similar constructions
              in ODBC.
              [color=blue]
              > I never use them with SQL Server. A review of the CallableStateme nt
              > interface docs gives no indication that the parentheses are needed.[/color]

              That's because it's up to the vendor how they have implemented it. If you
              have an OracleConnectio n, the CallableStateme nt is actually an
              OracleCallableS tatement.

              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.




              // Bjorn A


              Comment

              Working...