Using cursors on BD Java edition

(I changed the question becaus it wasn't clear)
I need to do a search in my database, but I don't have the key, I just have some data. Let me explain:
@Entity
class MyEntity {
@PrimaryKey(sequence="ID")
long id;
private String name;
private String surname;
private String birthDate; // format "MM/DD/AAAA" "12/31/2000"
Supose I want to find users by surname, (I don't have the key id).
How can I do it???
I know using cursors I can pass the key and data. For example If I bind the data setting the surname to a String,
doing:
do {
     next = cursor.getNext(key, data, LockMode.DEFAULT);
     MyEntity entry = dataBinding.entryToObject(data);
     System.out.println(entry);
} while (next == OperationStatus.SUCCESS);
the cursor goes through all data. It doesn't begin on the surname I posted...

Could you be more specific, perhaps with a concrete example? We're not sure what you are asking.
Thanks,
Linda

Similar Messages

  • Using Oracle Berkeley DB Java Edition RELEASE 3.2

    Hi,
    I am completely new to Oracle. I intend to use Oracle Berkeley DB Java Edition RELEASE 3.2., in conjunction with Java.
    Can some one help me figure out what documentation I should use, and the learning path ?
    Any suggestions would be greatly appreciated.
    Thanks
    Ravi Banthia
    Kolkata

    Please refer
    http://www.oracle.com/technology/products/berkeley-db/je/index.html

  • Use java edition and native edition at same time in a single java app

    Hi
    I have a situation where I need to use both versions of berkeley Db at the same time. I have an external library that I use that requires the Java edition and my own code that uses the native version. Unfortunately the source code of the library is not available and I don't want to redesign my program to use the Java edition.
    Some packages in je.4.0.103.jar and db.jar (version 5.1) contain the same naming structure and same classes eg. com.sleepycat.persist.EntityStore. I removed the duplicated packages in je.4.0.103.jar However it seems that the implementation is slightly different between the two version as I get
    java.lang.NoSuchMethodError: com.sleepycat.persist.EntityStore.<init>(Lcom/sleepycat/je/Environment;Ljava/lang/String;Lcom/sleepycat/persist/StoreConfig;)V
    When I simply had both versions available my code for the native version kept using the packages from the Java edition and the external library kept on using the native version and as a result I got loads of runtime errors.
    So how do I tell them apart. The problem is because both sets of packages have identical names and class names so Java does not know which ones to use. I am using eclipse so maybe there is some option where I can tell certain classes to use certain packages.
    Any ideas?

    Hi,
    We don't officially support using BDB and BDB JE from the same JVM process.
    It's possible to work around this limitation by creating two [url http://download.oracle.com/javase/1.4.2/docs/api/java/lang/ClassLoader.html] Java Classloaders  that load one of the two jar files. When calling BDB or BDB JE methods, the call must be bracketed with calls like this that cause the correct classloader to be used:
    ClassLoader saveLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(/* specify correct loader for BDB or BDB JE here */);
    try {
       // do something with BDB or BDB JE
    } finally {
      Thread.currentThread().setContextClassLoader(saveLoader);
    }We are not experts on classloaders and we don't have an example of doing this. We have not done it ourselves, we only know that users have done it.
    I hope this helps.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • Compatibility issues between Berkeley DB Java Edition and Berkeley DB

    We are trying to use both Berkeley DB Java Edition and Berkeley DB (Java/C) in one of our projects. However, they share the common classes (i.e. EntryDingin.java), but with their own different impementation. Is there any reason that they have to share the same names/packages? Can we request to have the shared java classes going into different packages?
    Thanks
    Yao

    Hello Yao,
    You're correct and the DB and JE products were not designed to run under the same classloader in the same JVM. It is very unlikely that we'll be changing the package names, since that would be very disruptive and yet have no value for the overwhelming majority of users. We will note your request, however, for future reference.
    The two workarounds I know of are:
    1. Use a separate classloader for the use of each product.
    2. Use a tool such as jarjar links (http://code.google.com/p/jarjar/) to rename the packages in one or both of the products.
    Option 2 is not something we (the JE team members) have experience with, but it was used successfully by a JE user. The user also pointed out a bug in the jarjar tool to be aware of: http://code.google.com/p/jarjar/issues/detail?id=21
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Wrong XQuery Launch Configuration in Jdeveloper Java Edition?

    Hi,
    i want to use xquery from JDeveloper Java Edition.
    I have a simple application with one project. I added the XML, XML schema and xquery feature my simple customer.xml and customer.xq
    Then i try to run customer.xq and get " java.lang.NoClassDefFoundError: oracle/xquery/XQException"
    In the log is a classpath that points to nowhere e.g. the classpath in the log shows C:\source\oracle_common\modules\oracle.xdk_11.1.0\xquery.jar but the real file is under c:\source\jdeveloper\modules\oracle.xdk_11.1.0
    where can i set the "oracle_common" path?
    I just unzipped the downloaded zipfile jdevjava11120.zip
    thanks
    steffen
    Edited by: Steffen on 30.08.2011 11:58

    Any suggestions?
    Maybe this is a Bug in the JDeveloper Release?
    It is the Generic Release Java Edition: 11.1.2.0.0 for Windows.
    Just unzipped it and set the MW_HOME var to my directory (no spaces in path).
    I need the xquery feature and dont want to install the big studio edition.

  • Can multiple threads share the same cursor in berkeley db java edition?

    We use berkeley db to store our path computation results. We now have two threads which need to retrieve records from database. Specifically, the first thread accesses the database from the very beginning and read a certain number of records. Then, the second thread needs to access the database and read the rest records starting from the position where the cursor stops in the first thread. But, now, I cannot let these two threads share the same cursor. So, I have to open the database separately in two threads and use individual cursor for each thread. This means I have to in the second thread let the cursor skip the first certain number of records and then read the rest records. However, in this way, it is a waste of time letting the second thread skip a certain of records. It will be ideal for us that the second thread can start reading the record just from the place where the first thread stops. Actually, I have tried using transactional cursor and wanted to let the two threads share the same transactional cursor. But it seems that this didn't work.
    Can anyone give any suggestion? Thank you so much!
    sgao

    If your question is really about using the BDB Java Edition product please post to the JE forum:
    Berkeley DB Java Edition
    If your question is about using the Java API of the BDB (C-based) product, then this is the correct forum.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Should i use the Java edition ?

    Hi,
    i'm not sure if i should use the Java edition or the "normal" edition of the berkeley db.
    My application is developed in Java, but i won't be using either JTA, JCA or JMX.
    Is there still any advantage to be taken from using the Java edition ?
    Thanks

    There are many minor differences, e.g., JE has somewhat better write performance, DB uses somewhat less memory, DB has an SQL interface and JE does not. But overall, the two products are very similar, so for most questions you might ask, the answer is going to be "about the same".
    If you want to choose the best product for your app, you'll have to define the very specific criteria that are most important to you. If you care most about getting every ounce of performance out of a specific piece of hardware, using a specific amount of memory, for a specific app (access pattern), then you'll have to write a test and do a comparison.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Using Berkeley Java Edition with Java Web Start

    Hi
    Have anyone had any experience using Berkeley Java Edition with Java Web Start?. I need to create an application that will download with the database to a client computer and create the database there

    Thanks for your reply Luca-Sanna,
    This is my jnlp file
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+" codebase="http://localhost:8080/dist" href="launch.jnlp">
    <information>
    <title>MyApplication</title>
    <vendor>My Company</vendor>
    <homepage href="/test.html"/>
    <description>My Test Application</description>
    <description kind="short">My Application</description>
    <icon href="test.gif" kind="default"/>
    <offline-allowed/>
    </information>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.5+"/>
    <jar href="myapp.jar" main="true" download="eager"/>
    <jar href="lib/appframework-1.0.3.jar" download="eager"/>
    <jar href="lib/beansbinding-1.2.1.jar" download="eager"/>
    <jar href="lib/commons-beanutils.jar" download="eager"/>
    <jar href="lib/commons-collections.jar" download="eager"/>
    <jar href="lib/commons-digester.jar" download="eager"/>
    <jar href="lib/commons-logging.jar" download="eager"/>
    <jar href="lib/derby.jar" download="eager"/>
    <jar href="lib/derbyclient.jar" download="eager"/>
    <jar href="lib/derbynet.jar" download="eager"/>
    <jar href="lib/itext-1.3.1.jar" download="eager"/>
    <jar href="lib/jasperreports-1.3.0.jar" download="eager"/>
    <jar href="lib/jbossall-client-2004-05-11.jar" download="eager"/>
    <jar href="lib/jdt-compiler-3.1.1.jar" download="eager"/>
    <jar href="lib/poi-2.0-final-20040126.jar" download="eager"/>
    <jar href="lib/swing-worker-1.1.jar" download="eager"/>
    <jar href="lib/toplink-essentials-agent.jar" download="eager"/>
    <jar href="lib/toplink-essentials.jar" download="eager"/>
    </resources>
    <application-desc main-class="mypackage.Login">
    </application-desc>
    </jnlp>
    I have seen many forums with the same above problem with no reply.
    Anyone knows what exactly the problem is?

  • Berkeley DB Java Edition (JE) and JRuby Interoperability

    I finally got around to doing a quick test of calling Berkeley DB Java Edition (JE) from JRuby (JRuby is a 100% pure-Java implementation of Ruby).
    Before we get to JE and JRuby you probably want to know the answer to this question: "Why you would want to run Ruby on a JVM?" The answer is threefold:
    1. Ruby Performance. A large amount of effort has been put into tuning contemporary JVMs (e.g. Hotspot, Java 6, etc.) and Ruby programmers (through JRuby) can benefit from these tuning efforts. The JRuby guys have set a goal to make JRuby the fastest Ruby implementation available and Sun is certainly throwing their weight behind that effort.
    2. Portability. JRuby is a Ruby interpreter that runs anywhere a Java 5 JVM runs. You download it as a single tar.gz and it will run pretty much anywhere.
    3. Legacy Code. JRuby makes legacy Java apps and libraries available to Ruby programmers (did you ever think you'd see the word "legacy" next to the word "Java"?).
    JE interoperability with JRuby is important because it means that Ruby programmers now have a simple, embeddable, ACID storage engine (JE) available to them.
    To test this interoperability, I cobbled together a simple Ruby test program which does the following:
    * Opens an Environment, Database, and Transaction
    * Creates 10 records with keys 1..10 and marshaled Ruby Time instances as the corresponding data. This uses the Ruby Marshal package for the data binding and the JE Integer binding on the key side. There's no reason why you couldn't use different marshaling packages or methods for keys and data.
    * Commits the transaction,
    * Performs a Cursor scan to read those 10 records and prints out the Time instances, and
    * Searches for and reads the record with key 5 (an arbitrary key) and prints out the Time instance that is the corresponding data
    By the way, hats off to the JRuby developers: all of this code "just worked", out of the box, and most of my two hour investment was spent learning enough basic Ruby to make it all work. If you already know Ruby and JE, then demonstrating this interoperability would take you all of about 10 minutes.
    This was all done at the "base API" level of JE and no modifications to JE were required. I used Transactions in my code, but there's no reason that you need to. Mark and I have been talking about how to integrate JE's Direct Persistence Layer (DPL) with JRuby and we think it can be done with some remodularization of some of the DPL code. This is exciting because it would provide POJO ACID persistence to Ruby programmers.
    Linda and I have been talking about whether it makes sense to possibly use Ruby as a scripting platform for JE in the future. Given how easy it was to bring up JE and JRuby, this certainly warrants some further thought.
    The Ruby code and corresponding output is shown below. By the way, if you see something that I didn't do "The Ruby Way", feel free to let me know.
    I'd love to hear about your experiences with JE and JRuby. Feel free to email me a charles.lamb at <theobviousdomain dot com>.
    require 'java'
    module JESimple
      require 'date'
      # Include all the Java and JE classes that we need.
      include_class 'java.io.File'
      include_class 'com.sleepycat.je.Cursor'
      include_class 'com.sleepycat.je.Database'
      include_class 'com.sleepycat.je.DatabaseConfig'
      include_class 'com.sleepycat.je.DatabaseEntry'
      include_class 'com.sleepycat.je.Environment'
      include_class 'com.sleepycat.je.EnvironmentConfig'
      include_class 'com.sleepycat.je.OperationStatus'
      include_class 'com.sleepycat.je.Transaction'
      include_class 'com.sleepycat.bind.tuple.IntegerBinding'
      include_class 'com.sleepycat.bind.tuple.StringBinding'
      # Create a JE Environment and Database.  Make them transactional.
      envConf = EnvironmentConfig.new()
      envConf.setAllowCreate(true)
      envConf.setTransactional(true)
      f = File.new('/export/home/cwl/work-jruby/JE')
      env = Environment.new(f, envConf);
      dbConf = DatabaseConfig.new()
      dbConf.setAllowCreate(true)
      dbConf.setSortedDuplicates(true)
      dbConf.setTransactional(true)
      db = env.openDatabase(nil, "fooDB", dbConf)
      # Create JE DatabaseEntry's for the key and data.
      key = DatabaseEntry.new()
      data = DatabaseEntry.new()
      # Begin a transaction
      txn = env.beginTransaction(nil, nil)
      # Write some simple marshaled strings to the database.  Use Ruby
      # Time just to demonstrate marshaling a random instance into JE.
      for i in (1..10)
        # For demonstration purposes, use JE's Binding for the key and
        # Ruby's Marshal package for the data.  There's no reason you
        # couldn't use JE's bindings for key and data or visa versa or
        # some other completely different binding.
        IntegerBinding.intToEntry(i, key)
        StringBinding.stringToEntry(Marshal.dump(Time.at(i * 3600 * 24)),
                                    data)
        status = db.put(txn, key, data)
        if (status != OperationStatus::SUCCESS)
          puts "Funky status on put #{status}"
        end
      end
      txn.commit()
      # Read back all of the records with a cursor scan.
      puts "Cursor Scan"
      c = db.openCursor(nil, nil)
      while (true) do
        status = c.getNext(key, data, nil)
        if (status != OperationStatus::SUCCESS)
          break
        end
        retKey = IntegerBinding.entryToInt(key)
        retData = Marshal.load(StringBinding.entryToString(data))
        dow =
        puts "#{retKey} => #{retData.strftime('%a %b %d')}"
      end
      c.close()
      # Read back the record with key 5.
      puts "\nSingle Record Retrieval"
      IntegerBinding.intToEntry(5, key)
      status = db.get(nil, key, data, nil)
      if (status != OperationStatus::SUCCESS)
        puts "Funky status on get #{status}"
      end
      retData = Marshal.load(StringBinding.entryToString(data))
      puts "5 => #{retData.strftime('%a %b %d')}"
      db.close
      env.close
    end
    Cursor Scan
    1 => Fri Jan 02
    2 => Sat Jan 03
    3 => Sun Jan 04
    4 => Mon Jan 05
    5 => Tue Jan 06
    6 => Wed Jan 07
    7 => Thu Jan 08
    8 => Fri Jan 09
    9 => Sat Jan 10
    10 => Sun Jan 11
    Single Record Retrieval
    5 => Tue Jan 06

    In my previous post (Berkeley DB Java Edition in JRuby), I showed an example of calling JE's base API layer and mentioned that Mark and I had been thinking about how to use the DPL from JRuby. Our ideal is to be able to define classes in Ruby, annotate those class definitions with DPL-like annotations, and have the JE DPL store them. There are a number of technical hurdles to overcome before we can do this. For instance, Ruby classes defined in JRuby do not map directly to underlying Java classes; instead they all appear as generic RubyObjects to a Java method. Granted, it would be possible for the DPL to fish out all of the fields from these classes using reflection, but presently it's just not set up to do that (hence the modification to the DPL that I spoke about in my previous blog entry). Furthermore, unlike Java, Ruby allows classes to change on the fly (add/remote new fields and methods) causing more heartburn for the DPL unless we required that only frozen Ruby classes could be stored persistently.
    On thinking about this some more, we realized that there may be a way to use the DPL from JRuby, albeit with some compromises. The key to this is that in JRuby, if a Java instance is passed back to the "Ruby side" (e.g. through a return value or by calling the constructor for a Java class), it remains a Java instance, even when passed around in JRuby (and eventually passed back into the "Java side"). So what if we require all persistent classes to be defined (i.e. annotated) on the Java side? That buys us the standard DPL annotations (effectively the DDL), freezes the classes that the DPL sees, and still lets us benefit from the POJO persistence of the DPL. All of this can be done without modification to JE or the DPL using the currently available release. I cooked up a quick example that builds on the standard "Person" example in the DPL doc and included the code below.
    require 'java'
    module DPL
      require 'date'
      # Include all the Java and JE classes that we need.
      include_class 'java.io.File'
      include_class 'com.sleepycat.je.Environment'
      include_class 'com.sleepycat.je.EnvironmentConfig'
      include_class 'com.sleepycat.persist.EntityCursor'
      include_class 'com.sleepycat.persist.EntityIndex'
      include_class 'com.sleepycat.persist.EntityStore'
      include_class 'com.sleepycat.persist.PrimaryIndex'
      include_class 'com.sleepycat.persist.SecondaryIndex'
      include_class 'com.sleepycat.persist.StoreConfig'
      include_class 'com.sleepycat.persist.model.Entity'
      include_class 'com.sleepycat.persist.model.Persistent'
      include_class 'com.sleepycat.persist.model.PrimaryKey'
      include_class 'com.sleepycat.persist.model.SecondaryKey'
      include_class 'com.sleepycat.persist.model.DeleteAction'
      include_class 'persist.Person'
      include_class 'persist.PersonExample'
      # Create a JE Environment and Database.  Make them transactional.
      envConf = EnvironmentConfig.new()
      envConf.setAllowCreate(true)
      envConf.setTransactional(true)
      f = File.new('/export/home/cwl/work-jruby/JE')
      env = Environment.new(f, envConf);
      # Open a transactional entity store.
      storeConfig = StoreConfig.new();
      storeConfig.setAllowCreate(true);
      storeConfig.setTransactional(true);
      store = EntityStore.new(env, "PersonStore", storeConfig);
      class PersonAccessor
        attr_accessor :personBySsn, :personByParentSsn
        def init(store)
          stringClass = java.lang.Class.forName('java.lang.String')
          personClass = java.lang.Class.forName('persist.Person')
          @personBySsn = store.getPrimaryIndex(stringClass, personClass)
          @personByParentSsn =
            store.getSecondaryIndex(@personBySsn, stringClass, "parentSsn");
        end
      end
      dao = PersonAccessor.new(store)
      dao.init(store)
      personBySsn = dao.personBySsn
      person = Person.new('Bob Smith', '111-11-1111', nil)
      personBySsn.put(person);
      person = Person.new('Mary Smith', '333-33-3333', '111-11-1111')
      personBySsn.put(person);
      person = Person.new('Jack Smith', '222-22-2222', '111-11-1111')
      personBySsn.put(person);
      # Get Bob by primary key using the primary index.
      bob = personBySsn.get("111-11-1111")
      puts "Lookup of Bob => #{bob.name}, #{bob.ssn}"
      children = dao.personByParentSsn.subIndex(bob.ssn).entities()
      puts "\nRetrieving children of Bob"
      while (true) do
        child = children.next()
        break if child == nil
        puts "#{child.name}, #{child.ssn}"
      end
      children.close()
      store.close
      env.close
    end

  • Please reply:how to avoid extra trailing spaces while using cursor sharing

    i am using cursor sharing with FORCE or SIMILAR.
    what is the solution to avoid extra trailing spaces without any java code change.
    do we have any option in oracle to avoid extra trailing spaces during the query processing ?
    I am using Oracle 10g
    CURSOR SHARING is a feature in which multiple sql statements
    which are same will have a shared cursor (in the library cache) for an oracle session,
    i.e, the first three steps of the sql processing (hard parse, soft parse, optimization)
    will be done only the first time that kind of statement is executed.
    There are two ways in which similar SQL statements with different condition values can be made to "SHARE" cursor during execution:
    1. Writing SQLs with Bind Variables: SQLs having no hard coded literals in them
    For e.g., the query below
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = :1
    AND dept_no =
    DECODE (SUBSTR (:2, 1, 3),
    :3, :4,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :5 AND dept_no <= :6)
    AND node.dept_type = :7
    ORDER BY node.emp_name
    Here all the variables are dynamically bound during the execution. The ":X" represents BIND Variable and the actual values are bound to the SQL only at the 4th step of the execution of the SQL.
    In applications: The queries written with "?" as bind variables will be converted into ":X" and are sqls with Bind Variables.
    2. The CURSOR_SHARING parameter: Only Useful for SQL statements containing literals:
    For eg., the query below:
    SELECT node.emp_name AS configid
    FROM emp node
    WHERE emp_no = 'H200'
    AND dept_no =
    DECODE (SUBSTR (:1, 1, 3),
    'PLN', :2,
    (SELECT MAX (dept_no)
    FROM emp
    WHERE emp_no = :3 AND dept_no <= :4)
    AND node.dept_type = :5
    ORDER BY node.emp_name
    In the query above, there are two hard coded literals H200 , PLN. In this case when the same SQL executed with different values like (H2003 , PLN), oracle will create a new cursor for this statement and all the first three steps ( hard & soft parse and optimization plan) needs to be done again.
    This can be avoided by changing the CURSOR_SHARING parameter which can be set to any of three values:
    1. EXACT: Causes the mechanism not be used, i.e. no cursor sharing for statements with different literals. This is the default value.
    2. FORCE: Causes unconditional sharing of SQL statements that only differ in literals.
    3. SIMILAR: Causes cursor sharing to take place when this is known not to have any impact on optimization.
    So, FORCE and SIMILAR values of the parameter will be helping in cursor sharing and improve the performance of the SQLs having literals.
    But here the problem arises if we use the FORCE and SIMILAR other than EXACT.
    alter session set cursor_sharing ='EXACT'
    select 1 from dual;
    '1'
    1
    alter session set curson_sharing='FORCE'
    select 2 from dual;
    '2'
    2
    alter session set curson_sharing='SIMILAR'
    select 3 from dual;
    '3'
    3
    So, this will give extra trailing spaces in when we retrieve from java method and any
    further java processing based on the hardcoded literal values will fail. this needs lot of
    effort in remodifying the existing millions of lines of code.
    My question is i have to use cursor sharing with FORCE or SIMILAR and can't we do the trimming
    from the oracle query processing level ?
    please help me on this ?
    Message was edited by:
    Leeladhar
    Message was edited by:
    Leeladhar

    Please reply to this thread
    How to avoid extr trailing spaces using Cursor sharing opton FORCE, SIMILAR

  • Need using cursor for query

    Hi all,
    can anybody tell me how to get the result of the following query by using cursor?
    SELECT (SUBSTR('        ', 1,LEVEL*2)
      || t1.label) AS t1_label,
      amount
    FROM
      (SELECT t1.label,
        t1.ID,
        t1.parent_id,
        SUM(t2.turnover) AS amount
      FROM t1,
        t2
      WHERE t2.t1_id = t1.id
      AND t2.t1_id  IN
        (SELECT id
        FROM t1
          START WITH t1.ID       = 2
          CONNECT BY PRIOR t1.ID = t1.parent_id
      GROUP BY t1.label, t1.ID, t1.parent_id
      ) t1
      START WITH t1.ID       = 2
      CONNECT BY PRIOR t1.ID = t1.parent_id;...and the result:
    t1_label             amount
         B11     11778.54
          B121     19980.28
            B1211     18842.77
            B1212     25480.56
          B122     18339.07
        B12            23455.9
        B13            20876.52Thanks,
    Alex
    Edited by: 860003 on Jun 9, 2011 1:30 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM

    860003 wrote:
    Is not that i don't want to use hierarchy queries, but find others ways, tricks to reach the result needed. I just want to explore different ways that Oracle provides to resolve issues.Not a problem with that in principle.
    Maybe using "loop, if-else, for" will provide us with an elegant way to get the result. However, a problem in principle with this. SQL and PL/SQL are not the same thing. Two separate and very different languages.
    In PL/SQL, you can code both PL and SQL - so you can write source code of 2 different language and mix these. The PL/SQL parser is clever enough to figure out what is what and glues the code seamlessly and transparently together.
    SQL is used to crunch SQL data. PL/SQL sucks at this in comparison (and Java/.Net sucks a heck of a lot worse at this). Cursor fetch loops? Bulk processing. Neat. But will always be slower than running that data crunching in SQL only.
    That is why there is a simple maxim for performance in Oracle: Maximise SQL. Minimise PL/SQL.
    Do not use PL/SQL to do what the SQL is perfectly able and capable of doing. The exception is when the processing is too complex for SQL to handle and you need the programming logic part of the PL/SQL language.
    My question is how to use this cursor to get the value, fetch it and then get another value(ofc only for the children) and fetch it again so i can output it? I thing this can be achieve but don't know how.All SQLs (and anonymous PL/SQL) are parsed and cursors are created. A cursor is a basically a set of instructions (as seen via execution plans) of how to get the job done. Think of cursors as programs that are executed and output data.
    So do you want t create a bunch of cursors (programs) and then call these from PL/SQL, consume their output, create/call new cursor programs and repeat?
    Or do you want to create a single cursor program that does the job and outputs the required results?
    Maximise SQL. Minimise PL/SQL.

  • Generate report using CURSORS? - Simple question

    Folks,
    I'm a real newbie still with PL/SQL so please excuse my ignorance I have a simple report I need to generate. The following SQL statement gets me all my "header" records:
    SELECT OHA.ORDER_NUMBER, HEADER_ID, ATT11, ATT12, ATT16
    FROM XXXWD.WD_DUPS DUPS, OE_ORDER_HEADERS_ALL OHA
    WHERE OHA.ATTRIBUTE11 = DUPS.ATT11
    AND OHA.ATTRIBUTE12 = DUPS.ATT12
    AND OHA.ATTRIBUTE16 = DUPS.ATT16
    AND (OHA.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED'))
    AND (ATT11 <> 'WESTERN SERVICE')
    ORDER BY ATT11, ATT12, ATT16
    What I want to do now is have a second script that will display all my detail records. Something like:
    SELECT OLA.LINE_NUMBER, OLA.ORDERED_ITEM, OLA.FLOW_STATUS_CODE
    FROM OE.ORDER_LINES_ALL OLA
    WHERE OLA.HEADER_ID = OHA.HEADER_ID
    I expect I'd do this with two cursors, passing the value of my HEADER_ID to my second cursor. But when I've used cursors before, they primarily have been to import data, and manipulate data. But what if I just want to create a report using these?
    I essentially want to display my header information, and then any lines below that data (if there is any, there may be a header with no lines).
    Can I create a simple report like this with cursors? Any help with this would be IMMENSELY appreciated. I'm really under the gun... :)
    Thanks so much!
    Steve

    Here's one query that will give you everything:
    SELECT OHA.ORDER_NUMBER
          ,OHA.HEADER_ID
          ,DUPS.ATT11
          ,DUPS.ATT12
          ,DUPS.ATT16
          ,OLA.LINE_NUMBER
          ,OLA.ORDERED_ITEM
          ,OLA.FLOW_STATUS_CODE     
    FROM   XXXWD.WD_DUPS        DUPS
          ,OE_ORDER_HEADERS_ALL OHA
          ,OE.ORDER_LINES_ALL   OLA
    WHERE  OLA.HEADER_ID   = OHA.HEADER_ID
    AND    OHA.ATTRIBUTE11 = DUPS.ATT11
    AND    OHA.ATTRIBUTE12 = DUPS.ATT12
    AND    OHA.ATTRIBUTE16 = DUPS.ATT16
    AND    OHA.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED')
    AND    DUPS.ATT11 <> 'WESTERN SERVICE'
    ORDER  BY OHA.ORDER_NUMBER
             ,OLA.LINE_NUMBER
             ,DUPS.ATT11
             ,DUPS.ATT12
             ,DUPS.ATT16
    ;(correction in order by clause)
    Message was edited by:
    Eric H

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Java edition compatible with standard edition?

    Hi
    I have a database created using Java edition 3.2.44
    I want to write an application in C++ which reads this database using the standard Berkeley DB (possibly at the same time as the java application is also accessing them). Are the database files compatible?
    I'm not too hopeful since the the database files are named something like 00000000.jdb and je.lck.
    Any help appreciated
    Nick

    Hi Nick,
    This FAQ entry addresses this question:
    [http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#2|http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#2]
    (a small additional information to this entry is that DPL API has been introduced for BDB as well in 4.7.25)
    As explained, the on-disk format for the database files is different. You should dump the database created with JE (using the DbDump/com.sleepycat.je.util.DbDump utility: [http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/je/util/DbDump.html|http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/je/util/DbDump.html]) and load it using BDB before opening it in a a program using one of the BDB APIs (using the db_load utility: [http://www.oracle.com/technology/documentation/berkeley-db/db/utility/db_load.html|http://www.oracle.com/technology/documentation/berkeley-db/db/utility/db_load.html] )
    If you face any issues with dumping/loading the database let me know.
    Regards,
    Andrei

  • DB High Availability - Java Edition

    I am using Berkeley DB Java Edition to do writes and reads to my database. I am planning on having a cluster of databases with HA feature. I noticed that the feature set for Berkeley DB Java Editon does not include High Availabilty.
    I did check the C example code that is available in the 4.4 version. I understand that I need to build a communication infrastructure in Java for master and replicated db's. Is there any example that I can follow, or any other materials available for doing HA in Java?

    I believe the answer in java replication example is relevant for you.
    <p>
    Please note that you should be able to build the communication infrastructure in C, and then still access DB via the Java interface layer from your Java program. (I.e., your communication infrastructure doesn't have to be in Java.)
    <p>
    Also, I hope it's clear that Berkeley DB Java Edition is a separate product. This is different from using Berkeley DB via its Java interface layer.
    <p>
    Alan Bram<br>
    Oracle

Maybe you are looking for

  • Never had such bad support - Think(g)s have changed since IBM

    I just wanted to point out that lenovo has one of the worst support i ever had with businnes products. I was always a thinkpad buyer and spend a lot of money to ibm. OS updates went well and the hardware compatibility was good. I always used the supp

  • RFC to soap with attachment

    Hi all, I need to implement a synchronous scenario where an R/3 system sends data via RFC to an external system that expects it in the format of soap with attachment. Then the external system responds with soap message without attachment. My main con

  • Song doesn't show I can buy ringtone.

    Hi! I downloaded a song that I wanted as a ringtone and when I go to my library and find the song it doesn't say that I can use it as a ring tone (the little bell isn't there). Am I doing something wrong or can anyone give me some advice on how to do

  • Merging two lists?

    I need to know if it is possible to merge two lists using coldfusion.  I have one list uploaded to the site then they want the ability to upload a second list with may have additional fields and/or different number of records.  Need to know if this i

  • Pictures Taken Not Stored

    Anyone know how to have the Camera Roll folder on my iPhone store the photos I take and not crash to the iPhone default home menu when I click on it in the sunflower icon'd Photos menu? Background: I've been using I think it is Adobe Photos Starter E