Create a cursor from a PL/SQL variable or an external file

Dear friends,
is there a way for me to make Oracle Forms read a cursor from a PL/SQL variable, or an external file? Let's suppose we have the code below:
DECLARE
cursor c_values is select * from my_table;
r_values c_values%ROWTYPE;
BEGIN
for r_values in c_values loop
do_something;
end loop;
END;
In the situation described above, could I create "select * from my_table" from a PL/SQL variable (it could be something like p_cursor = 'select * from my_table'), or an external file - for example, make my form read the contents of c:\my_select.sql , where we see the "select * from my table" text?
My question comes because I need to export data from select instructions that were dinamically created inside the form - that is, via PL/SQL -, and I don't want to rewrite it, but I'll have to do it if I have no choice. Your help will be greatly appreciated.
Best regards,
Franklin
Edited by: franklinbrasil on 12/03/2009 11:33
Edited by: franklinbrasil on 12/03/2009 11:35

Dear friends,
I am using DBMS_SQL package, which solved my problem. Please let me explain it better, if it's not clear.
I have some PL/SQL blocks inside my form, which creates SQL queries dinamically, and a dinamically created SQL is stored into a VARCHAR2 variable. These SQL queries are exported for use in Oracle Graphics, but since OG is not being developed by Oracle anymore then I am trying to find a substitute for it.
So I thought about creating an option for the final user: he/she can choose exporting data into Microsoft Excel, and user does what he/she wants, creating a customized graphic. Exporting into Excel works finely, with no problems at all - I could find a routine by searching on the web.
My goal was to use the same queries created above to export data dinamically to Microsoft Excel, and I absolutely don't want to rewrite all these dinamically created queries - one which works dinamically, other with no flexibility inside my form. Worse than it, I have many other dinamically created queries, and I obviously don't want to rewrite them all - any maintenance in this form would be terrible, with each SQL instruction written twice.
Since all dinamically created SQL instructions are stored inside a VARCHAR2 variable, I thought about reusing the same SQL, as explained above - and here we have your suggestions about using a ref cursor, execute immediate, and so on. And (answering Andreas) query structure is always based on the same table, but its structure changes a lot, depending on what the final user chooses in a drop-down list (it's a list of graphics options, where final user chooses one option, and form must mount SQL dinamically, based on user's choice).
By using your explanations, I could find DBMS_SQL solution here: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg09dyn.htm#26799
. Please notice that I had to change DBMS_SQL.native into 1 for it to work in my form. I'll mark all your answers as helpful because I can use them both for database and form purposes.
If my message was not clear enough, please tell me and I'll try to make it more clear.
Best regards,
Franklin

Similar Messages

  • How to create database link from oracle to sql server

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal

    Please help with how to create database link from oracle to sql server
    Best regards,
    Vishal
    Hi Vishal,
    I found a lof of information regarding how to create a database link from Oracle to SQL Server, please see:
    https://www.google.co.in/?gws_rd=cr&ei=vd3XUvGFO8TgkAXqlYCADg#q=how+to+create+database+link+from+oracle+to+sql+server
    We discuss SQL Server related issue in this forum. If you have any more question regarding Oracle, please post it in Oracle communities forum for better support.
    Regards,
    Elvis Long
    TechNet Community Support

  • How to create ICon/Cursor from pdf files

         I was able to create ICon from jpg file without problem but I couldn't create ICon from pdf files.
    Here my code:
    var myDoc = app.newDoc();
    myDoc.importIcon("myIcon"); // it worked when I chose a jpeg image, but it didn't
    //when chose a pdf file.
    icon = myDoc.getIcon("myIcon");
    oIcon = util.iconStreamFromIcon(icon);  
    myDoc.closeDoc(true);
    app.addToolButton({
                   cName: "myButtoon",
                   oIcon: oIcon,
                   cExec: "app.alert('Someone pressed me!')",
                   cTooltext: "Push Me!",
                   cEnable: true,     
                   nPos: 4
       //app.removeToolButton("myButtoon");
    My goal is to create buttons which have icons from a pdf file (stamp) and when user click on these buttons, the cursors become the icon . And then, when user click on the document, the iCon will be showed in the document. The point is: is there anyway to create icons/cursors/stamps from one pdf file. Because the stamp is changeable, when user changes the color/shape of the pdf file, the icons/cursors/stamps will automatically change
    What kind of pdf format do I have to use?
    I used the sample "SignHere.pdf" in stamps folder of Acrobat but it didn't work.
    Thanks.

    The SDK has all the information - but certainly there are only samples for those common actions that users have been doing for years.  Most developers don't recreate stuff already present in the application - such as the Stamp plugin - so we don't have samples of such things.
    But all the pieces you need are present in the SDK - it's just necessary obvious.  You will need to learn about the details of how the plugin APIs work to create the toolbars and toolbuttons, and then how to handle cursors.  You will then need to learn about PDF details in order to be able to take an existing PDF, potentially modify it (eg. Change the color(s)) and then place it onto another PDF.  
    The methods you listed are from JavaScript - there are alternative methods for plugins, such as the AVConversion APIs.

  • Create Trigger (PK from Sequence) in SQL Developer 1.5.1

    Hi all
    I'm new to Oracle and am trying to create the equivalent of an autonumber field on a table using the Create Trigger (PK from Sequence) option (by right clicking on a table in SQL Developer).
    I've set up a sequence called REQUESTID and when using the above option it generates the following SQL:
    begin
    execute immediate 'create or replace trigger AutoNumber '||
         ' before insert on "REQUEST" '||
         ' for each row '||
         'begin '||
         ' if inserting then '||
         ' if :NEW."REQUESTID" is null then '||
         ' select REQUESTID.nextval into :NEW."REQUESTID" from dual; '||
         ' end if; '||
         ' end if; '||
         'end;';
         end;
    When I click Apply I get an ORA-00942 (table or view does not exist). Am I doing something daft here?

    Never mind - sorted it - I created the table under a different Schema to the System login being used in SQL Developer and so didn't have the permissions to create the trigger on the table.

  • Creating Database Link from Oracle to SQL Server

    I am trying to create a database link from Oracle to SQL Server, and the documentation is about as clear as mud to me. Can anyone send me clear instructions on exactly what I need to do? What needs to be in tnsnames.ora and listener.ora files? Is there anything other than those two files that needs to be set up? Do I set up an ODBC connection? Anything else? I want to execute queries against a SQL Server database and load data into Oracle database.
    Thanks so much,
    Susan

    These are the instructions from an old document I created. The steps are same for SQL Server and Sybase. Hope it helps.
    The 9i Transparent Gateway Software is in Oracle Software CD -> oracle9i database -> Custom -> Oracle Transparent Gateways
    The gateway can be installed on the same machine as the Oracle database or
    on the Sybase server or on a third machine as a stand-alone.
    We have installed the gateway software in one of oracle database
    servers in a separate oracle home.
    These are the steps involved in configuring a gateway to a Sybase database
    1.     Install Sybase client and Gateway software on the Gateway Server
    2.     Configure <initsidfile> in the Gateway Server's <gatewayhome>
         /u00/app/oracle/product/9.2.0/tg4sybs/admin/init<gatewaysid>.ora
    Sybase server and database information is required for this step.
    eg: HS_FDS_CONNECT_INFO=USTRUD01.uwd
    3.     Add an entry in listener.ora in <listnenerhome>
         (/u00/app/oracle/product/9.0.1/network/admin/listener.ora) for the <gatewaysid>
    4.     Edit the tnsnames file (/u00/app/oracle/product/9.0.1/network/admin/tnsnames.ora)
    to add an entry <tnsalias> for the <gatewaysid>
    5.     Create a database link to the Sybase database in the oracle database.
    The steps for creating the database link are
    a. create a login oracle_tgw in the sybase server
    b. add the user to the sybase database with the necessary privilege on the tables
    c. create the database link in the required oracle database using the command
         "create public database link <dblinkname> connect to oracle_tgw identified by password using 'tnsalias'; "
    6.     Restart the gateway listener.

  • Create a dvd from past project and event moved to external hard drive

    i have version 7.04 DVD. Moved several projects and events to external hard drive. How do I go to "existing dvd projects" and create a dvd from a completed past dvd project? do i have to move the project and event back to the iMac hard drive..thanks

    A iDVD project contain links to the various elements you have used to make the project. Unless you have actually saved the project as an iDVD Project Archive (an option under FILE in iDVD) which can be a very large file because it actually contains all the elements used in the project with adjusted links, simply moving a project (and/or elements used in the project) breaks all the necessary links. Sometimes you can reestablish the links (iDVD usually gives you a chance to try), but it can't always be done.
    Good luck.

  • How to descrbe a ref cursor from a PL/SQL prog?

    Hi,
    here is a sample of the my problem
    let suppose a table country :
    create table country(country_code VARCHAR2(3), country_name VARCHAR2(50));
    then a package containing different procedures among them, this one :
    PL/SQL prog
    create or replace package country_pkg as
    type rec1 is ref cursor return country%rowtype;
    Procedure get_all_countries(rec in out rec1);
    blablabla ...
    END country_pkg;
    in the package body, i have the following code :
    create or replace package body country_pkg as
    procedure get_all_countries(rec IN OUT rec1) is
    begin
    if not rec%open then
    open rec for select * from country order by country_name;
    end if;
    exception
    when NO_DATA_FOUND then
    close rec;
    end get_all_countries;
    blablabla....
    end;
    Then in the C program
    (*proc)->request->command = "begin get_all_countries(:rec); end;"
    checkerr(&connect, \
         OCIStmtPrepare(connect->stmthp,\
         connect->errhp,\
         (*proc)->request->command,\
         strlen((*proc)->request->command),\
         OCI_NTV_SYNTAX, OCI_DEFAULT));
    checkerr(&connect, \
         OCIHandleAlloc((dvoid*)(connect->envhp),\
         (dvoid**) &((*proc)->stmthp), OCI_HTYPE_STMT,
    (size_t) 0,\
         (dvoid**) 0));
    bndhp = (OCIBind**) g_malloc0((*proc)->argnum*sizeof(OCIBind*));
    for(i = 0; i < (*proc)->argnum; i++)
    switch ((*proc)->desc->type)
    case 102:
    checkerr(&connect,
    OCIBindByPos(connect->stmthp, &bndhp[j],
    connect->errhp,
         i+1,&((*proc)->stmthp), (sb4) 0,
         SQLT_REF, (dvoid*) 0, (ub2*) 0, (ub2*) 0,
    (ub4) 0,
         (ub4*) 0, (ub4) OCI_DEFAULT));
    default:
    some code ....
    checkerr(&connect, \
         OCIStmtExecute(connect->svchp, connect->stmthp,\
         connect->errhp, 1, (ub4) 0, (OCISnapshot*) 0,\
         (OCISnapshot*) 0, OCI_DEFAULT));
    parm_status = OCIParamGet(connect->stmthp, OCI_HTYPE_STMT,connect->errhp, (dvoid**)&arg, 0);
    while(parm_status == OCI_SUCCESS)
    OCIAttrGet((dvoid*) arg, OCI_DTYPE_PARAM,
    (dvoid*)type,0, (ub4) OCI_ATTR_NUM_PARAMS,
    connect->errhp);
    counter++;
    parm_status = OCIParamGet(connect->stmthp,
    OCII_HTYPE_STMT,connect->errhp,
    (dvoid**)&arg, counter);
    This piece of code doesn't work as 'arg' is always NULL
    and OCIParamGet retruns OCI_SUCCESS.
    I'm certainly missing something but I don't see what. Could anyone help me to get that piece of code working?
    regards,
    Raphael

    unfortunately, not yet!
    I dropped the matter for now, I'll come back on it later.
    On your side, let me know if you find something interesting on that topic by posting a message here.

  • Creating Database link from Oracle9i to SQL server 2000

    Pls how do I create connectivity from Oracle9i database to query a table in an SQL server 2000 database.
    Pls I need the necessary steps to take.
    Thanx

    There are 2 solutions that you can use:
    1) Transparent Gateway for SQL Server
    2) Generic Connectivity
    Generic Connectivity is free with the database but has less features than the Gateway. For Generic Connectivity you will need to obtain an ODBC driver.
    The steps for using the gateway are available in the gateway manual and the steps for using Generic Connectivity is available in Chap 7 of the Heterogeneous Connectivity Administrator's Guide.

  • Q: NULL return REF CURSOR from a PL/SQL function

    I was told that PL/SQL does not handle properly NULL REF CURSORS.
    Here's my implementation in a PL/SQL package
    PACKAGE SPEC:
    TYPE z_rec IS RECORD (
    TYPE z_cur IS REF CUR RETURN z_rec;
    FUNCTION some_function(
    p_msg OUT VARCHAR2)
    RETURN z_cur;
    PACKAGE BODY:
    FUNCTION some_function(
    p_msg OUT VARCHAR2)
    RETURN z_cur
    IS
    retval z_cur;
    OPEN retval FOR
    SELECT ...
    -- Successfull data retrieval
    p_msg := NULL;
    RETURN retval;
    EXCEPTION
    WHEN OTHERS THEN
    p_msg := SUBSTR( SQLERRM, 1, 255 );
    RETURN NULL;
    END some_function;
    I am expecting that a user of this function would call it and test p_msg (output parameter)
    1. IS NULL p_msg it means there were no errors encounetered. The returned cursor can be NULL though (i.e. no records retrieved)
    2. IS NOT NULL p_msg, it means that there were errors and the returned cursor is not usable.
    My question is:
    what are the pitfalls of this approach?
    Thanks a lot.

    user10817976 wrote:
    I asked and still waiting for the answer.
    retval z_cur;
    What I am afraid for is that
    OPEN retval FOR
    SELECT ...
    EXCEPTION
    retval := NULL;
    tries to open the cursor. What happens in case of error? Well, I imagine retval is still NULL. Do I need to (try) to close the cursor in the EXCEPTION section (in order not to misuse the number of cursors in the pool?) That's my worry.No.
    If there is an error opening the cursor the cursor will not be open and will not need closing.
    The code should simply be
    function some_function
        return z_cur
    is
        retval z_cur;
    begin
        open retval for
            select ...
        return retval;
    end some_function;        It is bad practice for a function to have output parameters.
    It is bad practice to turn exceptions into return codes.
    http://tkyte.blogspot.com/2008/06/when-others-then-null-redux.html
    Remember everyone, everyone remember, keep in mind:
    When others not followed by RAISE or RAISE_APPLICATION_ERROR is almost certainly, with 99.999999999% degree of accuracy, a bug in your developed code. Just say "no" to when others not followed by raise or raise_application_error!Read the links, it leads to problems over and over again.

  • Creating new projects from old ones without deleting the wrong audio files!

    We did a piano & vocal recording session recently and recorded about a dozen songs. Voice audio files and midi (pianoteq) for piano. At the moment these are organised into three projects according to genre - classical, showtunes and jazz standards. I now want to get each song into its own separate project but while I need to avoid duplicating too many audio files, I'm also scared to death of deleting anything!
    Can someone please walk me through how I do this? I THOUGHT I knew and then a dialogue box (thankfully!!) flashed up saying something like, "Are you sure you want to delete these files they are shared by other projects?"
    I basically want to "save as" one of the large projects, rename it according to the song title and then delete the other songs from the Arrange. I thought I could then "select unused" in the Audio Bin and it would be cool because the original audio would be in the old (renamed) project . . . but I seem to have that wrong? Or I've missed a step?
    Hopefully someone can shed some light!

    Open the song. Cut the tracks at the appropriate places. Name the newly created regions with the correct song names. Select all the regions and then the command that turns the regions into new individual audio files. After the files are written, go into the audio bin and select unused. Delete unused. Save as (without resources) "Master Song". Then I'd delete all but the first pair of tracks from the arrangement. In the audio bin select unused again then delete. Logic will dump the unused parts out of the audio bin without deleting them from the drive. save as "First song" Re-open the master song and do this again with the second set of tracks.......

  • Create test sequence from lab view - add it to the .seq file

    Hello All,
                   I have a query. consider an test sequence that has already stored in "Test.seq" format. let us say we have 5 test steps.
    now is it possible to add a new test step to this existing test sequence using Lab VIEW. I mean if we enter a new test step this has to reflect in the existing test sequence "Test.seq".  i.e in the "Test.seq" we must have 6 test steps.
      If this is possible let me know how this can be done. 

    Michels,
    Guenter mande a very good point.  Make sure to take a look at the forum thread he linked to see the licensing implications of creating your own Sequences.
    There is a very good forum thread that discusses how to create steps programmatically.  You can find the forum here:
    http://forums.ni.com/ni/board/message?board.id=330&message.id=7785&requireLogin=False
    Regards,
    Santiago D

  • Is it possible to create a link from a picture's metadata to a test file?

    Hi everyone,
    I am looking for a way to get a direct link to the picture's deposited right of utilisation. I prefer a link in the picture's meta data to a text file - e.g. pdf or doc. Is that possible?
    PC with Lightroom5.
    Thanks a lot for help!

    To build on Ian's suggestion, you can include URLs to files on the computer, e.g.
    An easy way to construct such a URL is to go to your browser, give the Open File command (in Chrome, it's File > Open File), and then browse to the desired file.  The browser will open the file, and you can copy the URL from its address bar.
    If you don't like using the IPTC:Website field for this purpose, or if you want more than one field in which to store URLs, I think the Custom Metadata plugin would provide that capability. The author is very helpful and a frequent contributor here.
    Finally, you might consider my Any File plugin.  It lets you directly import files of any type into your catalog.  For example, you could import the release PDFs for an image and stack the release and the image together.

  • Declare Cursor from variable

    Hi,
    on an APEX page I can create a cursor from an item like this:
    cursor c is &P999_SQL_QUERY.;
    and there are no problems.
    Now I want to do the same in a procedure, but how could that be done?
    I pass the sql-Statement as a VARCHAR2 variable to the procedure, but I do not know how I can do that. I am not familar with bind variables or something like that.
    Can anyone help me please?
    Thank you,
    Tim

    > on an APEX page I can create a cursor from an item like this:
    cursor c is &P999_SQL_QUERY.;
    and there are no problems.
    Except for the very real and harsh danger of SQL injection. Pardon for being blunt, but code like that is bloody dangerous and IMO quite silly.
    > Now I want to do the same in a procedure, but how could that be done?
    You have created an anonymous PL/SQL block that are parsed and compiled at run-time (with APEX PL/SQL code doing the deed).
    You can do the same thing manually in PL/SQL writing your own code to perform this deed.
    It will however be equally dangerous and silly to do.

  • Create cursor from another cursor

    Hello,
    How do I create a cursor from the values of another cursor ?
    For Example,
    cursor c1
    select x, y from table 1;
    cursor c2
    select c1.x, c1.y, table 2.z
    from table 2
    where y := c1.y
    I get errors when I do this way. Can somebody help me out on this.
    Thanks
    Raj

    In this particular example, it's probably easiest to declare a single cursor that contains a join, i.e.
    cursor c1
    SELECT a.x, a.y, b.z
      FROM table1 a,
           table2 b
    WHERE a.y = b.yIf you really want to create the two cursors, though, you have to make sure that the first cursor is visible to the creation statement of the second. For example,
    for c1 in (select x, y from table1)
    loop
      for c2 in (select c1.x, c1.y, b.z from table2 b where b.y = c1.y)
      loop
      end loop;
    end loop;If you need more help, quoting the exact error an providing a snippet of the code you're using would be greatly helpful.
    Justin

  • Oracle DB Link from Oracle to SQL Server

    Dear buddies,
    I am trying to create a dblink from Oracle to SQL Server.
    This is my tnsnames.ora
    sq =
    (DESCRIPTION=
       (ADDRESS=(PROTOCOL=tcp)(HOST=LOCALHOST)(PORT=1521)
       (CONNECT_DATA=(SID=sq))
       (HS=OK)
    )This is my listener
    SID_LIST_LISTENER =
      (SID_LIST =
          (SID_DESC =
          (SID_NAME = sq)
          (ORACLE_HOME = D:\oracle\product\10.2.0\db_2)
          (PROGRAM = hsodbc)
    LISTENER =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      )initsq.ora
    # This is a sample agent init file that contains the HS parameters that are
    # needed for an ODBC Agent.
    # HS init parameters
    HS_FDS_CONNECT_INFO = sq
    HS_FDS_TRACE_LEVEL  = OFF
    # Environment variables required for the non-Oracle system
    #set <envvar>=<value>I have created my System DSN for sq with the appropriate values which works fine when I tested the connection.
    These 2 databases are in different servers.
    This is how I created the db link in Oracle
    create public database link sq
    CONNECT TO XXX IDENTIFIED BY "XXX"
    using 'sq'
    select "Column1"
    from "Table1"@'sq';The error I receive is: ORA-01729: database link name expected
    When I try to recreate the database link it tells me that: ORA-02011: duplicate database link name
    I hope someone could guide me.
    Thanks.

    C:\Documents and Settings\Administrator>tnsping sq
    TNS Ping Utility for 32-bit Windows: Version 10.2.0.4.0 - Production on 16-AUG-2011 14:48:40
    Copyright (c) 1997,  2007, Oracle.  All rights reserved.
    Used parameter files:
    D:\oracle\product\10.2.0\db_2\network\admin\sqlnet.ora
    TNS-03505: Failed to resolve name
    C:\Documents and Settings\Administrator>

Maybe you are looking for