Dynamic cursors in pro*c

Please, what I need to do in order to be able
to do something like this:
EXEC SQL DECLARE :c CURSOR FOR :s;
In other words: I want to use variables
in cursor names.
Is it possible ? How ?
Thank you.

Please, what I need to do in order to be able
to do something like this:
EXEC SQL DECLARE :c CURSOR FOR :s;
In other words: I want to use variables
in cursor names.
Is it possible ? How ?
Thank you.

Similar Messages

  • Dynamic Cursor in a procedure

    Hi,
    I am using 10g and wanted to check if we can use a dynamic cursor in a procedure.
    Following is my code and wanted to see if that can work with every query passed as a parameter.
    example ,
    exec test1 ('select col1, col2, col3 from table1','Two columns Sql')
    exec test1 ('select col1 from table2','one columns Sql')
    exec test1 ('select col1, col2, col3, col4, col5 from table3','Five columns Sql')
    CREATE OR REPLACE procedure test1 (p_sql IN VARCHAR2, p_subject IN VARCHAR2
    is
      v_cu_string       VARCHAR2(2000);
      v_string          VARCHAR2(2000);
      v_sql             VARCHAR2(4000);
      v_head            VARCHAR2(4000);
      v_head_sql        VARCHAR2(4000);
      v_str_sql         VARCHAR2(4000);
          TYPE cv_typ IS REF CURSOR;
          cv cv_typ;
    begin
      v_sql := p_sql;
        OPEN cv FOR v_sql;
           LOOP
             FETCH cv INTO v_cu_string;
             EXIT WHEN cv%NOTFOUND;
            ------ Processing steps
          END LOOP;
          CLOSE cv;
    END;Thanks

    user527060 wrote:
    Following is my code and wanted to see if that can work with every query passed as a parameter.
    Just curious as to why this is an improvement of
    exec test1 ('select col1, col2, col3 from table1','Two columns Sql')
    select col1, col2, col3 from table1And
    exec test1 ('select col1 from table2','one columns Sql')
    select col1 from table2And
    exec test1 ('select col1, col2, col3, col4, col5 from table3','Five columns Sql')
    select col1, col2, col3, col4, col5 from table3It needs more code from you to build, more code for anyone to enter to execute, limits selects to only one table I would guess also comes with less documentation than SQL.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/toc.htm

  • Dynamic Optimization and PRO tips

    Is dynamic optimization a new feature on System Center 2012 or it was included in previous versions under a different name?
    What are the main differences between dynamic optimization and PRO tips beside trigger customization?
    Can dynamic optimization work with Operations Manager Monitoring VMM only?
    Thanks!

    Hi
    Your filemaker pro database must be exported as sql in order for you to use it to create a database.
    This may not be a simple create and import into MySQL, see - http://dev.mysql.com/tech-resources/articles/filemaker_mysql_whitepaper/filemaker_to_mysql _whitepaper01.htm.
    PZ

  • Dynamic cursor definition in PL/SQL

    Is it possible to have dynamic cursor definition in PL/SQL. Like
    using DBMS_SQL for dynamic SQL. If yes, how?

    Assuming I understand your question correctly, you can use a REF
    CURSOR to which you associate a VARCHAR2 which is the query text:
    DECLARE
    TYPE t_cur IS REF CURSOR ; -- define t_cur as a type
    c_cur t_cur ; -- define an actual variable of type t_cur
    r_emp emp%ROWTYPE ; -- PL/SQL record to hold row
    v_query VARCHAR2(2000) := 'SELECT * FROM emp' ; -- the query!
    BEGIN
    OPEN c_cur FOR v_query ; -- v_query could contain any valid query
    FETCH c_cur INTO r_emp ; -- get first row from dataset
    CLOSE c_cur ; -- remember to close the cursor! ;)
    END ;
    HTH

  • Does Declare Dynamic Cursor Support with Order Clause?

    Given a dynamic cursor like
         declare CUR_10 dynamic cursor for SQLSA;
         prepare SQLSA from :ls_SQL;
         open dynamic CUR_10;
         do while TRUE
              fetch CUR_10 into :ls_var1, :ls_var2
         loop
    where ls_SQL is "select COL1, COL2 from TABLE_A order by COL2 desc"
    can I fetch values in the exact DESCENDING order of COL2?

    Hello Ronald,
    Values will be fetched in the way you SQL statement has been defined for your dynamic cursor, so in the descending order.
    I've tested your code with an Oracle connection and it works perfectly.
    Just ensure to add a condition to your DO WHILE statement when the resultset is exhausted:
    DO WHILE TRUE AND SQLCA.SQLCode <> 100
    Kind regards,
    Jacob

  • Report with Dynamic Cursor

    hi forum
    I need your help and I hope you can help me. In my job I need to do a Report, but the function that containts the cursor returns a ref cursor and this ref cursor doesn't return a special format 'cause the cursor that I use is Dynamic so when I try to do the report it is not generated.
    the documentation says that should return something for example
    type vref_cursor is ref cursor[b] return record;
    or
    type vref_cursor is ref cursor return depto%rowtype;
    but if I use this in a dynamic cursor it generates an Error and don't accpet this declaration only the following
    type vref_cursor is ref cursor;
    Do you Know how should I do the report with a dynamic cursor ?
    best regards
    thank's a lot

    That is not possible. From the online help:
    Each ref cursor query is associated with a PL/SQL function that returns a strongly typed ref cursor.

  • Fetching values of Dynamic Cursor

    Hi,
    Can I fetch values of dynamic cursor into a variable(record OR individual)? If yes what will be the type of that record/variable?
    Thanks in Advance!
    Regards
    RK

    bluefrog wrote:
    There is no way in 10g to identify the column data types of the result set of a dynamic ref cursor.
    In 11g one can use ;
    DBMS_SQL.DESCRIBE_COLUMNS (
    c IN INTEGER,
    col_cnt OUT INTEGER,
    desc_t OUT DESC_TAB);when using DBMS_SQL
    P;In 11g you can use a ref cursor and then use the DBMS_SQL package to convert that ref cursor to a DBMS_SQL cursor where you can then describe the columns. The initial query doesn't have to be a DBMS_SQL cursor. In 10g, unfortunately, there is no way to convert the ref cursor to a DBMS_SQL cursor, so dynamic cursors would have to be written as DBMS_SQL cursors initially. Ref cursors are only really suitable for 3rd party tools, such as when passing queries back to .NET or Java applications. Too many people try and use ref cursors inside PL/SQL and then discover why that's not a good idea.
    PL/SQL 101 : Understanding Ref Cursors:-
    PL/SQL 101 : Understanding Ref Cursors

  • Can I create a dynamic cursor in a program unit on oracle form....

    Hello folks,
    can I create a dynamic cursor on client side ( in a program unit on the oracle form), is it possible, I Know how to create it on server side using Ref cursor, but on client side i got this message (can't be created on client side or something like that).... please if someone can help

    > select count(*) from t_comsis
    <p>But when you put that select string into a varchar2 variable, it won't compile. Which makes it hard to create anything "dynamic".
    <p>In Forms, you can create and populate a record group dynamically, which is ok as long as your select will not retrieve too many (more than several hundred) rows.
    <p>Or, your other option is to use the Forms Exec_SQL dynamic sql package.

  • Dynamic cursors

    Hi,
    I'm trying to work on dynamic cursors.
    When I try to execute the below code, I'm getting the following error.
    BEGIN
      DYNAMIC_CURSOR.OPENCURSOR();
    END;
    exception raised ORA-00932: inconsistent datatypes: expected - got -
      Below is my code:
    CREATE OR REPLACE
    PACKAGE BODY dynamic_cursor AS
        PROCEDURE dyn_sel (
            tab_name   IN VARCHAR2,
            field_name IN VARCHAR2,
            val        IN VARCHAR2,
            crs        IN OUT t_crs)
        IS
            stmt VARCHAR2(200);
        BEGIN
            stmt := 'select * from '|| tab_name || ' where '|| field_name ||  ' = :1';
            OPEN crs FOR stmt USING val;
        END dyn_sel;
        PROCEDURE openCursor IS
            tc t_crs;
            f1 VARCHAR2(50);
            f2 VARCHAR2(50);
        BEGIN
            dyn_sel ('EMP','JOB','MANAGER', tc);
            LOOP
                FETCH tc INTO f1, f2;
                EXIT WHEN tc%notfound;
                dbms_output.put_line (f2);
            END LOOP;
        EXCEPTION
            WHEN OTHERS THEN
                dbms_output.put_line ('exception raised '||SQLERRM);
        END openCursor;
    END dynamic_cursor; -Thanks

    The selected columns must match the INTO clause, so you need to exactly fetch two columns as e.g. in
      stmt := 'select ename, job from ' || tab_name || ' where ' || field_name || ' = :1';
    ....

  • Error on a Dynamic Select using Pro*C

    I am a new user on Pro*C and I am facing an error for which I could not find a solution in the Pro*C/C++ Programmer’s Guide. The problem occurs when I do a dynamic SELECT to retrieve sequence of numbers (from 0 to 10) from a very simple table in a database.
    The program is retrieving the following sequence: {705, 961, 1217, 1473, 1729, 1985, 2241, 2497, 2753, 3009} rather than the sequence {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
    It’s very interesting to notice that the retrieved sequence, in hexadecimal, is equal to {2C1, 3C1, 4C1, 5C1, 6C1, 7C1, 8C1, 9C1, AC1, BC1}.
    I am quite sure that I'm missing a small detailed here and I would appreciate
    any help. Please find below the code that I am using.
    Thanks a lot!
    #include <string>
    #include <iostream>
    using namespace std;
    #include <sqlca.h>
    #include <sqlcpr.h>
    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR username[30];
    VARCHAR password[30];
    VARCHAR db_name [30];
    VARCHAR dns_name[30];
    EXEC SQL END DECLARE SECTION;
    void SQL_Error ( void )
    char msg[200];
    size_t buf_len = sizeof ( msg );
    size_t msg_len;
    sqlglm( msg, &buf_len, &msg_len );
    if ( msg_len > buf_len )
    msg_len = buf_len;
    cout << msg << endl;
    bool OpenDBConnection( char uname, char pword, char dns, char dbname )
    // Assign the database identifications to the ORACLE variables
    username.len = (unsigned short) strlen ( strcpy( (char *) username.arr, uname ) );
    password.len = (unsigned short) strlen ( strcpy( (char *) password.arr, pword ) );
    dns_name.len = (unsigned short) strlen ( strcpy( (char *) dns_name.arr, dns ) );
    db_name.len = (unsigned short) strlen ( strcpy( (char *) db_name.arr , dbname ) );
    /* Register sql_error() as the error handler */
    EXEC SQL WHENEVER SQLERROR goto err;
    /* Connect to the non default database */
    EXEC SQL CONNECT :username IDENTIFIED BY :password AT :db_name USING :dns_name;
    return ( true );
    err:
    SQL_Error();
    return ( false );
    ** Select the database using a dynamic method
    long SelectIDRecord ( void )
    EXEC SQL BEGIN DECLARE SECTION;
    // Define the dynamic statement
    char dyn_statement[4000];
    // Define the bind variables
    long db_id = 0;
    long db_id_type = 2; /* NUMBER */
    long db_id_len = 10;
    EXEC SQL END DECLARE SECTION;
    // Initialize the dynamic statement
    memset ( dyn_statement, 0, sizeof( dyn_statement ) );
    strcpy ( dyn_statement, "SELECT ID FROM TEST_DB ORDER BY ID" );
    EXEC SQL AT :db_name PREPARE s1 FROM :dyn_statement;
    // Declare and initialize the output descriptor
    EXEC SQL ALLOCATE DESCRIPTOR 'out';
    EXEC SQL AT :db_name DESCRIBE OUTPUT s1 USING DESCRIPTOR 'out';
    EXEC SQL SET DESCRIPTOR 'out' value 1 TYPE = :db_id_type,
    LENGTH = :db_id_len, DATA = :db_id;
    // Declare and open the cursor
    EXEC SQL AT :db_name DECLARE test_db_cursor CURSOR FOR s1;
    EXEC SQL AT :db_name OPEN test_db_cursor;
    EXEC SQL WHENEVER NOT FOUND DO BREAK;
    long nRec = 0;
    while ( true )
    EXEC SQL AT :db_name FETCH test_db_cursor INTO DESCRIPTOR 'out';
    EXEC SQL GET DESCRIPTOR 'out' VALUE 1 :db_id = DATA;
    nRec++;
    cout << "ID = " << (long) db_id << endl;
    // Close the cursor
    EXEC SQL AT :db_name CLOSE test_db_cursor;
    EXEC SQL DEALLOCATE DESCRIPTOR 'out';
    return ( nRec );
    err:
    SQL_Error();
    return ( 0 );
    int main ()
    char *uname  = "test";
    char *pword  = "test";
    char *dns    = "test_db";
    char *dbname = "test";
    OpenDBConnection ( uname, pword, dns, dbname );
    long nRec = SelectIDRecord ();
    }

    No need to specify the length if the data type is number and pointing to Long.
    You can directly map the values using INTO clause.

  • Improving Performance of Dynamic SQL in Pro*C

    I am using Dynamic sql format 3 in pro*C,
    i.e prepare sqlstmt from :sql_stmt
    declare cursor c1 for sqlstmt
    But the query is slow .I am also using
    order by with ltrim(rtrim(colname))
    & sometimes group by .
    can anyone tell how to improve performance
    of cursors in dynamic sql,or how can
    I use the same in Pl/sql with simultaneous
    printing of the rows returned,on a file.
    null

    Manoj,
    Typically, the slow performance is due to the SQL statement itself rather than the dynamic SQL execution code in Pro*C.
    Check your explain plan to see if the query performs well. I suspect that you will find your problem here.

  • After Effects CS5.5 will not open a Dynamically Linked Premiere Pro sequence in the comp. window

    Hi all,
    I'm trying to export a Premiere Pro sequence which is in 2K and the footage has been shot as RED 5K. Adobe Media Encoder will simply not work as I am having the quite widely discussed issue where it will just 'hang' at certain points and not complete the export.
    The most popular solution to this problem is to export via the Render Queue in After Effects instead. However, therein lies the problem.
    I go onto After Effects. Choose File -> Dynamic Link -> Import Premiere Pro Sequence.
    The box pops up, I choose the Premiere Pro Project File then select the sequence I want to export. It then appears in the After Effects project panel window like so:
    However - when I try and drag this to a new composition window, one of two things have happened. Either A) nothing happens (literally, NOTHING changes) or B) as the following example shows, it seems to add it to a new composition, but the video is entirely black. I have tried rendering it and it just produces a black video.
    The other thing people seem to suggest is to just import the entire Premiere Pro sequence into After Effects. I've tried this, but any titles I have added in PP force the video to fade out then back in, in the place where the title should be?? So I can't export the video this way either.
    My system is as follows:
    Thanks massively in advance for any help that is provided!

    This is months old but I'm now having the same problem with AE and Premiere CS6 after updating last night: Dynamic linked sequence shows up in the project window in AE and even plays video if previewed, but will not drag or alt-drag into any comps, including a new comp (makes a new comp with matching settings, but empty).
    Furthermore, I do actually have an earlier version of the same sequence placed in one of my AE comps, which I think was done using the same steps just prior to updating the apps last night. Did this break?
    I'm a little concerned since the biggest reason I'm trying to use premiere is to eliminate the exports when adding graphics in AE.

  • Non-responding keyboard and cursor, macbook pro 10.4.7

    Hi,
    My macbook pro has completely stopped detecting my keyboard and cursor [I am not referring to a usb keyboard, I'm talking about the original typing keyboard], otherwise, it's the keyboard that's malfunctioning. I plugged in a usb mouse and the cursor worked fine, so I suspect that the issue originates from the keyboard itself or some kind of disconnection. Has anyone encountered such issues before? I've attempted to install an apple keyboard update, but the computer refused it because the system did not need the update. I'm completely lost...please...help...thank you so much in advance!!!!!!!!

    this is the wrong place to be asking. please post here...
    http://discussions.apple.com/category.jspa?categoryID=190

  • Using a Dynamic cursor

    Hi,
    I have a problem with this code :
    DECLARE
         v_Column_Name           all_tab_columns.column_name%TYPE;      -- variable for TABLE_SQL
         v_data_type           all_tab_columns.data_type%TYPE;      -- variable for CHPS_SQL
         v_Table_Name           user_tables.table_name%type;
         lc$results     VARCHAR2(32767) := null;
         lc$Champ     VARCHAR2(32767) := null;
         lc$Requete     VARCHAR2(32767) := null;
         CURSOR C1 IS
              SELECT table_name FROM user_tables;
    BEGIN
         OPEN C1;
         LOOP
              FETCH C1 INTO V_Table_name;
              EXIT WHEN C1%NOTFOUND;
              DECLARE
                   CURSOR C2 IS
                        select column_name, data_type from all_tab_columns where table_name = V_TABLE_NAME;
              BEGIN
                   lc$results := 'INSERT INTO ' || v_table_name || '(';
                   lc$requete := 'SELECT ' ;
                   lc$Champ := NULL;
                   OPEN C2;
                   LOOP
                        FETCH C2 INTO V_column_name, V_data_type;
                        EXIT WHEN C2%NOTFOUND;
                        if lc$Champ IS NOT NULL then
                             lc$Champ := lc$champ || ',' || v_column_name;
                             lc$requete := lc$requete || ',' || '''''''''' || ',' || v_column_name || ',' || '''''''''';
                        else
                             lc$champ := lc$champ || v_column_name;
                             lc$requete := lc$requete || '''''''''' || ',' || v_column_name || ',' || '''''''''';
                        end if;
                   END LOOP;
                   CLOSE C2;
                   lc$results := lc$results || lc$champ || ') VALUES (';
                   lc$requete := lc$requete || ' FROM ' || v_table_name;
    -- MY PROBLEM BEGIN HERE
                   DECLARE
    *                    TYPE EmpCurTyp IS REF CURSOR;*
    *                    C3     EmpCurTyp;*
    *               BEGIN*
    *                    OPEN C3 FOR lc$requete;*
    *                    lc$champ := NULL;*
    *                    LOOP*
    *                         FETCH C3 INTO lc$champ ;*
    *                         Exit when C3%NOTFOUND ;*
    *                         lc$champ := lc$results || lc$champ || ')';*
    *                         dbms_output.put_line(lc$champ);*
    *                    END LOOP;*
    *                    CLOSE C3;*
    *               END;*
              END;
         END LOOP;
         CLOSE C1;
    END;          
    the error code is : ORA-00932: inconsistent datatypes: expected - got -
    Need help please,
    Thank

    904907 wrote:
    How can I use the dbms_SQL for this code?99% of the time this indicates design issues. You are trying to write "one-size-fits-all" code which by definition will have substantial overhead. Other than that, in general, you need to declare a variable for each data type possibly returned by dynamic SQL. Then use DBMS_SQL.DESCRIBE_COLUMNS to get data types of select list expressions. Fetch a row and then loop from 1 to number of select list expressions where loop body is one giant IF to test select list expression datatype and issue corresponding DBMS_SQL.COLUMN_VALUE into proper data type variable.
    SY.

  • Dynamic Cursor Fields Reference

    Hi,
    We have a requirement, whereby we need to refer the fields dynamically from the
    cursor, which we cannot decide during development time. It will be keep changing
    and need to be decided during run time only.
    In the below example, I have used "name_in" function to do this, it is not allowed
    in PL/SQL and supported only in Oracle*Forms.
    Please suggest what is the best method available for this requirement, can I
    declare a variable using "ROWTYPE" and use that by any method, thank you.
    DECLARE
    v_Primary_Key int;
    v_Result1 number(10);
    v_Result2 number(10);
    v_Result3 number(10);
    v_Result4 number(10);
    v_cntr int;
    CURSOR CR_TMP
    IS
         SELECT PKFLD, F1, F2, F3, F4, F5, F6 FROM TMP1;
    BEGIN
         FOR CF_TMP IN CR_TMP LOOP
              v_Primary_Key := CF_TMP.PKFLD;
              v_Result1 := CF_TMP.F1 + CF_TMP.F2;
              v_Result2 := CF_TMP.F2 + CF_TMP.F3;
              v_Result3 := CF_TMP.F2 + CF_TMP.F3 + CF_TMP.F4;
              FOR v_cntr in 1..5
              LOOP
              v_Result4 := v_Result4 + to_number(name_in('CF_TMP.F' ||
    v_cntr));
              END LOOP;
         INSERT INTO TMP2
         Values(v_Primary_Key, v_Result1, v_Result2, v_Result3, v_Result4);
         END LOOP;
    COMMIT;
    END;
    Regards,
    Deva

    The following example from my book on Oracle Database 11g PL/SQL Programming should help you because it'll work in at least 10g and perhaps 9i:
    DECLARE
    -- Define explicit record structure.
    TYPE title_record IS RECORD
    ( item_title VARCHAR2(60)
    , item_subtitle VARCHAR2(60));
    -- Define dynamic variables.
    title_cursor SYS_REFCURSOR;
    title_row TITLE_RECORD;
    stmt VARCHAR2(2000);
    BEGIN
    -- Set statement.
    stmt := 'SELECT item_title, item_subtitle '
    || 'FROM item '
    || 'WHERE SUBSTR(item_title,1,12) = :input';
    -- Open and read dynamic curosr, then close it.
    OPEN title_cursor FOR stmt USING 'Harry Potter';
    LOOP
    FETCH title_cursor INTO title_row;
    EXIT WHEN title_cursor%NOTFOUND;
    dbms_output.put_line(
    '['||title_row.item_title||']['||title_row.item_subtitle||']');
    END LOOP;
    CLOSE title_cursor;
    END;
    Hope it helps, Michael

Maybe you are looking for

  • 30GB of space disappears on External Drive after failed DMG copy via USB

    I have a 298.1 GB external Western Digital hard drive connected to my iMac by a USB 2.0 cable. It is formatted in NTFS-3G so I can use it with both my PC and Mac. Yesterday in Disk Utility I created a 50GB 256-bit encrypted DMG and told Disk Utility

  • Issue of Hebrew & English contacts language of device and calendar

    Intersting issue - When I send an invitation to people using my IPhone 4 (Hebrew support) using my Exchange 2003 server account - people who recieve this invitation in their IPhone see my name as ???????? When they see it in the PC Outlook - or on a

  • 3D anaglyphic no depth help

    Hi, I have just ventured into the world of creating anaglyphs (3D red/cyan) I can easily manipulate a photograph to get great results no problems. Now I am actually implementing some 3D into a game ( you will have to use red/cyan glasses of course).

  • User Defined Mapping Problem

    Dear SDNs, I write a user defined mapping program under a namespace, and I want to use it in other namespaces by drag and drop instead of importing, is that possible?

  • Number of reports/instances in a BOE XI R2 environment

    Is there any tool, BusinessObjects or third-party, that can list a total number of reports and/or report instances in a specific environment. My goal is to get an idea of which one of our client folders has the most reports, and more specifically whi