Select and cursor statement

Hi all,
Given the following code :
     TYPE option_rec IS RECORD
        value varchar2(3),
        label varchar2(255)
TYPE option_list_t IS TABLE OF option_rec;
FUNCTION get_object_list
    RETURN option_list_t
    PIPELINED
    DETERMINISTIC
  IS
        tmp option_rec;
  BEGIN
        tmp.value:='1';
        tmp.label:='foo';
        PIPE ROW(tmp);
        tmp.value:='2';
        tmp.label:='bar';
        PIPE ROW(tmp);
       RETURN;
  END get_object_list;
  FUNCTION generate_select(selected_value in varchar2)
    RETURN sys_refcursor
  IS
     ret sys_refcursor;
  BEGIN
    open ret for
         select value as value,
                '(' || value || ') ' || label as label,
                case value
                   when selected_value then
                      'selected'
                   else
                end as selected
           from table(get_object_list);
    return ret;
  END generate_select;
I can't succeed in runnig this query :
select *
from cursor(generate_select('2'))I have the following error :
ORA-00933: "SQL command not properly ended"What is wrong ?
I run on Oracle 10gR2

Having a pipelined function defined search documentation for TABLE operator
You must select from (TABLE(get_object_list()) where ...
Regards
Etbin
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2351
Edited by: Etbin on Apr 27, 2009 7:09 PM

Similar Messages

  • Select and Cursor doubt

    Dear All,
    I got a doubt b/n select and cursor.
    I read in one oracle book that select into clause will actually tries to get the data twice, Whereas the cursor will query only ones.
    Is this the case in Oracle 10g or both the select and cursor will fetch the data only ones.
    Ex
    select sal into v_sal from emp where empno = 7788 --> Ones it hit the data, oracle will again scan the entire set of records in the emp table for another match.
    Whereas
    Cursor c_sal is select sal from emp where empno = 7788; --> This will do the fetch operation only ones.
    Is this the case still True in Oracle 10g or 11i.
    Appreciate your help.
    Thankyou very much
    Madhu K

    the query is processed as follows (this is from ora doc)
    Parse:
    – Search for identical statement
    – Check syntax, object names, and privileges
    – Lock objects used during parse
    – Create and store execution plan
    Execute: Identify rows selected
    Fetch: Return rows to user process
    for cursor also same things are performed, but cursor is private sql area in which you can processes one row at a time, you can use cursor in your pl/sql program and access one row a time,
    so if you say,
    cursor c1 is select * from emp;
    c1 is private sql area where you can processes single row of emp , make comparisons, calculations etc,
    once you close the cursor this area is released and can be used by another cursor,
    the basic query processing rules remains the same,

  • Can I use a select and update statement in a single jsp file?

    I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
    note: I used a seperate table in BUY and SELL transaction
    After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
    select * from test, test1;
    update test
    set total_shares=total_shares-Stotal;
    where stock_code=Scode AND name_broker=Sbroker;
    Can i have both of these statements in the same jsp file in oder to update the buy table?
    Or can anyone suggest how can process that update?THANKS!
    --------------------

    Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?

  • Correct usage of select and option statements

    Is it ok if I say this in my option statement?
    <select name="XYZ" onchange="return valChange(this)">
    <option <%=Selected%> value="100"><%=100%%></option>Or should the option tag just contani the variable names instead of values directly?
    like this
    <option <%=aTmpSelected%> value="<%=abc%>"><%=fslr%></option>where atmpselected contains selected,
    abc contains 100,
    and
    fslr contains 100%,
    as values?
    Please specify using an example.
    Thanks for your time.

    Tutorial on how to use select elements:
    http://w3schools.com/tags/tag_select.asp
    Tutorial on how to use option elements:
    http://w3schools.com/tags/tag_option.asp
    Sandbox to test out your code:
    http://w3schools.com/html/tryit.asp?filename=tryhtml_select2
    The value attribute is the string that gets passed to the form when it's submitted. The text between the <option></option> tags is what gets displayed for that choice. You can use a conditional to decide if "selected" gets added to the html.

  • JDBC Sender - Different number of records selected and updated.

    Hi people,
    We have a JDBC -> Abap proxy scenario. The JDBC sender is pooling an Oracle database to retrieve data from a table X, each 30 minutes. The select and update statements in jdbc sender are below
    SELECT FIELD1, FIELD2, FIELD3 FROM MY_TABLE WHERE STATUS = 1
    UPDATE MY_TABLE SET STATUS = 2 WHERE STATUS = 1
    Sometimes the message sent to Abap proxy has, for example, 400 records. Looking at runtime workbench, message monitoring, for the same message there is a log like this
    Channel SENDER_JDBC_CHANNEL: Query executed successfully. Start update
    Channel SENDER_JDBC_CHANNEL: 510 row(s) updated successfully
    Someone has already experienced something like this? How can I handle this to guarantee to update only those read records?
    regards.
    roberti

    Hi All,
    Even we are facing the same problem.
    In our scenario, receiver is SAPR3. (IDOC)
    Will this parameter serialization work in our case?
    1. SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM PMBPITS.PITS_UNITY WHERE STATUS = '01' and rownum<200 . 
    2. UPDATE PMBPITS.PITS_UNITY SET STATUS = '02' , SAPTIMESTAMP = sysdate WHERE STATUS = '01' and rownum<200  ( currently the value is rownum < 5 )
    Thanks!!
    Regards
    Gouri

  • Delete statement that uses a sub-select with the statement in the cursor

    Hi all,
    How to write write a delete statement that uses a sub-select with the statement in the cursor?
    CURSOR excluded_dates IS         
           SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
          INTO my_current_date_time
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE';
    OPEN excluded_dates;
      LOOP
        FETCH excluded_dates INTO my_excluded_date;
        EXIT WHEN excluded_dates%NOTFOUND;
        DELETE FROM edr_rpt_tmp_inclusion_table
        WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
      END LOOP;
      CLOSE excluded_dates;Thanks

    Hi,
    In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
    View created
    SQL> select * from v_employees;
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE   JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
            110 John                 Chen                      JCHEN                     515.124.4269         28/09/1997  FI_ACCOUNT    8200,00                       108           100
            112 Jose Manuel          Urman                     JMURMAN                   515.124.4469         07/03/1998  FI_ACCOUNT    7800,00                       108           100
            125 Julia                Nayer                     JNAYER                    650.124.1214         16/07/1997  ST_CLERK      3200,00                       120            50
            127 James                Landry                    JLANDRY                   650.124.1334         14/01/1999  ST_CLERK      2400,00                       120            50
            131 James                Marlow                    JAMRLOW                   650.124.7234         16/02/1997  ST_CLERK      2500,00                       121            50
            133 Jason                Mallin                    JMALLIN                   650.127.1934         14/06/1996  ST_CLERK      3300,00                       122            50
            139 John                 Seo                       JSEO                      650.121.2019         12/02/1998  ST_CLERK      2700,00                       123            50
            140 Joshua               Patel                     JPATEL                    650.121.1834         06/04/1998  ST_CLERK      2500,00                       123            50
            145 John                 Russell                   JRUSSEL                   011.44.1344.429268   01/10/1996  SA_MAN       14000,00           0,40        100            80
            156 Janette              King                      JKING                     011.44.1345.429268   30/01/1996  SA_REP       10000,00           0,35        146            80
            176 Jonathon             Taylor                    JTAYLOR                   011.44.1644.429265   24/03/1998  SA_REP        8600,00           0,20        149            80
            177 Jack                 Livingston                JLIVINGS                  011.44.1644.429264   23/04/1998  SA_REP        8400,00           0,20        149            80
            181 Jean                 Fleaur                    JFLEAUR                   650.507.9877         23/02/1998  SH_CLERK      3100,00                       120            50
            186 Julia                Dellinger                 JDELLING                  650.509.3876         24/06/1998  SH_CLERK      3400,00                       121            50
            189 Jennifer             Dilly                     JDILLY                    650.505.2876         13/08/1997  SH_CLERK      3600,00                       122            50
            200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17/09/1987  AD_ASST       4400,00                       101            10
    16 rows selected
    SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
    2 rows deleted
    SQL> regards,

  • Combine select and update into single statement,without bind-variable

    I have a problem, that I think is not possible to solve the way I want to, but I just wanted to check before leaving the idea...
    I am looking for a way to combine the select and the update statement into one single statement. This is what I wan't to achive: select some data, and update the data selected before returning them.
    On this site http://www.psoug.org/reference/update.html I see that the following are possible:
    var bnd1 NUMBER
    var bnd2 VARCHAR2(30)
    var bnd3 NUMBER
    UPDATE employees
    SET job_id ='SA_MAN', salary = salary + 1000,
    department_id = 140
    WHERE last_name = 'Jones'
    RETURNING salary*0.25, last_name, department_id
    INTO :bnd1, :bnd2, :bnd3;
    I need to have this as a single statement, and cannot use bind-variables. So I was hoping that something like this could be possible:
    UPDATE customer c
    SET c.HAS_CREDIT ='1'
    WHERE c.HAS_CREDIT = '0'
    RETURNING c.CUSTOMER_NO, c.FIRSTNAME, c.LASTNAME
    where c.HAS_CREDIT = '1'
    But this doesn't compile, complaining of missing into (ORA-00925: missing INTO keyword). And even though I would like this to be possible because this would solve my current problem, I think it would be very confusing. For instance; would the where clause of the returning part be operating after the update or before?
    Any comments or suggestions on how to get it work in a single statement, or should I just leave this path straight away?

    Hi,
    RETURNING only works with bind variables, see
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/returninginto_clause.htm#sthref3006
    The real problem is that the form of RETURNING clause with bind variables is only valid for single row update or insert statements.
    To update (or insert) multiple rows and return the data, you will need to use
    RETURNING BULK COLLECT INTO clause. See
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2236
    Cheers,
    Colin

  • Mixed Signal Graph, Selected Cursors, and Cursor Position Problems

    I'm trying to work around an issue with a single multiplot cursor on a mixed-signal graph (doesn't work right, R&D bug report #100830) by grabbing the selected cursor x-position and updating that position across all four cursors, as seen below:
    However, I'm having two problems. 
    One, the selected cursor is not always the actual selected cursor.  Quite often, especially when selecting and dragging cursors 3 & 4 (indexed 2 & 3), the selected cursor shows up as 0 or 1.
    Two, and the one I'm more concerned about, is the fact that the four cursors X-positions never completely line up.  In every case, whichever cursor is deemed to be "selected", the other three will align to some point (the same for all three) that is offset from the actual value.  Please note that the X-values in my demonstration are identical (1000 points from 0.001 to 1) so I don't see this as being some snap issue where the value is offsetting to the closest available on the other arrays.
    I've attached my scratchpad demo.vi as an illustration. 
    Any help or insight is appreciated.
    Thanks,
    Mike Webster
    Attachments:
    demo.vi ‏47 KB

    I believe I found where the issue resides at least and a workaround.  This is a problem with XY graphs in general when trying to programmatically control the cursor position.  Somehow, the software goes looking for the nearest point instead of the identical point and has some sort of issue with its search algorithm.  Switching from attempting to match position to copying the cursor 'index' completely cleared up the problem I was having.  In the particular application I'm working on, the four graphs have identically spaced data on the X-axis, so this solution should work fine for me.

  • Auditing DDL and DML statements of selective IP addresses....

    Hi all,
    DB : 11.2.0.2 64 bit
    OS : RHEL 5.7 64bit
    Hi all,
    I want to audit all DDL and DML statements for some selective IP Addresses or hostnames.
    I read about Fine Grained Audit. I got the following code to enable auditing of nondatabase user's actions(Application users).
    created policy for client identifier.......
    BEGIN
    DBMS_FGA.ADD_POLICY(OBJECT_SCHEMA => 'OE',
    OBJECT_NAME => 'ORDERS',
    POLICY_NAME => 'ORDERS_FGA_POL',
    AUDIT_CONDITION => 'SYS_CONTEXT(''USERENV'', ''CLIENT_IDENTIFIER'') = ''Robert''',
    HANDLER_SCHEMA => NULL,
    HANDLER_MODULE => NULL,
    ENABLE => True,
    STATEMENT_TYPES => 'INSERT,UPDATE,DELETE,SELECT',
    AUDIT_TRAIL => DBMS_FGA.DB + DBMS_FGA.EXTENDED,
    AUDIT_COLUMN_OPTS => DBMS_FGA.ANY_COLUMNS);
    END;
    But I want to audit all DDL and DML statements for a particular schema say ABC from selective IP addresses or hostnames so how can I do this?
    Pl suggest.....
    Regards,
    Andy.

    Hi,
    You could :
    1. create a function, say myfunction, returning 1 if you want to audit, 0 otherwise
    This function would test sys_context('userenv','ip_address') within the desired IP address to be audited
    2. create your fga on the objects you want to audit adding the clause audit_condition=>'myfunction=1'
    Nicolas.

  • Palette highlight and Cursor do not align, making palette select difficult

    Folks,
    Don't expect I'm the first to report this but I didn't find anything about it from a forum search so better to report it then ignore it.
    Under the Eclipse IDE when trying to select one of the actions listed lower on the palette the cursor does not match the highlight. The lower you go in the list the farther off the alignment gets until, in order to select Sequence, the last item in the list, you have to have the cursor very far down past the sequence icon in order for it to be actually highlighted and selectable. Only then can it be selected and dragged to the designer view. The topmost icons align the cursor to the highlight well but the further you go down the list the farther off the alignment gets.
    Designer is 0.9.13, Eclipse is at Version: 3.1.0 Build id: I20050627-1435
    Thought you might want to know.

    Apparently the distribute spacing command only uses the top object as a reference. I would say that's a bug.

  • Performance Measure - Select SUM and Collect Statement.

    Dear All,
    I am using YNME_PROCESS_PO_CUST Badi in this i writing some validation Delivery Completion.
    For that i need to calculate GR qty and Delivery quantity based on this i need some validation. But here i confussed which statement i need to use for bast performance.
    Note: In Badi Item Level Data will be process one by one..like item level 10 then 20 then 30......Like that
    Code will like that---
    SELECT  SUM( menge )  FROM ekes
                                INTO  l_delqty
                                WHERE ebeln =  ls_mepoitem-ebeln
                                AND   ebelp =    ls_mepoitem-ebelp.
            SELECT  SUM( dabmg  )  FROM ekes
                             INTO  l_grqty
                             WHERE ebeln =  ls_mepoitem-ebeln
                             AND   ebelp =  ls_mepoitem-ebelp.
            l_delqty1 =  l_grqty - l_delqty.
            IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
            ENDIF.
    I check in SE38 response is better in this code.
    Other code may be like that .. same data will be like upper/
          SELECT * FROM ekes
                     INTO CORRESPONDING FIELDS OF TABLE it_ekes
                     WHERE ebeln =  ls_mepoitem-ebeln
                     AND    ebelp =   ls_mepoitem-ebelp.
          LOOP AT it_ekes.
            MOVE-CORRESPONDING it_ekes TO it_ekes1.
            COLLECT it_ekes1.
            CLEAR  it_ekes.
          ENDLOOP.
          READ TABLE it_ekes1 INDEX 1.
          IF sy-subrc EQ 0.
            l_delqty1 =  it_ekes1-menge - it_ekes1-dabmg.
          ENDIF.
        IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
       ENDIF.
    Can any send me document--
    Regard
    DK

    Hi,
    Single Select statement is certainly better.
    But no need to do select * and using into corresponding fields. These will reduce the performance. Also the loop statment is not absolutely correct. Following could be a sample code.
    TYPES: BEGIN OF gx_ekes,  (maintaining same sequence of fields as in select statement, this way no need of into corresponding fields)
                 ebeln type ebeln,
                 ebelp type ebelp,
                 menge type bbmng,
                 dabmg type dabmg,
                 END OF gx_ekes.
    DATA : lit_ekes TYPE TABLE OF gx_ekes,
                git_ekes TYPE TABLE OF gx_ekes,
                wa_ekes TYPE gx_ekes.
    SELECT ebeln
                  ebelp
                  menge
                  dabmg
    FROM ekes
      INTO TABLE it_ekes
    WHERE ebeln = ls_mepoitem-ebeln
    AND ebelp = ls_mepoitem-ebelp.
    LOOP AT lit_ekes INTO wa_ekes.
    COLECT wa_ekes INTO git_ekes.
    CLEAR: wa_ekes.
    ENDLOOP.
    CLEAR: lit_ekes.
    Now the first record in git_ekes will have the sum as only one line item is being passed in the user exit.
    Regards,
    Pranav.

  • Insert and select in one statement

    using MS Sql server and VB i can execute two queries Insert and select in one statement e.g. (insert into (....) values (...) Select @@Identity).
    how can i do the same thing using Oracle and VB. ???
    It gives error. here's what i want to do.
    (insert into table1 (...) values (...) Select table1_sequence.currval from dual )
    Khurram

    Here's how you can achieve the same Oracle :-
    Test Db>desc tmp1;
    Name Null? Type
    EMP_NO VARCHAR2(10)
    EID NUMBER
    Test Db>insert into tmp1 (emp_no, eid)
    2 select '123', 1
    3 from dual;
    1 row created.
    Shailender Mehta

  • The trackpad of my 13" macbook pro (mid 2012) has geen going nuts for about a week now. It randomly clicks and drags the cursor to all places on screen, it randomly clicks, selects and swipes. Have tried spm reset and pressure on whole trackpad. Help?!

    It goes nuts for hours and the next day it acts completely fine. My macbook is impossible to work with when the problem is active; it randomly clicks, drags, selects and even selects words (in a yellow colour) to come up with latin(?!) translations.
    Ive tried the reset (option+cmd+r+p) and it seemed to work at first but now it doesnt seem to have any effect whatsoever.
    Also tried to apply pressure to the entire surface of the trackpad or just the top corners; no effect whatsoever.
    It's been quite an expensive purchase for a young student like me and i've really enioyed it until last week.
    I'd be relieved if someone came up with a solution; especially since its warranty has expired for half a year now.

    Hi there Bram3,
    You may find the troubleshooting steps in the article below helpful.
    Portables and Magic Trackpad: Jumpy or erratic trackpad operation
    http://support.apple.com/kb/ts1449
    -Griff W. 

  • Invalid Cursor state Exception  -  Help required

    Hi,
    I'm having a web page(JSP), which is making use of 3 ResultSet objects. Using the first two, i'll populate two different Drop down list, with values from database(Access) while loading the page for first time.
    Now if the user select any value from any (or both) of drop down list and clicks submit, i need to display all values in database, meeting the criteria from first & second drop down list. For this selection, i'm using the third ResultSet variable. While executing the query, i'm sure that 3rd ResultSet is returning some value. But when i try to retrieve the value to a string variable, i'm getting the Invalid cursor state exception.
    Throughout the page, i haven't closed any of the ResultSet. When i closed the first and second ResultSets in the third function(where 3rd ResultSet is used), i'm not getting any value. Its returning like ResultSet closed.
    Please help me to get this solved. It's very urgent because without this, i cannot proceed further. Please share your ideas.
    Thanks in advace for your valuable help

    If you open a new resultset within the same statement, all previously opened will be closed.
    Read the API docs, luke.

  • Invalid cursor state when trying to insert record

    Hi everyone!
    I'm using JDBC-ODBC bridge to connect to a mySql database, which works fine. Then I try to insert new records, but this only works for the first record in the table.
    When there is already a record in the table, I always get "[Microsoft][ODBC Driver Manager] Invalid cursor state" when calling the updateRow()-method of the result set.
    Here is my code:            // open db connection
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Connection conn = DriverManager.getConnection("jdbc:odbc:TTManager", "xxxx", "xxxx");
                // Prepare SQL statement
                java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                ResultSet result = stmt.executeQuery("SELECT * FROM Player");
                result.moveToInsertRow();Then all fields are filled in this manner:            result.updateString("Name", name);And finally the insertRow should be written to the db:            result.insertRow();But at this point it gives the mentioned error, including these messages:         at sun.jdbc.odbc.JdbcOdbcResultSet.setPos(JdbcOdbcResultSet.java:5272)
            at sun.jdbc.odbc.JdbcOdbcResultSet.insertRow(JdbcOdbcResultSet.java:4132)Since I'm very unexperienced with Java, I guess (or hope^^) it's just some stupid beginner's mistake.
    Oh, almost forgot to mention: The new record's data doesn't violate any unique-constraints on the table, all fields are explicitely filled and all variable's data types are matching their according field types!
    Any help would be appreciated!
    reinski

    Ok, I needed to help myself and this is what I found out:
    If the table already contains records, it is not enough to doresult.moveToInsertRow();but I must beresult.last();
    result.moveToInsertRow();I didn't find any explanation and even the code examples from the Sun tutorial don't mention this, so I guess it's a bug occurring in my poor IT environment: DB server running mySQL 5.0.0-alpha on a P1-233-MMX w/ 64MB under WinNT4 (hey don't laugh!!^^).
    Maybe this information is of use to someone having similar problems...
    Greetings!
    reinski

Maybe you are looking for