Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL & Java syntax question :(

Re: PL/SQL & Java syntax question :(

From: Rauf Sarwar <rs_arwar_at_hotmail.com>
Date: Wed, 06 Aug 2003 13:56:57 +0000
Message-ID: <3207368.1060178217@dbforums.com>

Originally posted by Monty
> Could someone help me with a syntax (: problem please. I know the
> syntax is somewhere in the Oracle documentation but I cannot find it.
> I have included my PL/SQL,Java below - just copy/paste into SQL/Plus.
> `
> Here is some sample output (PL/SQL to create procedures/packages at
> bottom of this posting).
>
> When I execute:
>
>
>
>
>
> SQL>
> SQL> SELECT pkg_test.method1('XXX') FROM DUAL;
>
> PKG_TEST.METHOD1('XXX')
> ------------------------------------------------
> one argument:XXX
>
> SQL>
>
>
>
>
>
> When I execute:
>
>
>
>
> SQL>
> SQL>
> SQL> SELECT pkg_test.method2('XXX','YYY') FROM DUAL;
>
> PKG_TEST.METHOD2('XXX','YYY')
> -------------------------------------------------------
> two arguments:XXX and YYY
>
> SQL>
>
>
>
>
> But I can not find the syntax so that when I execute
>
> SELECT pkg_test.method3('ZZZ') FROM DUAL;
>
> The output I get is
>
> PKG_TEST.METHOD3('ZZZ')
> -------------------------------------------------------
> two arguments:XXX and YYY
>
>
>
> Remove the "--" comments to execute.
>
> My question is what is the syntax to use a default value in the "IS
> LANGUAGE JAVA NAME clause" as outlined in my "method3".
> Thank you and sorry for asking a syntax question.
> Monty
>
> ---Here is the code, using Oracle8i/9i on a WinBox.
>
>
> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "test" AS
> package com.something;
> public class Test
> {
> public static String methodName(String s1)
> {
> return "one argument:"+s1;
> }
> public static String methodName(String s1,String s2)
> {
> return "two arguments:"+s1+" and "+s2;
> }
> }
> /
>
> CREATE OR REPLACE PACKAGE pkg_test AS
> FUNCTION method1(s1 IN VARCHAR2) RETURN VARCHAR2
> AS LANGUAGE JAVA NAME
> 'com.something.Test.methodName(java.lang.String) return
> java.lang.String';
> FUNCTION method2(s1 IN VARCHAR2,s2 IN VARCHAR2) RETURN VARCHAR2
> AS LANGUAGE JAVA NAME
> 'com.something.Test.methodName(java.lang.String,java.lang.String)
> return java.lang.String';
> -- FUNCTION method3(s1 IN VARCHAR2) RETURN VARCHAR2
> -- IS LANGUAGE JAVA NAME
> 'com.something.Test.methodName("XXX",java.lang.String) return
> java.lang.String';
> END pkg_test;
> /
>
> SELECT pkg_test.method1('XXX') FROM DUAL;
> SELECT pkg_test.method2('XXX','YYY') FROM DUAL;
> --SELECT pkg_test.method3('ZZZ') FROM DUAL;

You can modify method3 and wrap it around method2. Assign first or second parameter a default value e.g.

FUNCTION method3 (

   s1 in varchar2,
   s2 in varchar2 default 'XXX' ) return varchar2 as
begin

   return method2(s1, s2);
end method3;

Regards
/Rauf Sarwar

--
Posted via http://dbforums.com
Received on Wed Aug 06 2003 - 08:56:57 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US