Spend multiple values with parameter of stored procedure

CREATE TABLE VTEST_INSERT)

NUMBER OF MY_ID,

COLUMN1 VARCHAR2 (50)

);

-SELECT * FROM VTEST_INSERT;

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (1, 'TEST1');

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (2, "TEST2");

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (3, "TEST3");

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (4, "TEST4");

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (5, 'TEST5');

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (1, "TEST6");

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (2, 'TEST7');

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (3, "TEST8");

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (4, 'TEST9');

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (5, "TEST10");

CREATE OR REPLACE

PROCEDURE VTEST_INSERT_SP (vid in VARCHAR2, vname IN VARCHAR2)

AS

BEGIN

DELETE FROM VTEST_INSERT WHERE MY_ID IN (vid);

INSERT INTO VTEST_INSERT (MY_ID, COLUMN1) VALUES (vid, vname);

END;

/

EXEC VTEST_INSERT_SP(1,'TEST999');

This set works well above. But I want to be able to pass multiple values VNAME. so, something like:

EXEC VTEST_INSERT_SP(1,'TEST999','TEST888','TEST777');

any help is appreciated. Thank you.

This would make many inserts each with the same vid and values of different VNAME.

Try something like this

  1. SET SQLBLANKLINES
  2. ALTER SESSION SET PLSQL_WARNINGS = ' ENABLE: ALL ';
  3. DROP TABLE vtest_insert;
  4. CREATE TABLE vtest_insert (vid NUMBER, vname VARCHAR2 (20));
  5. INSERT ALL
  6. IN vtest_insert (vid, vname) VALUES (1, "yyyy")
  7. IN vtest_insert (vid, vname) VALUES (1, "bb")
  8. IN vtest_insert (vid, vname) VALUES (1, "cccccc")
  9. IN vtest_insert (vid, vname) VALUES (2, "ddd")
  10. IN vtest_insert (vid, vname) VALUES (2, 'ee')
  11. SELECT * FROM .dual 'PUBLIC '.
  12. SELECT * FROM vtest_insert;
  13. CREATE or REPLACE TYPE vnames_tab_ty IS TABLE OF VARCHAR2 (20)
  14. /
  15. DISPLAY ERRORS;
  16. CREATE OR REPLACE PROCEDURE vtest_insert_sp
  17. (
  18. p_vid IN vtest_insert.vid%TYPE,
  19. p_vnames IN vnames_tab_ty
  20. )
  21. DEFINE AUTHID
  22. IS
  23. BEGIN
  24. DELETE FROM vtest_insert WHERE the vid = p_vid;
  25. FORALL idx IN p_vnames. FIRST... p_vnames. LAST
  26. INSERT INTO vtest_insert (vid, vname) VALUES (p_vid, p_vnames (idx));
  27. END vtest_insert_sp;
  28. /
  29. DISPLAY ERRORS;
  30. >
  31. DECLARE
  32. Vnam vnames_tab_ty;
  33. vid vtest_insert.vid%TYPE.
  34. BEGIN
  35. BK.vid: = 1;
  36. BK.vnames: is vnames_tab_ty ('vn-01', 'vn-02', 'vn-03');.
  37. vtest_insert_sp (p_vid-online bk.vid, p_vnames-online bk.vnames).
  38. COMMIT;
  39. BK.vid: = 2;
  40. BK.vnames: is vnames_tab_ty ('vn-04', 'vn-05', 'vn-06', 'vn-07');.
  41. vtest_insert_sp (p_vid-online bk.vid, p_vnames-online bk.vnames).
  42. COMMIT;
  43. END;
  44. /
  45. SELECT * FROM vtest_insert;

Which produces the following output

Table created.

5 rows created.

VNAME VID

---------- --------------------

1-aaaa

1 bb

1 cccccc

2 ddd

2 EA

Type of creation.

No errors.

Created procedure.

No errors.

PL/SQL procedure successfully completed.

VNAME VID

---------- --------------------

1 VL-01

1 VL-02

1 VL-03

2 vn-04

2 vn-05

2 vn-06

2 vn-07

7 selected lines.

SQL >

Kind regards

Dariyoosh

Tags: Database

Similar Questions

  • pass values of parameter to the procedure stored in the URL, possible?

    Hi, everyone, our system is Apex4.0.2 in Linux CentOS 5 on Oracle 11 g 2, here is the procedure:

    create or replace procedure test_public (Cust_id integer)
    is

    Start
    owa_util.mime_header ("text/xml", FALSE);
    owa_util.mime_header ("application/octet", FALSE);
    -Close the HTTP header
    owa_util.http_header_close;

    HTP.p (DBMS_XMLGEN.getXML ("SELECT * FROM demo_orders where customer_id ='|")) cust_ID));
    end;

    +/+

    the call to the stored procedure is SUCCESSFUL when Test_public has no parameters, as:
    http://myserver/Apex/myschema.test_public (OK)
    the question is: I want to spend the 3 settings in my stored procedure (on production procedure), do not know how?

    Any suggestions are greatly appreciated

    create or replace procedure test_public (param1, param2 IN VARCHAR2, param3 in NUMBER IN number)

    http://myserver/apex/myschema.test_public?param1=¶m2=¶m3=
    
  • What subprogramme should we prefer to return multiple values with OUT parameter?

    Hello

    I worked on the procedures and functions, and aware of their differences. Today I have an interview question that - suppose I don't have return multiple values through a subroutine and I want nor run any what DML within this subprogramme and I want to use this subprogramme in the SQL query. What subprogramme I would prefer - "Operating Mode" or "Function" and why?

    In my view, both can be used in this case, but want to see your views and opinions.

    Kind regards

    Sachin jerbi

    In terms of software engineering, if you claim something that you expect to "return" something (a value or values) then you use a function.  If you call something to "do" something, and then you use a procedure.

    THE settings are not good practices in many cases and should not strictly considered "return" of values.  Instead, they are assigned values in the code and generally act as pointers to the original variable/structure that was passed as a parameter (the actual internals of Oracle don't quite do it, but in principle this is what they do).

    A return value (or structure) of a function is basically push in the battery to the point that the RETURN statement is issued, and then the code calling the stack appears to assign it to a variable or placeholder, it should go in.

    If it seems a little difference between procedures and functions to some people, it is recommended to use functions for obtaining values and procedures to do things, in most cases.  It is not just "syntactic sugar", as mentioned above.

  • Can we do non-mandatory parameter of stored procedure?

    Can we make a parameter in the stored procedure as a non-mandatory? so that we can call the stored procedure with parameters?

    Assign a default value, for example

    p_someparameter IN INTEGER DEFAULT 0
    

    or

    p_someparameter IN INTEGER := 0
    

    Syntax of the parameter

  • BPEL does not receive "return value" of MS SQL, stored procedure

    Hello

    We are facing this problem citing a MS SQL stored procedure the BPEL (jdbc 1.2 driver). We have created the wsdl for the stored procedure correctly using a command line utility tool provided with Oracle SOA Suite.
    But the question is THAT BPEL is not able to get the data present in the statement of "return" of the procedure. We receive null output. But it is able to extract the data from the output variable, if any. Case 1 below is for the return statement. Case 2 is for the output variable


    Case 1: in the following, the output is returned using the return statement. The BPEL that calls this procedure is to obtain a NULL value as an answer to this.


    ALTER PROCEDURE [dbo]. [AddNumbersRet]
    -Add the parameters for the procedure
    @Number1 int,
    @Number2 int
    AS
    BEGIN
    -SET NOCOUNT ON added to avoid additional results sets from
    -interfering with SELECT statements.
    SET NOCOUNT ON;

    -Controls insert for procedure here
    Return (@Number1 + @Number2);
    END

    Case 2: in the following, the output is returned using the SumOfNums output variable. The BPEL that calls this procedure is to obtain a correct answer.


    ALTER PROCEDURE [dbo]. [AddNumbers]
    @Number1 int,
    @Number2 int,
    @SumOfNums int output
    AS
    BEGIN

    -SET NOCOUNT ON added to avoid additional results sets from
    -interfering with SELECT statements.
    SET NOCOUNT ON;

    Set @SumOfNums = (@Number1 + @Number2);

    END



    Case 1 is a failure and case 2 is successful. We cannot change our procedures similar to case 1 to use variables of output because of dependencies on other applications.

    All the world is facing this problem? This looks like a bug in BPEL. Please, share your experiences.


    Thanks and greetings

    Mohan

    Published by: user10980910 on December 8, 2009 05:16

    There is a gap in the command line utility that was addressed in the adapter configuration (AS11gR1) Wizard. The API is a procedure, not a function, so does not return the query for the parameters that the utility made anything for the RETURN statement.

    The adapter configuration wizard is unable to say if there is a RETURN statement either, but it provides the user with a check box that can be used to indicate the presence of the declaration. In the wizard, if you check the checkbox, a parameter is added to the XSD to the RETURN statement. In essence, the adapter will process the procedure as a function and you will get the value of the PERFORMANCE.

    Usually, I wish to indicate that you certainly should NOT change the generated XSD. But you might be able to do it, by adding the necessary element to the OutputParameters for your RETURN statement. Add the following immediately AFTER the element of 'Lines', which occurs first in the XSD and BEFORE all items for the other none.

    Use a value for the "" that is meaningful to you. The wizard uses the name of the stored procedure with the name of the element. We could call this "RETURN_VALUE" or else if is more to your liking. Add the item after you generate the XSD using the command line utility, and then use the XSD when you model your BPEL processes. The WSDL should already have the content for this element handling.

  • Several values of parameter of a procedure

    Hi all
    Here, I need to create a procedure and this procedure has a parameter for this setting, I need to pass multiple values separated by a ',' (comma)


    Any help... Thanks in advance

    Hello

    Welcome to the forum!

    See
    http://www.Oracle-base.com/articles/Misc/DynamicInLists.php
    http://tkyte.blogspot.com/2006/06/varying-in-lists.html

  • Pass complex Types with chains to stored procedures: become null

    Hello

    I would like to pass an array of strings or a type of custom to a PL/SQL stored procedure object, you use the JDBC thin driver. It is possible if the tables or object types contain integers. With strings (resp. varchar2) However, I encountered a repetitive problem, no matter what I tried: the varchar2 field seems to be null in the stored procedure.

    There is something special with the passage of short strings?

    I tested with Oracle version server 10.2.0.3, 10.2.0.4 and 11.1.0.7.0.
    JDBC Thin drivers used are ojdbc14.jar is of 10.2.0.4 and ojdbc5.jar 11.1.0.7.0.
    I use Java 5.

    Tested approaches include:
    -oracle.sql.StructDescriptor, preparedStatement.setSTRUCT, or setStruct
    -Pass a Java type that implements the SQLData with preparedStatement.setObject
    -Pass a Java type that implements ORAData and ORADataFactory

    I tested it with an example of metalink (Doc ID 458572.1), and as I said, this example shows the same problem: strings passed appear as null - in three versions of Oracle that I tested. The example has been changed only with respect to the scheme name.
    ()Doc ID 458572.1 refers to a bug that shows the behavior I describe here, but this bug should be fixed in 10.2.0.4 and 11).

    I can paste some of my source code, but I feel that the solution could be found elsewhere, such as problems, version mismatch, the character set...

    Any ideas on the specialties with passage of strings in types of objects or paintings? My strings are null. (For tables, I get the right amount of NULL values).
    I even checked that I can pass a string argument simple to a procedure that worked indeed.

    Kind regards
    Carsten

    There is something special with the passage of short strings?

    Yes, this is a common problem. You must include orai18n.jar classpath. BTW it is documented here and here.

  • spend multiple values lists at different page Manager

    Hello
    I try to convey the values of a list manager page 2 to a box of text on page 1 item when this button is clicked. (I tried only point display, any type of element is fine as long as it displays multiple values)

    I always get only the first value in the list manager spent. Can you help me get all values?

    I created a workspace to explain the problem.

    Workspace: TIMES
    Username: TESTBUTTON
    password: hiking

    Application: report

    I have two pages, on page 2, I have a list manager and once I select several values and press go, it redirects to page 1 and sets the value of article D with the value. How to set multiple values?

    Any help is greatly appreciated.

    Thank you
    Priya

    Spriya wrote:
    Hello
    I try to convey the values of a list manager page 2 to a box of text on page 1 item when this button is clicked. (I tried only point display, any type of element is fine as long as it displays multiple values)

    I always get only the first value in the list manager spent. Can you help me get all values?

    I created a workspace to explain the problem.

    Workspace: TIMES
    Username: TESTBUTTON
    password: hiking

    Application: report

    I have two pages, on page 2, I have a list manager and once I select several values and press go, it redirects to page 1 and sets the value of article D with the value. How to set multiple values?

    Manager of the list items using the colon (': ') to separate multiple values. The values containing a colon cannot be passed in the URL of the APEX, where they make a special use as separators between the components of the query string. Therefore, the content of a list manager containing more than 1 value can be passed using a redirection branch which passes by the URL values.

    Another approach is to set the value of the target in a process of (conditional on the same key as the branch) page rather than in the branch.

  • spend multiple values on the interaction of click value

    Hi gurus:

    I have a requirement where I need to display a report of the first (a table or a PivotTable), with the type Cust_ID, recipes, etc. Cust_id is a unique dimension. Most of the stuff is made.

    And then the user wants to select 4 different values of Cust_ID and run another report of detailed comparison of the attributes of these clients.

    Now, the solution I proposed one or the other was a copy and paste in the new edition box prompt, or multiple selection on cust_id on new page.

    But the 'expert' user interface wants something like boxes to tick next to all ranks and press a button that automatically starts a comparison report.

    I know that we can pass a value to the other report using the value interaction. But how I spend 4 different values to the click?
    Or is there no other way?

    Please help me.

    V

    Sorry there not be useful. I think that the solution works and book it that the user needs. Article is that sometimes we spend too much time trying to satisfy a user wants and brings us to spend our valuable time that could be spent more productively. Well...

    Good luck, however, Vinay!

  • How to accept the array as a parameter of stored procedure

    Hi, this is the scenario

    the java team send me a table of numbers as an input for my procedure.

    the size of the array can be dynamic... I do not know the size

    what I have to do is

    I have to write a procedure that must accept this table as parameter
    crosses of the first element of the array too the end of the array to each value in the table

    and get on a table for this value and remove this line in the table

    How can I do?

    Please suggest

    concerning
    REDA

    Published by: raj_fresher on May 7, 2009 11:42

    Raj,

    Here is the code

    --This is you will create
    create or replace type TYP_PHONES as table of Varchar2(15) ;
    /
    --- This will be your procedure
    create or replace
    procedure give_me_an_array1( p_array in TYP_PHONES )
    as
    begin
    -- Do whatever you want to with the data you get
    for i in 1 .. p_array.count
    loop
    dbms_output.put_line( p_array(i) );
    end loop;
    end;
    /
    

    Tell your guy java to define this table as below

    String[] intArray= {"john","miller","scott"};
    ArrayDescriptor descriptor =ArrayDescriptor.createDescriptor( "TYP_PHONES", conn );
    ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
    

    * [Full active code | http://db-oracl.blogspot.com/2009/05/passing-arrays-from-java.html] *.

    SS

  • Multiple WHEN MATCHED in Oracle STORED PROCEDURE

    Hi all
    I use Oracle version 10.1.0.4.2. Can I use several "WHEN MATCHED' for my procedure stored as below in SQL SERVER:

    WHEN put in CORRESPONDENCE AND target. Quantity - source. OrderQty < = 0
    THEN DELETE
    WHEN MATCHED
    THEN UPDATE the target VALUE. Quantity = target. Quantity - source. OrderQty,
    target. ModifiedDate = GETDATE()


    Thanks in advance

    ==========================================

    Copy the SQL Code
    USE AdventureWorks2008R2;
    GO
    IF OBJECT_ID (no Production.usp_UpdateInventory', P') IS NOT NULL DROP PROCEDURE Production.usp_UpdateInventory;
    GO
    CREATE PROCEDURE Production.usp_UpdateInventory
    DateTime @OrderDate
    AS
    MERGE Production.ProductInventory as target
    USING (SELECT ProductID, SUM (OrderQty) FROM Sales.SalesOrderDetail AS sod
    JOIN Sales.SalesOrderHeader AS soh
    ON grass. SalesOrderID = soh. SalesOrderID
    AND soh. OrderDate = @OrderDate
    GROUP BY ProductID) AS source (ProductID, OrderQty)
    (TARGET. ProductID = source. ProductID)
    WHEN put in CORRESPONDENCE AND target. Quantity - source. OrderQty < = 0
    THEN DELETE
    WHEN MATCHED
    THEN UPDATE the target VALUE. Quantity = target. Quantity - source. OrderQty,
    target. ModifiedDate = GETDATE()
    OUTPUT $action, Inserted.ProductID, Inserted.Quantity, Inserted.ModifiedDate, Deleted.ProductID,
    Deleted.Quantity, Deleted.ModifiedDate;
    GO

    EXECUTE Production.usp_UpdateInventory ' 20030501'

    Use:

    WHEN MATCHED
    THEN UPDATE SET target.Quantity = target.Quantity - source.OrderQty,
    target.ModifiedDate = GETDATE()
    DELETE WHERE target.Quantity <= 0
    

    SY.

  • How to check multiple values with another column?

    Hi all

    create table xxc_abc (col1 , dept_id number number);

    create the table xxc_bbb (col2 number,sa_dept_id number);

    insert into xxc_abc values (1,10)

    insert into xxc_abc values (2,11)

    insert into xxc_abc values (3,12)

    insert into xxc_bbb values (20.10)

    insert into xxc_bbb values (20,11)

    insert into xxc_bbb values (20,12)

    SELCT

    xxc_abc a.,

    xxc_bbb b

    where a.dept_id = b.sa_dept_id

    Expected results

    a.Col1 b.col2

    ---------  --------

    1 20

    2 20

    3 20

    I need to get several values a.col1 with the same value of the b.col2 column

    a.Col1 b.col2

    ------- ------

    1 20

    2 20

    3 20

    Thank you

    Post edited by: Rajesh123 added Test cases in the main Thread

    Select the number you want to


    with

    xxc_abc as

    (select 1 col1, 10 dept_id in union double all the)

    Select 2,11 Union double all the

    Select double 3.12

    ),

    xxc_bbb as

    (select col2 20, 10 sa_dept_id union double all the)

    Select 20,11 Union double all the

    Select 20,12 double

    )

    Select col1, col2, cnt_all, cnt_not_null, cnt_unique

    from (select a.col1, b.col2,

    Count (*) on cnt_all (b.col2 partition).

    Count (a.Col1) on cnt_not_null (b.col2 partition),

    Count (distinct a.col1) on cnt_unique (b.col2 score)

    xxc_abc a.,

    xxc_bbb b

    where a.dept_id = b.sa_dept_id

    )

    where least (cnt_all, cnt_not_null, cnt_unique) > 1

    order by col1

    COL1 COL2 CNT_ALL CNT_NOT_NULL CNT_UNIQUE
    1 20 3 3 3
    2 20 3 3 3
    3 20 3 3 3

    Concerning

    Etbin

  • Java stored procedure

    Hello

    I tried to register with the Java stored procedure and created a Java class for it. I am quite successful in compiling and executing the code using the Java compiler in Windows CMD, but I meet below error when I try to do the same thing via Java stored proc.
    PRAZY@orcl> CREATE OR REPLACE  FUNCTION WINREGREAD(REGKEY VARCHAR2,REGVALUE VARCHAR2) RETURN VARCHAR2
      2  AS
      3  LANGUAGE JAVA NAME 'WindowsRegistry.readString(java.lang.String,java.lang.String) return java.lang.String';
      4  /
    
    Function created.
    PRAZY@orcl> call winregread('Software\\MyApps','Test') into :mystring;
    call winregread('Software\\MyApps','Test') into :mystring
    *
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.NullPointerException
    
    
    Elapsed: 00:00:00.01
    PRAZY@orcl>
    Here's the Java code and its put
    //Uncomment the below like while compiling Java source in DB
    //CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "WinRegistry" AS
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.prefs.Preferences;
    public class WindowsRegistry {
      public static final int HKEY_CURRENT_USER = 0x80000001;
      public static final int HKEY_LOCAL_MACHINE = 0x80000002;
      public static final int REG_SUCCESS = 0;
      public static final int REG_NOTFOUND = 2;
      public static final int REG_ACCESSDENIED = 5;
      private static final int KEY_ALL_ACCESS = 0xf003f;
      private static final int KEY_READ = 0x20019;
      private static Preferences userRoot = Preferences.userRoot();
      private static Preferences systemRoot = Preferences.systemRoot();
      private static Class<? extends Preferences> userClass = userRoot.getClass();
      private static Method regOpenKey = null;
      private static Method regCloseKey = null;
      private static Method regQueryValueEx = null;
      static {
        try {
          regOpenKey = userClass.getDeclaredMethod("WindowsRegOpenKey",
              new Class[] { int.class, byte[].class, int.class });
          regOpenKey.setAccessible(true);
          regCloseKey = userClass.getDeclaredMethod("WindowsRegCloseKey",
              new Class[] { int.class });
          regCloseKey.setAccessible(true);
          regQueryValueEx = userClass.getDeclaredMethod("WindowsRegQueryValueEx",
              new Class[] { int.class, byte[].class });
          regQueryValueEx.setAccessible(true);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
      private WindowsRegistry() {  }
    
      public static String readString(String key, String valueName)
       throws IllegalArgumentException, IllegalAccessException,
        InvocationTargetException 
      {
    
        int hkey = HKEY_LOCAL_MACHINE;
          return readString(systemRoot, hkey, key, valueName);
      }
    
    private static String readString(Preferences root, int hkey, String key, String value)
    throws IllegalArgumentException, IllegalAccessException,
        InvocationTargetException 
      {
        try
    {
        int[] handles = (int[]) regOpenKey.invoke(root, new Object[] {
            new Integer(hkey), toCstr(key), new Integer(KEY_READ) });
    
        if (handles[1] != REG_SUCCESS) {
          return null;
        }
        byte[] valb = (byte[]) regQueryValueEx.invoke(root, new Object[] {
            new Integer(handles[0]), toCstr(value) });
        regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
        return (valb != null ? new String(valb).trim() : null);
    }
    catch (NullPointerException e)
    { 
    return e.getMessage();
    }
      }
    // utility
      private static byte[] toCstr(String str) {
        byte[] result = new byte[str.length() + 1];
        for (int i = 0; i < str.length(); i++) {
          result[i] = (byte) str.charAt(i);
        }
        result[str.length()] = 0;
        return result;
      }
    
    //Begin - Remove the following lines while compiling Java source in DB
    public static void main(String[] args) throws Exception 
      {
    String value = "";
    value = WindowsRegistry.readString("Software\\MyApps","Test");
        System.out.println("Reg key Value is: " +value);
      }
    //End
    
    };
    
    //Output
    d:\Java_Test>javac WindowsRegistry.java
    
    d:\Java_Test>java WindowsRegistry
    Reg key Value is: TEST VALUE
    
    -----------------------------------------------------------------------------
    
    Env. Details:
    =======
    Windows Vista 32 bit
    
    DB:
    ====
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    As you can see, I get my results when I run the same command prompt class, but encounter an error when it is executed from the DB.

    Also, I have granted permission to the runtime using DBMS_JAVA. Is there an any other permission problem?

    Kindly help and let me know if you need another entry.

    Thank you!

    Kind regards
    Prazy

    The Pref class is not supported in Oracle. So I used Java SP for BACK orders executed and calling in turn REG QUERY command.
    Tested with Windows 2003, Win XP and Win Vista (32-bit).

    PRAZY@orcl> select banner from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE     11.1.0.6.0     Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production                                                                                                                                                                                                                    
    
    Elapsed: 00:00:00.00
    PRAZY@orcl> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "WindowsRegistry" AS
      2  import java.io.*;
      3  import java.lang.*;
      4
      5  public class WindowsRegistry {
      6
      7  public static String ReadKey(String key,String valueName)
      8  {
      9       String finalVal=null;
     10       String curVal=null;
     11       String command="reg query " + key + " /v " + valueName;
     12         try {
     13             // get runtime environment and execute child process
     14             Runtime systemShell = Runtime.getRuntime();
     15             Process output = systemShell.exec(command);
     16             // open reader to get output from process
     17             BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
     18             String line = null;
     19              while((line = br.readLine()) != null )
     20                  {
     21                 finalVal = curVal;
     22                      curVal = line;
     23                  }
     24                 output.waitFor();
     25            //get the value by calling findkeyval method
     26            finalVal=findKeyVal(finalVal.trim(),valueName);
     27             return finalVal;
     28             }
     29          catch (IOException ioe){ return "";}
     30          catch (Throwable t) { return "";}
     31  }
     32
     33  //Method to split the output and retrieve key value
     34  public static String findKeyVal(String keyLine,String valName)
     35  {
     36       String retVal="";
     37       String [] temp = null;
     38       temp = keyLine.split("\\s+");
     39       if (temp[0].equals(valName)) {
     40            for (int i=2; i CREATE OR REPLACE FUNCTION WinRegRead(keyPath varchar2,keyName varchar2) RETURN VARCHAR2
      2  AS
      3  LANGUAGE JAVA NAME 'WindowsRegistry.ReadKey(java.lang.String,java.lang.String) return java.lang.String';
      4  /
    
    Function created.
    
    Elapsed: 00:00:00.01
    PRAZY@orcl> var keyVal varchar2(50)
    PRAZY@orcl> print
    
    KEYVAL
    --------------------------------------------------------------------------------------------------------------------------------                                                                                                                          
    
    PRAZY@orcl> call WinRegRead('HKLM\Software\Oracle','inst_loc') into :keyVal;
    
    Call completed.
    
    Elapsed: 00:00:00.04
    PRAZY@orcl> print
    
    KEYVAL
    --------------------------------------------------------------------------------------------------------------------------------
    C:\Program Files (x86)\Oracle\Inventory                                                                                                                                                                                                                   
    

    Fact!

    I hope this might help someone!

    Kind regards
    Prazy

  • Calling stored procedure with an input of DATE parameter

    Hello. A question about the Date input parameters when you call a stored procedure.

    I have a procedure that takes a DATE as input parameter. I would DATE this value to include a time element.

    My Application Module method takes an input as a java.util.Date (myParamDate) parameter - that will preserve a time element (?).

    However when I create the CallableStatement, I am trying to set the parameter using setDate like this (for the param 5):
                st = getDBTransaction().createCallableStatement("begin cs_my_pck.request_values(?,?,?,?,?,?,?,?); end;", 0);            
                Connection myConn = st.getConnection();
                ArrayDescriptor myArrDesc  =  ArrayDescriptor.createDescriptor("CS_FIELD_TABT", myConn);
                Array sqlParamNameArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramNames.toArray());
                Array sqlParamValueArray = new oracle.sql.ARRAY(myArrDesc, myConn, paramValues.toArray());
                Array sqlFilterNameArray = new oracle.sql.ARRAY(myArrDesc,myConn,filterNames.toArray());
                    
                st.setString(1, repType);
                st.setObject(2, sqlParamNameArray);
                st.setObject(3,sqlParamValueArray);
                st.setObject(4,sqlFilterNameArray);
    
                java.sql.Date myRepDate = new java.sql.Date(myParamDate.getTime());
    
                st.setDate(5,myRepDate);
                
                System.out.println("Report Date = " + myRepDate.toString());
                st.setString(6,repUser);
                st.setString(7,repAttach);
                // set out param
                st.registerOutParameter(8, Types.NUMERIC);
                st.execute();
    I understand java.sql.Date does NOT include a time element. But setDate() only accepts a java.sql.Date so my parameter of the procedure ends with a zero time element.

    How to call this procedure keeping the time element?

    Thank you.

    It includes the time element, if you want more precision with time stamp.

    http://docs.Oracle.com/javase/6/docs/API/Java/SQL/date.html

  • The Null value as the default value for an input to a stored procedure parameter

    Hello

    How can we set the default values with the NULL value for the parameter in a stored procedure.
    create or replace procedure emp_proc ( p_test_input in varchar2
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2,
                                                       p_manager_id in number )
    as
      begin
       if ( upper ( p_test_input ) = 'I' )
       then
          insert into emp
          values      ( p_emp_id  ,p_emp_name ,p_Manager_id,sysdate );
       elsif ( upper ( p_test_input ) = 'D' )
       then
          delete from emp
          where       emp_id  = p_emp_id;
       else
          dbms_output.put_line
             ( 'Please input ''A'' for ADD or ''D'' Delete  EMPLOYEE'
             );
       end if;
    end;
    As described above if I want to delete only the functioning

    I want to call this procedure without pass additional parameters.
     EXECUTE  emp_proc('D',1010);
    Published by: Rede on May 28, 2010 12:21

    Published by: Rede on May 28, 2010 12:22
    create or replace procedure emp_proc ( p_test_input in varchar2,
                                                        p_emp_id in number,
                                                        p_emp_name in varchar2 default null,
                                                       p_manager_id in number default null )
    

Maybe you are looking for