Open the cursor

Oracle 11g

For a procedure, if I use the hardcode

procedure sp_test)

p_rc on sys_refcursor,

P_1...

P_2...

)

is

Start

Open the p_rc for

Select *.

from TEST_TABLE

...

But now I want to use the dynamically built sql, such as

if condition1 then

v_sql: =...

elsif condition2 then

v_sql: =...

run v_sql pubs

How can I find the the cursor in this case p_rc?

Thank you

Hello

If the query text is in v_sql, then you can open a cursor like this:

P_rc OPEN FOR v_sql;

There is no need to EXECUTE IMMEDIATE.

Tags: Database

Similar Questions

  • Open the cursor Question

    Hello

    Declare

    Cursor c

    is

    Select * from...

    Cursor c1

    is

    Select * from...

    Begin

    OPEN C;

    Loop

    Fetch c

    IN one;

    FETCH c1

    IN b;

    End loop;

    End;

    If I write as above on the right error ora-01001?

    I love below cannot?

    Declare

    Cursor c

    is

    Select * from...

    Cursor c1

    is

    Select * from...

    Begin

    OPEN C;

    OPEN c1;  ---????

    Loop

    Fetch c

    IN one;

    FETCH c1

    IN b;

    End loop;

    End;

    The code of follow through logically.

    First, you open two separated/not related sliders. (p.s. calling c1 and c_1 does not help you read what is happening - give meaningful names of things)

    You then in a loop.

    You get the first record of "c1".

    You retrieve the first recording of 'c_1 '.

    If you get a recording of "c1" (which you did the first time) then you are perpetuating and print the details of the employee him.

    If you get a recording of 'c_1' (which you did the first time) then you are perpetuating and print details of her Department.

    you loop around back.

    You retrieve the next record in "c1".

    You retrieve the next record in 'c_1 '.

    If you get a recording of "c1" (makes you this second time) then you perpetuate and print the details of the employee him.

    You will find then that 'c_1' did not return a second record for departments (because the query retrieves only one record for the Department 10), so that you leave the loop.

    Then, you close the sliders.

    That's how it works, but I doubt that's what you really wanted to.

    The number of times will make you a loop around the data depends on of what that either the query returns the least number of rows, in this case the request of the Prosecutor, which is only to recover 1.  By chance looking for employees first if you get 2 of them, but you will never get beyond this amount.

    So, of course, you can open the two sliders together if you want and close them together if you want... but you have to separate the curls as they are independent of each other:

    SQL > declare
    2 v_empno emp.empno%TYPE;
    3 v_deptno emp.deptno%TYPE;
    4 d_deptno dept.deptno%TYPE;
    5 c_emp cursor is
    6. Select empno,
    DeptNo 7
    8 of the emp
    9 where deptno = 10;
    10 c_dept of cursor is
    11. Select deptno separate
    12 of the Department
    13 where deptno = 10;
    14 start
    15 open c_emp;
    16 open c_dept;
    17 loop
    18 extract c_emp in v_empno, v_deptno;
    19 when out c_emp % notfound;
    20 dbms_output.put_line (' employee Details: ' | v_empno |) » '|| v_deptno);
    21 end of loop;
    22
    23 loop
    24 extract c_dept in d_deptno;
    25 exit when c_dept % notfound;


    26 dbms_output.put_line (' Department Details: ' | d_deptno);
    27 end of loop;
    28 close c_emp;
    29 close c_dept;
    30 end;
    31.
    Employee details: 7782 10
    Employee details: 7839 10
    Employee details: 7934 10
    Details of the Department: 10

    However, it is not advisable, you open cursors before using them and leaving them open after using them.

    Best practice would be...

    SQL > declare
    2 v_empno emp.empno%TYPE;
    3 v_deptno emp.deptno%TYPE;
    4 d_deptno dept.deptno%TYPE;
    5 c_emp cursor is
    6. Select empno,
    DeptNo 7
    8 of the emp
    9 where deptno = 10;
    10 c_dept of cursor is
    11. Select deptno separate
    12 of the Department
    13 where deptno = 10;
    14 start
    15 open c_emp;
    loop 16
    17 get c_emp in v_empno, v_deptno;
    18 when out c_emp % notfound;
    19 dbms_output.put_line (' employee Details: ' | v_empno |) » '|| v_deptno);
    20 end of loop;
    21 close c_emp;
    22
    23 open c_dept;
    24 loop
    25 extract c_dept in d_deptno;
    26 exit when c_dept % notfound;
    27 dbms_output.put_line (' Department Details: ' | d_deptno);
    28 end of loop;
    29 close c_dept;
    30 end;
    31.
    Employee details: 7782 10
    Employee details: 7839 10
    Employee details: 7934 10
    Details of the Department: 10

    Of course, if the sliders are linked (i.e. you want to get the Department information about the current employee you are looking at) then you need to do as I showed in my first answer.

  • PLS-00355 error when opened the cursor in the procedure

    Hello everyone,

    I have a problen that makes me crazy:

    Whenever I try to compile the following procedure, the error "PLS-00355: table using pl/sql not allowed in this context" occurs but I don't see what the problem is. I hope that the wisdome of the community will help to solve the problem.

    Here is the code:

    CREATE or REPLACE PROCEDURE data_year (study_year in NUMBER) HAVE
    CONSTANT CHAR Sep: = "";
    CURSOR cursor_year (year_of_interest NUMBER) IS
    Select
    BBS_CONDITIONS. COUNTRYNUM as a country,
    BBS_CONDITIONS. STATENUM as State,
    BBS_CONDITIONS. ROUTE road,
    BBS_ROUTES. LATITUDE lat,
    BBS_ROUTES. LONGITUDE as lon,
    BBS_SUMMARY. AUG as Aug,
    BBS_SPECIES. ENGLISH_COMMON_NAME as the name,
    BBS_SPECIES. MIGRATION_TYPE as migtype,
    BBS_SUMMARY. SPECIESTOTAL County,
    BBS_CONDITIONS. MONTH as smonth,
    BBS_CONDITIONS. STARTTIME as starttime,
    BBS_CONDITIONS. ENDTIME as end time,
    BBS_CONDITIONS. AMATURES amatures, as
    BBS_CONDITIONS. ASSISTANT Assistant
    of BBS_SPECIES.
    BBS_ROUTES,
    BBS_SUMMARY,
    BBS_CONDITIONS
    where BBS_ROUTES. ROUTE = BBS_CONDITIONS. ROUTE
    and BBS_ROUTES. STATENUM = BBS_CONDITIONS. STATENUM
    and BBS_ROUTES. COUNTRYNUM = BBS_CONDITIONS. COUNTRYNUM
    and BBS_SPECIES. AUG = BBS_SUMMARY. AUG
    and BBS_CONDITIONS. AN = BBS_SUMMARY. YEAR
    and BBS_CONDITIONS. ROUTE = BBS_SUMMARY. ROUTE
    and BBS_CONDITIONS. STATENUM = BBS_SUMMARY. STATENUM
    and BBS_CONDITIONS. COUNTRYNUM = BBS_SUMMARY. COUNTRYNUM
    and BBS_SPECIES. CLASS_ID = 0
    and BBS_CONDITIONS. AN = year_of_interest
    order by country, State, road, migtype, Aug.
    rec_year cursor_year % ROWTYPE;
    I have NUMBER: = 1;
    TYPE table_year_type IS TABLE OF cursor_year % ROWTYPE;
    table_year table_year_type;
    BEGIN - Beginning of the data_year procedure
    table_year: = table_year();
    OPEN cursor_year (study_year);
    LOOP
    EXTRACT the cursor_year in rec_year;
    EXIT WHEN cursor_year % NOTFOUND;
    table_year. EXTEND (1);
    table_year (i): = rec_year;
    i: = i + 1;
    END LOOP;
    CLOSE Cursor_year;
    DBMS_OUTPUT. Put_line ('country' | sep |) "the State" | Ms | "Route". Ms | "lat". Ms | "lon".
    || Ms | "Aug" | Ms | "name" | Ms | "migtype" | Ms | 'count '. Ms | 'month ' | Ms
    || "starttime" | Ms | "endtime" | Ms | "amatures | Ms | "Wizard");
    BECAUSE me in table_year. FIRST... table_year. LAST LOOP
    DBMS_OUTPUT. Put_line (to_char (table_year (i). Country) | Ms | To_char (table_year (i). State) |
    Ms | To_char (table_year (i) .route) | Ms | To_char (table_year (i). LAT) | Ms |
    To_char (table_year (i). LON) | Ms | To_char (table_year (i). AUG) | Ms |
    table_year (i) .name | Ms | To_char (table_year (i) .migtype). Ms |
    To_char (table_year (i). Count). Ms | To_char (table_year (i) .smonth). Ms |
    To_char (table_year (i). StartTime) | Ms | To_char (table_year (i). EndTime) | Ms |
    To_char (table_year (i). RPID) | Ms | To_char (table_year (i). Assistant));
    END LOOP;
    END; -End of the data_year procedure
    /

    Thanks in advance, TC

    Give a line number? I wonder if it might be

    table_year: = table_year();

    that is the origin of the problem. Try to remove and see.

    Better yet, change your code to

    ...
       TYPE table_year_type IS TABLE OF cursor_year%ROWTYPE INDEX BY BINARY_INTEGER;
    
       table_year     table_year_type;
    BEGIN         
    
        OPEN cursor_year (study_year);
        FETCH cursor_year BULK COLLECT INTO table_year;
        CLOSE cursor_year;
    ...
    

    Published by: Dave hemming on November 21, 2008 09:51

  • Open the cursor exceeds the maximum value

    Hello

    I'm under 10.2.0.1.0 and the open_cursor max value is set to 300.
    Earlier, my developers were getting error ORA-01000. However, when I checked again after two days, I see the number is 1605 way greater than the max value. Why I can't see any error now?

    Anyone know?

    Thank you.
    Shawn

    I see that the number is from 1605

    message SQL used to get this number

    OPEN_CURSOR is a session limit by

  • Open with the cursor

    Greetings-

    I have a block of code on a report in the grid control, and it works well.
    What bothers me is that I need to specify the parameter in the
    Open the cursor so many times. I know that there is an easier way.
    Here is a simple example of this article:


    T1d: = sysdate - 90

    my_str: = ' select * from my_table where collection_timestamp
    between: 1 and (: 1 + 1)';

    my_cursor cursor open for my_str using t1d, t1d.

    However - in my code I use this about 24 times. Any help would be appreciated.

    Thank you

    Brian

    Rate the original question when you asked it... However, it is possible to 'normalise' your bind variables in the query using subquery factoring for example

    declare
      dt1    date;
      my_str varchar2(32767);
    begin
      dt1 := sysdate - 90;
      my_str := 'with t as (select :1 as dt from dual)
                 select *
                 from my_table, t
                 where collection_timestamp between t.dt and (t.dt + 1)';
    
      open cursor my_cursor for my_str using dt1;
      ..
    

    If you are linking to the weighted subquery just inside, and then this subquery is used throughout the application to provide the values.

  • When a new tab opens the cursur button in the address bar to search and not the search engine

    When a new tab opens the cursor will move to the address bar to search and not to the search engine, I put to a new tab page.

    I went to about: config and changed keyword.enable to false. It works for the homepage at Firefox startup.

    How to disable the address for a new tab search, as I did for my homepage?

    sheilahsay

    Hello sheilahsay, maybe this addon works for you: https://addons.mozilla.org/firefox/addon/custom-new-tab/

  • Cursor of return of (nested) function - PLS-00201: identifier of the CURSOR must be declared

    Hello

    I have a function in which I use nested functions (because I don't want to create objects explicit / external, it is a requirement that I don't have any effect on / I don't want to change).

    In my external function, I use cursor by declaring them in IS-section and then open using the loop for instruction.

    In my inner function / nested, I also want to use a cursor.

    There I also said one like I did in an external function within the section IS of the nested function.

    SQL Developer complains about syntax error (';: wait ").

    When you try to compile the whole process I get the following error:

    "Error (97,14): PLS-00201: identifier 'CURSOR' must be declared '.

    It's my external function starts as:

    CREATE OR REPLACE FUNCTION FN_GENERATE_QUERY_PMT (instance_id_in IN NUMBER, language_in IN VARCHAR2)
    RETURN CLOB
    IS
         CURSOR c_outer IS
          SELECT * FROM BLA;
    

    When it comes to my internal function with the section IS of the external function and stands (inner functions should be at the end of the Section IS to stand behind the statements of variable and cursor, otherwise there will be an error):

    FUNCTION nfn_get_value (num_in IN NUMBER)
          RETURN SYS_REFCURSOR
        IS
          SYS_REFCURSOR c_inner IS
          SELECT *
          FROM BLUB;
        BEGIN
          RETURN c_where_in;
        END;
    

    After that there will be another nested function, then the BEGIN section will appear.

    When looking for 'function returns cursor' I can only find solutions where the cursor is declared in section IS (sometimes its an AS-section o_O * worried *) but wihtoug select, just declare type.

    The cursor focus is added in the Begin block to the way open for instruction. But I don't want to open it yet. I want to open the cursor using the loop statement. I am able to reopen? used can it be two sliders while one will not be closed properly?

    How to fix to return a cursor that I can use in my external function.

    Advice would be appreciated.

    Thanks in advance.

    Maybe I got the soultion
    First of all, I found this thread:

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:5241391331097

    said the following:

    2) a ref cursor is just a cursor.  a ref cursor is just a cursor.  a ref cursor is just a cursor.... (keep saying it over and over
    

    But fortuneately I also found this post:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:14188501024541

    where thankfully someone shared her knowledge with others:

    In view of this block of code - you may see more "prominent" unlike - any

    How many times you run this block - cursor C will always be select * twice.  The ref

    cursor is not guaranteed.

    Another difference is that a ref cursor can be returned to a client.  a plsql 'cursor cursor.

    cannot be returned to a client.

    Another difference is a cursor can be global - a ref cursor cannot (you cannot set

    them outside a procedure / function)

    Another difference is a ref cursor can be passed to the subroutine - a subroutine

    cursor cannot be.

    This explains why the samples seem always fair with open (Ref) cursor within the section to START.

    I expeceted this (as I wrote in the first post) and ask if the course of opening will be sent back twice or just redirect. I suppose it it reassigns who were just a little in performance.

    But I can't yet find this good explanation of this type anywhere within the documentation and of course I didn't read it all. Shame on me, but I'm always engaged by internet download.

    I would be grateful if someone could say my last statement and leave a comment on double-distribution of the refcursors has reopened.

    Thanks in advance.

  • I want to open a new tab, but keep the cursor in the adressbar. Right not every time I open a new tab, I come to a page with google search and the firefox logo.

    Everytime I open a new tab, I'm greeted by this page

    http://blog.Mozilla.org/UX/files/2012/05/Firefox-beta-13-redesigned-About_Home-Page1.PNG?128c42

    Is a small problem for me, because when I want the cursor at the beginning in the adressbar. So, if for example, I opened a new page, I type in imdb.com I receive directly on imdb.

    Today, however, with the Home tab firefox screen. I have to do a google search for imdb.

    A small problem perhaps, but enough to be annoying.

    Is there a way to move the settings or something similar, and keep the cursor in the address bar after you open a new tab?

    Hello

    If you only want the new tabs do not have home page, you can change it by going in your Subject: config page and replacing "browser.newtab.url" Subject: vacuum. For me at least, if I open a new tab on a white page, the cursor remains the address bar.

    In order to change your Firefox Configuration please follow the following steps:

    1. In the address bar, type Subject: config

    and press enter. The subject: config "this might void your warranty!" warning page may appear.

    1. Click on I'll be careful, I promise! to keep the comments: config page.

    If you also want to change your home page to a blank page, you can do so in virtue:

    • (on Windows) Tools > Options > general, or
    • Menu

      > Options (preferences on Mac and Linux) > general

    Then change the dropdown to "when Firefox starts:"so that it is set to 'Show a blank page'.»

    Note that you can continue to do research on the awesome bar and search bar where you want to do a Google search.

    Does this solve the problem? Let us know.

  • When I opened a new tab, the cursor is automatically in the field of navigation, because I reinstalled Firefox yesterday. Is there a solution?

    When I opened a new tab, the cursor is automatically in the field of navigation, because I reinstalled Firefox yesterday. Is there a solution?

    I solved.

    I installed mutorrent, which in turn installed 'Safe Protect' of 'Intermediary' that messed up my Internet browser settings.

    I uninstalled it and everything turned back to normal, when I opened a new tab, the cursor is automatically in the address bar (ie. it is highlighted).

    Thanks for your time.

  • At the opening of the cursor does not automatically go to the search box?

    When Mozilla Firefox is open, I expected the cursor in the default search box. No Ant that is why it must be located in the area before you can enter the search criteria.


  • When I click on the shortcut it does not open firefox but if I hold the cursor on the short cut it shows tabs from last time, but not open them

    But if I hold the cursor on the short cut, that it shows the last tab and how many pages come from my last visit, but will not open them no matter how many times I click it

    If you think that your Firefox window can be "off-screen" somewhere, what happens sometimes to certain users, this discussion has a few things to heal that: when I go to open firefox it appears on my toolbar, but not on my screen where it is?

  • When I place the cursor over a link means that there not respond.for ex when I opened my email yahoo, I can't signout in that.when I hover over signout what it na no respond.but in another browser it answer.

    When I place the cursor over a link means that there not respond.for ex when I opened my email yahoo, I can't signout in that.when I hover over signout what it na no respond.but in another browser it answer.

    This problem may be caused by the Yahoo! toolbar as scopes as well down and covers the top of the browser window, allowing links in this part of the screen not clickable.

    You can keep an eye on this thread:

  • When opening new tab I'm headed to Google, but the cursor remains in the address bar. Anyway to automatically move the cursor to the google search bar?

    Thank you in advance. I upgraded to firefox 4, and since then, I had a problem. When you open a new tab, I chose to be directed on google.com. In the past my cursor automatically went to the search bar on this page when I open a new tab. After the upgrade, the cursor remains right in the address bar, but I would like it moves automatically into the bar of google search on the page. Does anyone know how to fix this? Thanks again.

    What extensions do you use?

    A new tab opens by default like a Virgin tab (topic: empty).

    If this isn't the case, then an extension has changed this behavior.

    Start Firefox in Firefox to solve the issues in Safe Mode to check if one of the extensions of the origin of the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > appearance/themes).

  • My laptop can open internet explore properly, the cursor may work when you tap the address space to type a Web site, but the site it does not point to the search space to find anything except the right button

    My laptop can open internet explore properly, the cursor may work when you tap the address space to type a Web site, but the site it does not point to the search space to find anything except the right button. What is the problem? Harry

    When you try to search it's inside Windows or Internet explore?
    When is this last work fine?
    You did changes to the computer?
    Has it worked before, then you can try to run the system restore and check if that helps

    ;)

  • Is there a public api Api to check that the cursor is open or close for blackberry 6.0?

    Hi all

    is there an api to check the slider is open or close for Blackberry JDE 6.0.

    Thank you

    Navneet Gupta.

    Hi you

    First of all "accept the solution please...." »

    See this link for more information...

    http://www.BlackBerry.com/developers/docs/4.6.0api/NET/rim/device/API/system/sensor.html

    Net.rim.device.api.system import. *;
    Import net.rim.device.api.ui.UiApplication;
    Import net.rim.device.api.ui.component.RichTextField;
    Import net.rim.device.api.ui.container.MainScreen;

    SerializableAttribute public class SensorDemo extends UiApplication
    {
    public SensorDemo()
    {
    Screen SensorDemoScreen = new SensorDemoScreen();
    pushScreen (screen);
    }
    Public Shared Sub main (String [] args)
    {
    SensorDemo app = new SensorDemo();
    app.enterEventDispatcher ();
    }
    class SensorDemoScreen extends screen implements the SensorListener
    {
    private RichTextField statusField1;
    private RichTextField statusField2;

    public SensorDemoScreen()
    {
    setTitle ("sensor Demo");
    statusField1 = new RichTextField();
    statusField2 = new RichTextField();
    Add (statusField1);
    Add (statusField2);

    Check for the presence of a sensor
    Boolean hasFlipSensor, hasHolsterSensor, hasSliderSensor;
    hasFlipSensor = Sensor.isSupported (Sensor.FLIP);
    hasHolsterSensor = Sensor.isSupported (Sensor.HOLSTER);
    hasSliderSensor = Sensor.isSupported (Sensor.SLIDE);
    statusField1.setText ("Flip:" + hasFlipSensor + "\nHolster:")
    + hasHolsterSensor + "\nSlider:" + hasSliderSensor + "\n"); "."
    Check the status of a sensor
    If (Sensor.isSupported (Sensor.SLIDE))
    {
    int sliderState = Sensor.getState (Sensor.SLIDE);
    Switch (sliderState)
    {
    case Sensor.STATE_SLIDE_CLOSED:
    do something if the cursor is closed
    statusField2.setText ("cursor is closed.");
    break;
    case Sensor.STATE_SLIDE_IN_TRANSITION:
    do something about cursor in transition
    statusField2.setText ("Slider is between open and closed.");
    break;
    case Sensor.STATE_SLIDE_OPEN:
    do something if the cursor is open
    statusField2.setText ("slider is open.");
    break;
    by default:
    statusField2.setText ("cannot determine the State of the cursor from.");
    }
    }
    Listening to changes to a sensor
    Sensor.addListener (Application.getApplication (),)
    Sensor.SLIDE);
    }

    implementation of the SensorListener.onSensorUpdate)
    change cursor only checks
    ' public void onSensorUpdate (int sensorID, int update)
    {
    If (sensorID is Sensor.SLIDE)
    {
    If (update is Sensor.STATE_SLIDE_OPEN)
    {
    do something if the cursor is now open
    statusField2.setText ("Slider is now open.");
    }
    ElseIf (update == Sensor.STATE_SLIDE_IN_TRANSITION)
    {
    do something if the cursor is now transitioning
    statusField2.setText ("Slider condition changes.");
    }
    ElseIf (update == Sensor.STATE_SLIDE_CLOSED)
    {
    do something if the cursor is now closed
    statusField2.setText ("Slider is now closed.");
    }
    }
    }
    }
    }

    .................

    Manoj Kumar bakkar

Maybe you are looking for