What to do when a table name is a reserved word?

I know the best answer is not to use a reserved word to name a table. But I have no control over that in this situation. I have read that using all Caps and quotations will allow you to use the table name in queries, i.e. "CATEGORY" is suppose to free the table to be used. But that is certainly not working, nor any variation of that formatting.
Does anyone know how to format a reserved word to allow queries?
Thank You

Use double quotes:
SQL> create table ALTER (a number);
create table ALTER (a number)
ERROR at line 1:
ORA-00903: invalid table name
SQL> create table "ALTER" (a number);
Table created.
SQL> desc alter
ERROR:
ORA-00931: missing identifier
SQL> desc "ALTER"
Name                                      Null?    Type
A                                                  NUMBER
SQL> insert into "ALTER"
  2  select level from dual connect by level<=10;
10 rows created.
SQL> select * from "ALTER";
         A
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
10 rows selected.BTW CATEGORY is not a reserved word:
SQL> create table category (a number);
Table created.Max
http://oracleitalia.wordpress.com
Edited by: Massimo Ruocchio on Feb 25, 2010 12:32 AM

Similar Messages

  • What is the field and table name to describe -Employee Hourly Rate or Emplo

    Hi,
    Can any one please tell me what is the field and table name to describe 
    Employee Hourly Rate or Employee Rate.
    Thanks for ur time.
    Murali.

    Hi Murali,
    The hourly rate is tied to a Wagetype & maintained in Infotype 0008. The database table is PA0008.
    the field could vary depending on the No of wagetypes maintained.
    regards,
    Suresh Datti

  • What it means when psoprdefn table doesnot have PS user

    what it means when psoprdefn table doesnot have PS user?
    invalid access id and password for signon see your security administrator
    getting this message please help!
    Thanks,
    kishore

    Can you please describe what you are doing and about the oracle error that prompted.
    Shafiulla Syed

  • Getting problem when retriving Table name

    Hi,
    I'm having problem when i trying to get the table name from database. I'm using NetBeans 6.0, And It does n't show any error during compile and run time. I could n't find where the problem is?
    Code:_
    DatabaseMetaData dbm=conn.getMetaData();
    String[] types={"TABLES"};
    ResultSet rs=dbm.getTables("%","%","%",types);
    System.out.println("TableName:");
    while(rs.next())
    String tableName=rs.getString("TABLE_NAME");
    String tableSchema=rs.getString("TABLE_SCHEM");
    String tableCatalog=rs.getString("TABLE_CAT");
    System.out.println(tableName);
    conn.close();
    System.out.println("Disconnected from database");
    Output is:_
    MySQL Connect Example.
    TableName:
    BUILD SUCCESSFUL
    Regds,
    Prabu
    Edited by: [email protected] on Apr 16, 2008 12:32 PM

    Why did you repost? Don't do this, it is extremely rude!
    Stick with your other thread. I just gave you what I believe to be the correct answer.
    [Original Post|http://forum.java.sun.com/thread.jspa?threadID=5286520&tstart=0]

  • Problem in the output when the table name is explicitly assigned.

    hi
    Am using a procedure to copy the information's in a table to a flat file. my aim is to achieve this copy function by assigning the table name from user explicitly.
    this is the program:
    create or replace procedure jk(table_name in varchar2) is
    sel_table varchar2(30);
    l_bool BOOLEAN;
    irows INTEGER := 1;
    buffer LONG;
    f utl_file.file_type;
    BEGIN
    sel_table:='select * from '||table_name;
    f := utl_file.fopen('SAMPLE','tablename.txt','W');
    OWA.cgi_var_name (1) := 1;
    OWA.cgi_var_val (1) := 1;
    OWA.init_cgi_env (1, OWA.cgi_var_name, OWA.cgi_var_val);
    HTP.adddefaulthtmlhdr (FALSE);
    l_bool :=
    OWA_UTIL.tableprint (ctable => sel_table,
    cattributes => '',
    ntable_type => OWA_UTIL.pre_table,
    ccolumns => '*',
    cclauses => '',
    ccol_aliases => '',
    nrow_min => 0,
    nrow_max => 500
    WHILE (irows != 0)
    LOOP
    buffer := HTP.get_line (irows);
    utl_file.put_line(f,buffer);
    /* do whatever you like with the contents of the buffer */
    /* You may write to a file or simply print it out */
    DBMS_OUTPUT.put_line (buffer);
    END LOOP;
    END;
    the error during execution:
    SQL> @for.sql
    Procedure created.
    SQL> exec jk('CUST');
    BEGIN jk('CUST'); END;
    ERROR at line 1:
    ORA-00931: missing identifier
    ORA-06512: at "SYS.DBMS_UTILITY", line 125
    ORA-06512: at line 2
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 1120
    ORA-06512: at "SYS.DBMS_SQL", line 323
    ORA-06512: at "SYS.OWA_UTIL", line 595
    ORA-06512: at "SYS.OWA_UTIL", line 689
    ORA-06512: at "SYS.OWA_UTIL", line 1222
    ORA-06512: at "XMLUSER.JK", line 14
    ORA-06512: at line 1
    thanks in advance
    karthik.J

    You better don't supply the whole select statement to OWA_UTIL.tableprint but only the table name!

  • Table name (Availability to reserve)

    hi all
    in INVentory ABC super user there is Onhand quantity when the Onhand quantity form is opened there is a tab called Availability when it is cliclKED
    there is a field namely Availability to reserve ,when i do record history its says record history not available
    could anyone please let me know the name of the table where Availability to reserve is present
    i did check in mtl_onhand_quantity and mtl_onhand_quantity_details too
    kindly guide
    thanking in advance

    hi
    i went thru tht API u suggested ,i dont know how to proceed
    this is the query i created ,containg on hand qty,i require the available to reserve also inorder to calculate Onhand-Available to reserve
    SELECT i.segment1 itemno, i.segment2 partno, i.segment3 oldno, i.description,Q.transaction_quantity ,F.INVENTORY_ITEM_STATUS_CODE,
           q.transaction_quantity onhand, cst.item_cost,
           q.transaction_quantity * cst.item_cost total, q.subinventory_code,
           l.segment1 LOCATOR, o.NAME ORGANIZATION
      FROM mtl_system_items i,
           mtl_onhand_quantities q,
           mtl_item_locations l,
           hr_all_organization_units o,
           cst_item_costs cst,
            MTL_SYSTEM_ITEMS_FVL F
    WHERE i.inventory_item_id = q.inventory_item_id(+)
    AND i.inventory_item_id = F.inventory_item_id
       AND l.inventory_location_id = q.locator_id
       AND l.organization_id = q.organization_id
       AND o.organization_id = i.organization_id
       AND i.organization_id = q.organization_id(+)
       AND i.organization_id = F.organization_id
       AND i.inventory_item_id(+) = cst.inventory_item_id
       AND i.organization_id(+) = cst.organization_id
       AND i.organization_id IN (104, 123, 121, 105)kindly guide me
    Edited by: makdutakdu on Jan 6, 2011 8:58 AM
    Edited by: makdutakdu on Jan 6, 2011 9:00 AM

  • URGENT !!!!...What is the Select Options Table name

    HI Folks,
    Can anyone of u tell me ...what is the name of the Structure/Table which has fields SIGN, OPTION, LOW, HIGH.
    Thanks in advance.
    Points will be rewarded for the needful.

    Hi John,
    I think there is no specific structure/ table available for this, we have to use replicate the standard format with custom one.
    TYPES: BEGIN OF linetype,
             sign   TYPE c LENGTH 1,
             option TYPE c LENGTH 2,
             low    {TYPE type}|{LIKE dobj},
             high   {TYPE type}|{LIKE dobj},
           END OF linetype.
    Thanks & Regards,
    Muthu

  • What's lost when I change names, or hard reset?

    My first question here:
    I've used a Zire 21 for many years, and have some commercial software on it that required activation codes that were e-mailed upon payment.  One is Piloc, a foreign language localization program, the other is SuperMemo, a flash card program for the same. I use them every day.
    Now I've bought a Treo 680.  That software isn't compatible with the Treo, so I'd like to keep the Zire going.  But standard installation of the Treo software has the Treo using the old Zire user name.  I'm sure I can't synch my Zire using that same name.
    Reading manuals & online info, it looks like I can give my Zire a new user name by a hard reset (scary!), or by a hidden rename procedure involving the shortcut graffiti stroke, a dot, etc.  If I understand it correctly, this will allow me to reinstall software and data (like flash card progress data).
    But are my software activation codes likely to work?  Supermemo in particular claimed it calculated my activation code using my user name.  That sounds like it would prevent a reinstallation ... unless the software "knows" that it's been paid for, and allows me to reinstall even if the user name is different.
    Does anyone know for sure how this will work?  Will I be able to reinstall?  Would a synchronization then re-load all my progress data on the flash cards?  Should I try a rename (instead of a hard reset) in the hopes that less would be lost?
    If there's a high likelihood of losing everything, I'd probably just keep charging the Zire and hope it never crashes!
    - Frank Krygowski
    Post relates to: Treo 680 (AT&T)

    I did a hard reset of the Zire, then went through the digitizer calibration and time zone setting, then synched. 
    I get a window popping up that says:
    "This Palm Powered [TM] handheld does not have a user account associated with it.  Please creaste or select an existing user account to synch with handheld.  What do you want to do?
    [default radio button]  Create a new user account named [blank box]
    [alternate radio button]  Select an existing user account  [Choices in this box are Frank Krygowski Treo, and my wife's dead Zire named Peg Krygowski]
    I assumed I was supposed to use Frank Krygowski Treo username.  The hotsynch proceeded, and a very long Log file was generated.  But the Zire now has no calendar data (the two handhelds previously had nearly equal calendars), no "to do" lists (which were identical and extensive), no ToDo lists (which were extensive) and so on.  Also, the foreign language software (Piloc and a Polish-English dictionary) are either missing or not functioning.
    What gives?  If the backup files are an image of this Zire, I'm afraid I'm in trouble.
    I _really_ don't want to lose the volumes of data (to-do lists, calendar, etc etc) that are now only on the Treo.  Is there a chance I should change the Treo's username once more, then re-synch?  Or did I goof in choosing the Treo's username?  Should I redo the hard reset and re-synch the Zire with the original username, "Frank Krygowsk"

  • What are the fileds and table names for salesorder reoprt

    hi,
        how to find tables and fields for the sales order report / any report?

    Hi,
    Check the following standard reports in SD,
    Sales summary - VC/2
    Display Customer Hierarchy - VDH2
    Display Condition record report - V/I6
    Pricing Report - V/LD
    Create Net Price List - V_NL
    List customer material info - VD59
    List of sales order - VA05
    List of Billing documents - VF05
    Inquiries list - VA15
    Quotation List - VA25
    Incomplete Sales orders - V.02
    Backorders - V.15
    Outbound Delivery Monitor - VL06o
    Incomplete delivery - V_UC
    Customer Returns-Analysis - MC+A
    Customer Analysis- Sales - MC+E
    Customer Analysis- Cr. Memo - MC+I
    Deliveries-Due list - VL04
    Billing due list - VF04
    Incomplete Billing documents - MCV9
    Customer Analysis-Basic List - MCTA
    Material Analysis(SIS) - MCTC
    Sales org analysis - MCTE
    Sales org analysis-Invoiced sales - MC+2
    Material Analysis-Incoming orders - MC(E
    General- List of Outbound deliveries - VL06f
    Material Returns-Analysis - MC+M
    Material Analysis- Invoiced Sales - MC+Q
    Variant configuration Analysis - MC(B
    Sales org analysis-Incoming orders - MC(I
    Sales org analysis-Returns - MC+Y
    Sales office Analysis- Invoiced Sales - MC-E
    Sales office Analysis- Returns - MC-A
    Shipping point Analysis - MC(U
    Shipping point Analysis-Returns - MC-O
    Blocked orders - V.14
    Order Within time period - SD01
    Duplicate Sales orders in period - SDD1
    Display Delivery Changes - VL22
    <b>Reward if helpful.</b>

  • Dynamic SQL : passing table name as parameter

    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice

    Hi,
    b003cf5e-e55d-4ff1-bdd2-f088a662d9f7 wrote:
    Hi
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
    DECLARE lookupTableRow CURSOR FOR
      SELECT TableName FROM SYS_LookUpTable
      OPEN lookupTableRow
      FETCH NEXT FROM lookupTableRow INTO @tableName
      WHILE @@FETCH_STATUS=0
      BEGIN
      SET @sql='SELECT * FROM '+@tableName
    EXECUTE sp_executesql @sql
      IF @counter=0
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
      END
      ELSE
      BEGIN
      INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
      END
      SET @counter=@counter+1
      FETCH NEXT FROM lookupTableRow INTO @tableName
      END
      CLOSE lookupTableRow
      DEALLOCATE lookupTableRow
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
    So i cant do this too with ORACLE dynamic sql .
    Please advice for any solution
    * how can i use dynamic sql with table name as parameter ?
    * how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
    Thanks for the advice
    I have a SQL query (a store procedure )  that i want to convert to PLSQL
    I doesn't help when you use one term to mean another thing.
    SQL is a language used in both Oracle and other products, such as Microsoft's SQL Server. I don't know much about SQL Server, but Oracle (at least) doesn't support stored procedures in SQL itself; they have to be coded in some other language, such as PL/SQL.  
    As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
    If the table name is a parameter (or only known at run-time for any reason), that's exactly the kind of situation where you MUST use dynamic SQL.
    The number of columns that a query produces (and their datatypes) is fixed when you compile a query, whether that query is dynamic or not.  If you have multiple queries, that produce result sets with different numbers of columns, then you can't combine them into a single query.  The best you can do with one query is to add NULL columns to some of the queries so they all produce the same number of columns.
    If you're just displaying the results, there might not be any reason to combine separate result sets.  Just display one result set after another.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Find R/3 table name

    Hi Gurus,
    How to find out what is the R/3 table name to LO datasources ?
    Example 2lis_02_itm , 2lis_11_vaitm etc...
    Thanks
    Liza

    you basically derive it from functional understanding of datasource.
    or you can always check in Businesss Content...like check the origin table of below link from Business Content:
    http://help.sap.com/saphelp_nw04/helpdata/en/7f/0f8c4037fba62be10000000a1550b0/content.htm

  • How to view Table names?

    Dear gurus....
    can u tell me how to view or whats the Tcode to view  table names like  for PO its CEKKO
    and for PR its CEBAN and RFQ,Service etc??
    Thanks

    Hi there,
    To search on a field from table it's coming help -F1 then technical details -F9
    If you double click on the field table-field you are directy to the view
    If u know table i would rather use SE16 or SE16N depending on r release.
    CEKKO is indeed a structure. EKKO is the table.
    enjoy!

  • Quering table names containing a value in any column

    I searched a bit around this forum and found a solution for how to query the list of all tables
    select table_name from user_tables;
    However, I do not know how to do this -
    I want to find the list of all table names where any of the fields in these tables should have the value containing a number in it.
    Say for example I have a database containing many tables Students, Teachers, Principals and many other such 100+ tables. I want to find the list of all tables names which contain the word "ohn" in any of their fields. The string "ohn" MAY be in Employees table under First Name field as John and in Teachers under Nick Name field as Johnny, etc.
    So, I do not know what are the columns/field names. I only know that the value of any of these columns will contain the string "ohn" (like '%ohn%'). Now, how do I write a query for this which will give me the table names?
    Please assist!

    Well, this is by no means production code, but it should help you along the way to what you need.
    create table test_1
      column1 varchar2(100)
    create table test_2
      column1 number,
      column2 varchar2(100),
      column3 varchar2(100)
    insert into test_1 values ('THIS WILL HAVE MY STRING WITHIN IT');
    insert into test_2 values (1, 'WILL NOT QUALIFY', 'NEITHER WILL THIS');
    commit;
    declare
      l_search_string   varchar2(100) := '%MY STRING%';
      l_count           number;
    begin
    for everything in
      select
        ' with data as (select :x as search_string from dual) select count(*) from ' || table_name || ' where ' || replace(search_string, '-', ' like (select search_string from data) or ') || ' like (select search_string from data) ' as sql_string, table_name
      from
        select
          substr(MAX(SYS_CONNECT_BY_PATH(column_name,'-')), 2) as search_string, table_name
        from
          select
            row_number() over (partition by table_name order by 1) as rn,
            table_name,
            column_name
          from dba_tab_cols
          where table_name in ('TEST_1', 'TEST_2')
          and   data_type in ('CHAR', 'VARCHAR2', 'NVARCHAR2', 'NCHAR', 'CLOB')
        group by table_name
        start with rn = 1
        connect by prior table_name = table_name
        and rn = prior rn + 1
    loop
      execute immediate everything.sql_string into l_count using l_search_string;
      if l_count > 0
      then
        dbms_output.put_line(everything.table_name || ' has ' || l_count || ' rows ');
      end if;
    end loop;
    end;
    /Edited by: Tubby on Jan 28, 2010 9:57 PM
    I forgot to ask your version number, so if the code i posted doesn't work on your version, you'll have to let us know what your version is ....

  • Jdbc bug in executeUpdate(sql, int[]) when table name is case-sensitive;

    I have found a bug in oracle's jdbc (ojdbc6.jar), can someone tell me how to submit it so that it can be fixed?
    The BUG: using executeUpdate(insert_sql_stmt, int[]) to retrieve the generatedKey generated by before-insert trigger using a sequence results in error when the tablename is case-sensitive (but OK if table name in uppercase).
    Steps to reproduce:
    1a. create table "mixCase" (f1 integer, f2 varchar2(20));
    1b. create table upperCase (f1 integer, f2 varchar2(20));
    2a. create sequence mixCase_seq start with 1;
    2b. create sequence upperCase seq start with 1;
    3a. create or replace trigger mixCase_trigger before insert on "mixCase"
    bq. for each row \\ begin \\ select mixCase_seq.nextval into :new.f1 from dual; \\ end;
    3b. create or replace trigger upperCase_trigger before insert on upperCase
    bq. for each row \\ begin \\ select upperCase_seq.nextval into :new.f1 from dual; \\ end;
    4a. String url = "jdbc:oracle:thin:@//localhost:1521/orcl";
    bq. conn=DriverManager.getConnection(url,user,password); \\ Statement stmt = conn.createStatement (); \\ int rc=stmt.executeUpdate("insert into \"mixCase\"(f2) values('aa')",new int[]{1});
    4b. String url = "jdbc:oracle:thin:@//localhost:1521/orcl";
    bq. conn=DriverManager.getConnection(url,user,password); \\ Statement stmt = conn.createStatement (); \\ int rc=stmt.executeUpdate("insert into upperCase(f2) values('aa')",new int[]{1});
    When you run 4a or 4b in a java jdbc program:
    4b runs OK and rset=stmt.getGeneratedKeys() returns the correct f1 value of 1.
    4a results in error:
    bq. h6. java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist \\ + at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)+ \\ + at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)+ \\ + at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)+ \\ + at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)+ \\ + at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:406)+ \\ + ...+
    +Notes:&lt;/&lt;/em&gt;
    # If Statement.RETURN_GENERATEDKEYS is used instead of "new int[]{1}" in 4b, there is no error but the rset=stmt.getGeneratedKeys() returned in a ROWID such as 'AAARUyAAEAAAAGQAAL', not what is expected. Other database's jdbc return the correct generated integer value.
    # Same 4b error if new String[]{"f1"} is used as 2nd argument for executeUpdate.
    # The only difference in 4a and 4b is that 4a has case-sensitive table name. All sequence names, trigger names, column names are implicitly deemed to be uppercase by oracle in both cases.
    bq.
    Edited by: user10343198 on Oct 2, 2008 5:50 PM
    Edited by: user10343198 on Oct 2, 2008 6:34 PM

    Please patch one fo your machines to 10.2.0.3 and then try and duplicate. You do not have to go through the complete registration of the XSD process thoguh you can check and see if the c based parser will validate on the command line using the
    schema executible under your oracle_home bin directory.
    schema 1.xml 1.xsd
    for example
    if it dupes in 10.2.0.3 open a TAR with support so that we may bug it.
    regards
    Coby

  • Invalid table name when pass in the table name as variable in dynamic sql

    Hi,
    I need to create a stored procedure which will return a list of data to my java application like the following.
    first, select the table name from the first table.
    For example : SELECT T_NAME FROM MDR_SMSTABLES
    second, select the data from the table which returned by first select statement
    For example : SELECT * FROM T_NAME.
    I use dynamic sql with cursor to select the data. But it returns "java.sql.SQLException: ORA-00903: invalid table name"
    I fetch the table name to varchar2. I think this might the cause it returns me the this error. But i don't know what type should i put for the table name other then varchar2.
    val2 VARCHAR2(200);
    OPEN cv FOR
    SELECT T_NAME FROM MDR_SMSTABLES WHERE T_DATE=d_dt_sent;
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR
    'SELECT * FROM :t WHERE MID = :m' USING val2, msg_id;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    As my stored procedure is quite long, so i just paste some of the code here. Hope the information is enough. Can anyone please help?
    Thanks

    DECLARE
    val2 VARCHAR2 (200);
    cv sys_refcursor;
    refcur sys_refcursor;
    BEGIN
    OPEN cv FOR
    SELECT table_name
    FROM user_tables
    WHERE table_name IN ('EMP', 'DEPT');
    FETCH cv INTO val2;
    WHILE cv%FOUND
    LOOP
    OPEN refcur FOR 'SELECT * FROM '||val2;
    EXIT WHEN refcur IS NOT NULL;
    FETCH cv INTO val2;
    END LOOP;
    END;

Maybe you are looking for