OPENING CURSOR WITH TABLE NAME AS PERAMETER

hi all,
here i have a problem. please help me.
create or replace procedure MAX_ID
(COLUMN_NAME IN VARCHAR2,
TABLE_NAME IN VARCHAR2) IS
CURSOR MAX_CURSOR IS SELECT COLUMN_NAME FROM TABLE_NAME;
begin
END;
in the above procedure table name and column name are in parameters. I have to declare cursor with the in parameter values. How to solve this problem. Give me solution as soon as possible. Waiting for your valuable suggestions.
with regards,
vali

Hi,
You will need to use dynamic SQL to be able to do that. This one returns a single row but you may need to work more on this to achieve the results which you are looking for based on your requirement.
PROCEDURE get_data_dynamically_pr(pv_sqlstr VARCHAR2,pn_count IN OUT NUMBER) IS
ln_cursor NUMBER;
ln_rows NUMBER(5);
BEGIN
/* Retrieve the count from a table we passed */
ln_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(ln_cursor, pv_sqlstr,DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN(ln_cursor, 1, pn_count);
ln_rows := DBMS_SQL.EXECUTE(ln_cursor);
IF DBMS_SQL.FETCH_ROWS(ln_cursor) = 0 then
RETURN;
END IF;
DBMS_SQL.COLUMN_VALUE(ln_cursor, 1, pn_count);
DBMS_SQL.CLOSE_CURSOR(ln_cursor);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20400,SQLERRM||'Exception raised in dynamic sql proc..');
END;
I hope this might be useful to you.

Similar Messages

  • Tried opening a file in library and it states can't open database with library name? It says Relaunch then will not open? and Blocks me completely from Aperture. I have to go to Finder to Rename it? I need this file how do I get it to open?

    Tried opening a file in library and it states can't open database with library name? It says Relaunch then will not open? and Blocks me completely from Aperture. I have to go to Finder to Rename it? I need this file how do I get it to open?

    Aftershotz,
    You're going to have to give a bit more information.
    What do you mean by "opening a file in library?"  There is no function of Aperture to open files -- you can open (switch) libraries.
    You'll have to be more specific about error messages, too.  Perhaps some screenshots would be useful to diagnose your problem.  "Can't open database with library name" is not enough detail about what Aperture is really telling you.
    nathan

  • Problem with writing a procedure with table name as an input parameter

    Hi all,
    I am writing a procedure with table name as an input parameter:
    below is the code
    create or replace procedure prc(in_tbl in varchar2)
    as
    begin
    execute immediate ' truncate table tlb ';
    insert into tbl
    select a,b,c from in_tbl;
    end;

    user579585 wrote:
    Hi all,
    I am writing a procedure with table name as an input parameter:
    below is the code
    create or replace procedure prc(in_tbl in varchar2)
    as
    begin
    execute immediate ' truncate table tlb ';
    insert into tbl
    select a,b,c from in_tbl;
    end;You'll also need to use dynamic sql for the insert:
    execute immediate 'begin insert into tbl select a,b,c from '||in_tbl||'; end';

  • Problem with table name lengths.

    Has anyone experienced with table name length problem?
    When tables are created with schema registration, and the name is longer than 14 characters, the table is created. But when I "select * from xxxx_xxxx_xxxx_xxxx" it says that the table doesn't exist.
    What's the max length of a table name? Or is this a problem with XDB?
    Thanks,
    Benjamin

    Found the problem.
    All table names must be all capitalized and seperated with underscore.
    Is there something I need to set in oracle? or is this a bug? The tables are created but can't be accessed because of the case of table name... that doesn't make sense.

  • Maximum Open Cursors with the CachedRowSet

    Hi all,
    I have a simple task that is cause significant headaches. I'm using the CachedRowSet to process records from an Oracle 8.1.6 database. The code simply populates the row set with records, makes changes to 2 or 3 fields in each record, then calls the acceptChanges().
    When I process about 200 records, everything works fine. If I try to process 300 records, I get the error
    "ORA-01000: maximum open cursors exceded".
    Right before the acceptChanges is called, there is only 1 cursor opened ( I'm checking this via the V$OPEN_CURSOR table). After the acceptChanges is called, it throws the error. Inside my catch block, I put a loop in to print the open cursors. All but two of them is from my app and showing the exact same SQL, update table set name ....
    I have tried populating it directly and through a ResultSet, neither work. When I do a similar process using a ResultSet by itself, it is fine.
    If anyone could please suggest what I might be overlooking I would appreciate it. Also, I would also like to know if there is someway to examine the specific SQL that is being sent to the database if possible.

    we've had similar problems with Oracle creating and not destroying its own cursors("under the covers"). There is relevant info at the following link:
    http://forums.java.sun.com/thread.jsp?forum=48&thread=135291
    quick checklist:
    1. close all statements/preparedstatements/resultsets explicitly and immediately after you are finished with them
    2. increase your number of open_cursors in init.ora file
    -->we had to increase ours to over 700 at one point.
    3. commit/rollback explicitly when finished transactions.
    hope this helps
    Jamie

  • Opening two cursors using open cursor with bulk collect on colections ..

    Is it possible to have the implementatiion of using bulk collect with collections using two open cursors ..
    first c1
    second c2
    open c1
    loop
    open c2
    loop
    end loop
    close c2
    end loop;
    close c1
    what i found is for every outer loop of cursor c1 , cursor c2 is open and closed for every record.
    is this willl imporove the performace .?
    EXAMPLE:-
    NOTE: The relatoin between finc and minc is one to many ..finc is parent and minc is child
    function chk_notnull_blank ( colname IN number ) return number is
    BEGIN
    if ( colname is NOT NULL and colname not in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
    RETURN colname ;
    else
    RETURN 0;
    end if;
    END chk_notnull_blank;
    procedure Proc_AnnualFmlyTotIncSummary is
    CURSOR c_cur_finc IS SELECT FAMID FROM FINC ;
    CURSOR c_cur_minc IS SELECT FAMID, MEMBNO , ANFEDTX, ANGOVRTX, ANPRVPNX, ANRRDEDX, ANSLTX, SALARYX, SALARYBX, NONFARMX, NONFRMBX , FARMINCX, FRMINCBX, RRRETIRX, RRRETRBX, SOCRRX, INDRETX, JSSDEDX, SSIX, SSIBX from MINC minc WHERE FAMID IN ( SELECT FAMID FROM FINC finc WHERE minc.FAMID = finc.FAMID );
    v_tot_fsalaryx number := 0;
    v_tot_fnonfrmx number := 0;
    v_tot_ffrmincx number := 0;
    v_tot_frretirx number := 0;
    v_tot_findretx number := 0;
    v_tot_fjssdedx number := 0;
    v_tot_fssix number := 0;
    v_temp_sum_fsalaryx number := 0;
    v_temp_sum_fnonfrmx number := 0;
    v_temp_sum_ffrmincx number := 0;
    v_temp_sum_frretirx number := 0;
    v_temp_sum_findretx number := 0;
    v_temp_sum_fjssdedx number := 0;
    v_temp_sum_fssix number := 0;
    TYPE minc_rec IS RECORD (FAMID MINC.FAMID%TYPE, MEMBNO MINC.MEMBNO%TYPE , ANFEDTX MINC.ANFEDTX%TYPE, ANGOVRTX MINC.ANGOVRTX%TYPE , ANPRVPNX MINC.ANPRVPNX%TYPE , ANRRDEDX MINC.ANRRDEDX%TYPE , ANSLTX MINC.ANSLTX%TYPE, SALARYX MINC.SALARYX%TYPE , SALARYBX MINC.SALARYBX%TYPE , NONFARMX MINC.NONFARMX%TYPE , NONFRMBX MINC.NONFRMBX%TYPE, FARMINCX MINC.FARMINCX%TYPE , FRMINCBX MINC.FRMINCBX%TYPE , RRRETIRX MINC.RRRETIRX%TYPE , RRRETRBX MINC.RRRETRBX%TYPE, SOCRRX MINC.SOCRRX%TYPE , INDRETX MINC.INDRETX%TYPE , JSSDEDX MINC.JSSDEDX%TYPE , SSIX MINC.SSIX%TYPE , SSIBX MINC.SSIBX%TYPE );
    v_flag_boolean boolean := false;
    v_famid number ;
    v_stmt varchar2(3200) ;
    v_limit number := 50;
    v_temp_FAMTFEDX number := 0 ;
    v_temp_FGOVRETX number := 0 ;
    v_temp_FPRIVPENX number := 0 ;
    v_temp_FRRDEDX number := 0 ;
    v_temp_FSLTAXX number := 0 ;
    v_temp_FSALARYX number := 0 ;
    v_temp_FNONFRMX number := 0 ;
    v_temp_FFRMINCX number := 0 ;
    v_temp_FRRETIRX number := 0 ;
    v_temp_FINDRETX number := 0 ;
    v_temp_FJSSDEDX number := 0 ;
    v_temp_FSSIX number := 0 ;
    BEGIN
    OPEN c_cur_finc ;
    LOOP
         FETCH c_cur_finc BULK COLLECT INTO famid_type_tbl LIMIT v_limit;
         EXIT WHEN famid_type_tbl.COUNT = 0;
         FOR i in famid_type_tbl.FIRST..famid_type_tbl.LAST
         LOOP
         OPEN c_cur_minc ;
         LOOP
         FETCH c_cur_minc BULK COLLECT INTO minc_rec_type_tbl LIMIT v_limit;
         EXIT WHEN minc_rec_type_tbl.COUNT = 0;
              FOR j IN minc_rec_type_tbl.FIRST..minc_rec_type_tbl.LAST
              LOOP
              if ( famid_type_tbl(i) = minc_rec_type_tbl(j).FAMID ) THEN
              v_temp_FAMTFEDX := v_temp_FAMTFEDX + chk_notnull_blank(minc_rec_type_tbl(j).ANFEDTX );
              v_temp_FGOVRETX := v_temp_FGOVRETX + chk_notnull_blank(minc_rec_type_tbl(j).ANGOVRTX);
              v_temp_FPRIPENX := v_temp_FPRIPENX + chk_notnull_blank(minc_rec_type_tbl(j).ANPRVPNX);
              v_temp_FRRDEDX := v_temp_FRRDEDX + chk_notnull_blank(minc_rec_type_tbl(j).ANRRDEDX);
              v_temp_FSLTAXX := v_temp_FSLTAXX + chk_notnull_blank(minc_rec_type_tbl(j).ANSLTX );
              v_temp_FSALARYX := v_temp_FSALARYX + chk_notnull_blank(minc_rec_type_tbl(j).SALARYX ) + chk_notnull_blank(minc_rec_type_tbl(j).SALARYBX);
              v_temp_FNONFRMX := v_temp_FNONFRMX + chk_notnull_blank(minc_rec_type_tbl(j).NONFARMX) + chk_notnull_blank(minc_rec_type_tbl(j).NONFRMBX);
              v_temp_FFRMINCX := v_temp_FFRMINCX + chk_notnull_blank(minc_rec_type_tbl(j).FARMINCX) + chk_notnull_blank(minc_rec_type_tbl(j).FRMINCBX );
              v_temp_FRRETIRX := v_temp_FRRETIRX + chk_notnull_blank(minc_rec_type_tbl(j).RRRETIRX) + chk_notnull_blank(minc_rec_type_tbl(j).RRRETRBX ) + chk_notnull_blank(minc_rec_type_tbl(j).SOCRRX);
              v_temp_FINDREXT := v_temp_FINDRETX + chk_notnull_blank(minc_rec_type_tbl(j).INDRETX);
              v_temp_FJSSDEDX := v_temp_FJSSDEDX + chk_notnull_blank(minc_rec_type_tbl(j).JSSDEDX);
              v_temp_FSSIX := v_temp_FSSIX + chk_notnull_blank(minc_rec_type_tbl(j).SSIX ) + chk_notnull_blank(minc_rec_type_tbl(j).SSIBX);
              END IF;
              END LOOP;
         END LOOP ;
         CLOSE c_cur_minc;
         UPDATE FINC SET FAMTFEDX = v_temp_FAMTFEDX WHERE FAMID = famid_type_tbl(i);
         END LOOP;
    END LOOP;
    CLOSE c_cur_finc;
    END;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package =>'PKG_FCI_APP',p_procedure => 'Proc_Annual_Deductions_FromPay ' , p_location => v_location);
    end Proc_AnnualFmlyTotIncSummary ;
    Is the proga efficient and free from compilation errors ..?
    thanks/kumar
    Edited by: kumar73 on Sep 22, 2010 12:48 PM

    function chk_notnull_blank ( colname IN number ) return number is Maybe this function should have its own forum:
    how to use case in this program
    Re: how to declare a formal parameter in a function of type record and access ?
    Re: how to define a function with table type parameter
    Re: creation of db trigger with error ..
    Re: How to write a trigger for the below scenario
    how to improve the code using advanced methods
    yours advice in improving the coding ..
    How to use bulk in multiple cursors !!
    ;-)

  • Problem with table name in procedure

    Hi Team,
    I have a procedure in which table name is stored in a variable.
    I want to use this table_name in one select statement of a same procedure.
    declare
    v_table_name varchar2(30);
    begin
    v_table_name:='EMPLOYEE';
    FOR cur IN
    ( select ename,empno,deptno from v_table_name )
    loop
    dbms_output.put_line(cur.ename);
    end loop;
    end;
    Edited by: rajendra on Feb 26, 2012 9:29 AM

    sb92075 wrote:
    you must utilize EXECUTE IMMEDIATEWhy? Plain cursor variable will do:
    declare
        v_table_name varchar2(30);
        v_cur sys_refcursor;
        v_ename varchar2(20);
        v_empno number;
        v_deptno number;
    begin
        v_table_name:='EMP';
        open v_cur for 'select ename,empno,deptno from ' || v_table_name;
        loop
          fetch v_cur
            into v_ename,
                 v_empno,
                 v_deptno;
          exit when v_cur%notfound;
          dbms_output.put_line(v_ename);
        end loop;
        close v_cur;
    end;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.
    SQL> SY.

  • GR/IR:  Open receipts with vendor name

    Hello SAP Gurus-
    I am not sure if we are doing something wrong but we are currently reconciling our GR/IR account and what we noticed is that when we added the vendor name to the report with the help of an OSS note, we noticed that it gives us all transactions that make up the balance however it isn't what we wanted exactly.
    What we were looking for was once we execute MR11 and handle all differences, we want to see only open receipts with the Vendor name.  How can we achieve this?  Is there a report?  Should the GR/IR account be set up as a clearing account?
    Any help/ insight is greatly appreciated!

    figured it out

  • Dynamic SQL Statement with table name

    Dear all
    i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?
    should be something like "select * from <mytablename>"
    Thank you
    Herbert

    Yes this is possible. use the below reference code for this.
    data: g_tablename type w_tabname,
            gv_dref TYPE REF TO data.
    FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.
    gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)
    CREATE DATA gv_dref TYPE TABLE OF (g_tabname).
    ASSIGN gv_dref->* TO <g_itab>.
    now use the below select query to fetch the data
      SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.
    Hope this will help

  • Prefix with table name

    I have a query which involves two tables with both have some common columns ..I thought that if we don't prefix column names with the table names we would get a "column ambigously defined" error so that we will know that we need to prefix that column name with the table name. But I am not getting this error and instead I am getting wrong results as a consequence of not prefixing the column name with the table name.
    Is this usual? How do I avoid this?

    user8117487 wrote:
    I have a query which involves two tables with both have some common columns ..I thought that if we don't prefix column names with the table names we would get a "column ambigously defined" error so that we will know that we need to prefix that column name with the table name. But I am not getting this error and instead I am getting wrong results as a consequence of not prefixing the column name with the table name.
    Is this usual? How do I avoid this?Column ambigously defined means that a similar column is present in the table. A simple case;
    select emp_id from emp e, dept d
    where e.emp_id=d.emp_id
    Ex Senior DBA
    It is not easy being a DBA

  • Difference between with table name with * and without *

    Hi..
    I had seen some of the standard abap that the table name had *, like *ekpo. What is the meaning? What is the difference between with * and without * ? 
    Thanks and Regards,
    Rishika

    Hi rishika,
    1. This is actually a facility provided in abap syntax.
    2. It is usually checked while saving a record.
    3. For eg.
    If we have one variable
    EKKO
    and another *EKKO
    (They both are same only, with same structure)
    (but two different variables)
    4. The functional meaning, for usage purpose,
    of *EKKO is OLDEKKO.
    5. While saving the transaction,
    the data is saved only if there is any change
    in the values.
    IF EKKO <> *EKKO.
    *--- SAVE
    ELSE.
    MESSAGE 'NO DATA CHANGED'
    ENDIF.
    6. We can aswell use any other variale
    eg. oldekko
    oekko
    myekko
    etc,
    7. But for business meaning,
    R/3 has the facility for *
    1. we can use almost everywhere.
    2. just copy paste
    report abc.
    TABLES : T001.
    TABLES : *T001.
    DATA : ITAB LIKE EKKO.
    DATA : *ITAB LIKE EKKO.
    DATA : NUM TYPE I.
    DATA : *NUM TYPE I.
    regards,
    amit m.

  • How to  Find Logical Database with table name

    Shankar

    Version 4.6x
    If you need to find the logical database for a table name, you can used <b>SE36</b> - Logical Database Bulider.
    Steps :-
    Go to transaction <b>SE36</b>
    Click <b>Extras -> Table usage</b>
    Supply the Table name and hit enter.
    A Display Logical Database will be shown on a pop-up windows.
    Reward  points  if it is  usefull ....
    Girish

  • PROBLEM WITH TABLE NAMES

    HI Experts,
    I need to give my new table name as z_xxx_xxxx_xxxxxx.
    But iam not able to give this name and create a new table since.
    The length is bigger.
    and it is not allowing me to keep the undersocres in the second place.
    Can any one advice

    Hi Karthick,
    Check out the following links:
    http://help.sap.com/saphelp_45b/helpdata/en/0d/d2f7d04a0c11d182b80000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/4a56b2185851468b39b719daa2d3aa/content.htm
    Regards,
    Rajesh K Soman
    <b>Please reward points if found helpful</b>

  • Sql Except query to Display mismatched records along with Table names

    Hi
    I am using below query to display mismatch records between two tables
    SELECT * FROM table1
    EXCEPT
    SELECT * FROM table2
    UNION
    SELECT * FROM table2
    EXCEPT
    SELECT * FROM table1
    This displays mismatched records like below
    Sunil  1000  india
    Sunil 1500  india
    I would like to display even the table names in the result For ex;
    Sunil  1000  india  Table1
    Sunil 1500  india   Table2
    Can you please help us in this regard.

    cnk_gr's query should work for you. 
    One change that I would make is to use UNION ALL, not UNION.  UNION eliminates duplicate rows, which means SQL has to do additional work (sort the result and then check for duplicates). 
    So if you can have duplicates and don't want them in your result, then you would use UNION.  And if you can have duplicates and you want the duplicates in the result, you would use UNION ALL.  But in cases like this, where you know you cannot have
    duplicates (because column 1 contains 'TABLE1' for every row in the first half and column 1 contains 'TABLE2' for every row returned from the second half of the query), you should always use UNION ALL.  It will be more efficient.
    Tom

  • Join of cursor with table

    Hi experts,
    Oracle Version: 11GR2
    I get dataset in the ref cursor as an out parameter from a procedure. Now, I have to derive column "NAME" from table "TEST" using ID as a join key between cursor and a table.
    How can we do this in oracle?
    Thanks

    You cant join a cursor to a table. cursor is a SQL work area where instruction to execute a SQL is processed.
    I could think of three approaches
    1. The best way is to include the table "TEST" in the original SQL that builds the cursor.
    2. If that is not possible then you need to fetch them (may be) into a SQL collection type and then join the table "TEST" with the collection type.
    3. Or you may have to loop thorough the cursor and then for each row fetched you would have to join with the table "TEST"
    Lets say this is your procedure
    create or replace procedure getdept
      p_out_rc out sys_refcursor
    as
    begin
      open p_out_rc for
      select deptno
        from dept;
    end;
    Example for 2nd approach
    Create a SQL Nested Table.
    create or replace type deptno_tbl as table of number(10)
    And you write a PL/SQL code like this. Code in red is the one to consider.
    SQL> declare
      2    l_deptno deptno_tbl;
      3    l_rc     sys_refcursor;
      4  begin
      5    getdept(l_rc);
      6    fetch l_rc bulk collect into l_deptno;
      7
      8    for i in (
      9               select ename
    10                 from emp e
    11                 join table(l_deptno) t
    12                   on e.deptno = t.column_value
    13             )
    14    loop
    15      dbms_output.put_line(i.ename);
    16    end loop;
    17  end;
    18  /
    KING
    CLARK
    ADAMS
    SCOTT
    JONES
    SMITH
    TURNER
    BLAKE
    MARTIN
    WARD
    ALLEN
    Example for 3rd approach.
    SQL> declare
      2    l_rc     sys_refcursor;
      3    l_deptno number(10);
      4  begin
      5    getdept(l_rc);
      6    loop
      7      fetch l_rc into l_deptno;
      8      exit when l_rc%notfound;
      9      for i in (
    10                 select ename
    11                   from emp e
    12                  where e.deptno = l_deptno
    13               )
    14      loop
    15        dbms_output.put_line(i.ename);
    16      end loop;
    17    end loop;
    18  end;
    19  /
    CLARK
    KING
    SMITH
    JONES
    SCOTT
    ADAMS
    ALLEN
    WARD
    MARTIN
    BLAKE
    TURNER
    Finally I would again like to highlight that first approach is by far the best approach. The second and third approach has there own performance downside.

Maybe you are looking for

  • 10.1.3 - Strange noisy error.

    Sometime I get a noisy error without any visible consequence. The error is : java.lang.ClassCastException: oracle.jbo.dt.jdevx.JdvXmlNode      at oracle.jbo.dt.jdevx.JdvApplication.loadFromProject(JdvApplication.java:1553)      at oracle.jbo.dt.jdevx

  • Lightroom export actions crashes photoshop

    Hello This is a problem that has eluded me for a while. Im running Lightroom 3 and photoshop cs5 (both have the latest updates) . Now I've created droplets that run various actions. In lightroom I export images and use export actions dialog box to ha

  • Adding itemCreationPolicy="immediate" on mx:Panel causes null object reference error in Flex 4.x

    The itemCreationPolicy works fine with spark components and other mx component until we hit by mx panel. Looks like an error is thrown from StyleProtoChain. The interesting thing is the null object reference error both occurs in Flex 4.0 and Flex 4.1

  • Photo shop wont install

    hi I have just got adobe photo editor and the adobe photoshop wont install it comes up with this error....could anyone help please? Code: 6 Please see specific errors below for troubleshooting. For example,  ERROR: -----------------------------------

  • How to unistall and reinstall my 4g wifi device

    Hi all I am running yosemite on my 15" MBP and up until last night had no problems logging on to the internet using my telstra 4g wireless device. I cannot connect now and when i run network diagnostics i get a country codes conflict error. I am sure