Repeat a Select statement

Hello

I run a query on a very large table, something like

SELECT (SOME SUBQUERIES ON THE MOVEMENT), (SOME MORE SUBQUERIES), ().
MOVEMENTS MV
WHERE MV. EFFECTIVE_DATE > = START DATE
AND MV. EFFECTIVE_DATE < END DATE
AND... CERTAIN OTHER CONDITIONS

My problem is that the runtime grows exponentially with the length of the interval between SOME_START_DATE and SOME_END_DATE.
So, for an interval of a month, it takes a minute but for a period of two months, that he just keeps going, I ran out of patience after about 15 min.
I want to start for a long interval of the year so I was wondering if there is a way to repeat the select statement in a list of dates in PL/SQL?
Or maybe a different approach?

Would appreciate some advice

Thank you

939478 wrote:
Or maybe a different approach?

Yes!
First: Join the tables instead of asking the database to do subqueries for each line you want from the MOVEMENTS.
Second: Gives us a small input and outputs expected, so we can work out a solution.

Tags: Database

Similar Questions

  • Several Select statements fill Horizontal

    Hello
    I wonder how to fill these three instructions select a line, horizontal. The data does not correctly from my code below.
    The first statement returns 4 rows
    The second statement returns 27 lines
    The last third statement returns 31 rows
    My problem is that when the code below runs more than 500 rows are returned. What I do wrong to not fill the
    results.
    Example of how the data should look like, I don't understand the third declaration for space.
    CUSTOMER NAME - CUST_FIRST_NAME -CUST_LAST_NAME - CUST_CITY | CUSTOMER NAME - CUST_FIRST_NAME -CUST_LAST_NAME - CUST_CITY 
             1                           JOHN                   DOE                 HOUSTON                1                       CHERYL                   JONES                WACO  
             1                           BOB                     BOBBY                DALLAS                 1                       ANNETTE                JONES                AUSTIN
              --this data should not be repeating since the other select statements             1                       TOM                       BOBBY               JACOB
              --has more rows, these rows should be empty                                             1                       TOMMY                   BANKS               ROB
                                                                                                                           1                       BILLY                      HANK                 TOM  
    select distinct x.*, y.*, z.*
    from
    (select count(*) as "CUSTOMER NAME", 
    CUST_FIRST_NAME,
    CUST_LAST_NAME,  
    CUST_CITY
    from DEMO_CUSTOMERS
    where CUST_FIRST_NAME  like '%A%'
    --and HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
    GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
    ORDER BY CUST_FIRST_NAME ASC) x,
    (select count(*) as "CUSTOMER NAME", 
    CUST_FIRST_NAME,
    CUST_LAST_NAME,  
    CUST_CITY
    from DEMO_CUSTOMERS
    where CUST_FIRST_NAME  not like '%A%'
    --and HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
    GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
    ORDER BY CUST_FIRST_NAME ASC) y,
    (select count(*) as "CUSTOMER NAME", 
    CUST_FIRST_NAME,
    CUST_LAST_NAME,  
    CUST_CITY
    from DEMO_CUSTOMERS
    --where HIRE_DATE BETWEEN TO_DATE(:P10_START_DATE, 'MM/DD/YYYY') AND TO_DATE(:P10_END_DATE, 'MM/DD/YYYY')
    GROUP BY CUST_FIRST_NAME, CUST_LAST_NAME, CUST_CITY
    ORDER BY CUST_FIRST_NAME ASC) z;
    I hope someone can help me with this, thanks a lot.

    Hello

    The best is probably the cross join the demo_customer table will be a table that has 3 lines (so that the demo_customers data can be repeated up to 3 times, that the conditions are met), assign a number line (r_num) for the data replcated and pivot so that data on a line by r_num like that :

    WITH     cntr     AS
    (
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 3
    )
    ,     got_criteria     AS
    (
         SELECT     d.cust_first_name, d.cust_last_name, d.cust_city
         ,     CASE
                   WHEN  c.n     = 1
                   AND   cust_first_name         LIKE '%A%'
                         THEN  c.n
                   WHEN  c.n     = 2
                   AND   cust_first_name     NOT LIKE '%A%'
                         THEN  c.n
                   WHEN  c.n = 3
                   AND   cust_first_name     >= 'A'
                         THEN  c.n
              END     AS crit_num
         FROM          demo_customers     d
         CROSS JOIN     cntr          c
    --     WHERE   hire_date     BETWEEN     TO_DATE (:p10_start_date, 'MM/DD/YYYY')      -- Filter as much as possible here
    --                    AND     TO_DATE (:p10_end_date,   'MM/DD/YYYY')
    )
    ,     got_r_num     AS
    (
         SELECT     got_criteria.*
         ,     DENSE_RANK () OVER ( PARTITION BY  crit_num
                                   ORDER BY          cust_first_name
                             ,                cust_last_name     -- Be sure to include these
                             ,             cust_city
                           )      AS r_num
         FROM    got_criteria
         WHERE     crit_num     IS NOT NULL
    )
    SELECT       r_num
    ,       NULLIF (COUNT (CASE WHEN crit_num = 1 THEN 1 END), 0)          AS cnt_1
    ,       MIN   (CASE WHEN crit_num = 1 THEN cust_first_name END)     AS first_name_1
    ,       MIN   (CASE WHEN crit_num = 1 THEN cust_last_name  END)     AS last_name_1
    ,       MIN   (CASE WHEN crit_num = 1 THEN cust_city       END)     AS city_1
    ,       NULLIF (COUNT (CASE WHEN crit_num = 2 THEN 1 END), 0)          AS cnt_2
    ,       MIN   (CASE WHEN crit_num = 2 THEN cust_first_name END)     AS first_name_2
    ,       MIN   (CASE WHEN crit_num = 2 THEN cust_last_name  END)     AS last_name_2
    ,       MIN   (CASE WHEN crit_num = 2 THEN cust_city       END)     AS city_2
    ,       NULLIF (COUNT (CASE WHEN crit_num = 3 THEN 1 END), 0)          AS cnt_3
    ,       MIN   (CASE WHEN crit_num = 3 THEN cust_first_name END)     AS first_name_3
    ,       MIN   (CASE WHEN crit_num = 3 THEN cust_last_name  END)     AS last_name_3
    ,       MIN   (CASE WHEN crit_num = 3 THEN cust_city       END)     AS city_3
    FROM       got_r_num
    GROUP BY  r_num
    ORDER BY  r_num
    ;
    

    The result of your sample data is:

    .R_ CNT FIRST    LAST                CNT FIRST    LAST                CNT FIRST    LAST
    NUM  _1 _NAME_1  _NAME_1  CITY_1      _2 _NAME_2  _NAME_2  CITY_2      _3 _NAME_3  _NAME_3  CITY_3
    --- --- -------- -------- ---------- --- -------- -------- ---------- --- -------- -------- ----------
      1   1 ABBY     DUNN     MOBILE       1 JOHN     EDDY     DALLAS       1 ABBY     DUNN     MOBILE
      2   1 EDWARD   TODD     AUSTIN       1 JOHN     JAMES    HOUSTON      1 EDWARD   TODD     AUSTIN
      3                                    1 JOHNNY   GEORGE   CINCY        1 JOHN     EDDY     DALLAS
      4                                    1 MILLY    BROOKS   DE RIDDER    1 JOHN     JAMES    HOUSTON
      5                                                                     1 JOHNNY   GEORGE   CINCY
      6                                                                     1 MILLY    BROOKS   DE RIDDER
    

    This has only to make a pass through the demo_customers table, so I think it will be faster to do a self-join, where you have to make a separate pass mark for each criterion.
    Make sure that the analytical got_rnum.r_num ORDER BY clause contains all the columns that have been in your original GROUP BY, even if you don't really care to their order. The main request will make a GROUP BY r_num, so including the columns in this clause ORDER BY to include in the GROUP BY.

    The problem with the full outer join is that you still do not put join conditions after the individual tables. After that the each keyword JOIN there will be a table name or a alias and immediately after that must come the key word WE followed by a coindition to join.
    I made a mistake earlier: when full outerer joining several tables, would better meet you each new table in each of the previous tables, because it is unclear which of these tables may be missing due to the outer join. In other words, the join condition for f had better be:

    ON           f.r_num = COALESCE (d.r_num, e.r_num)
    

    because d.r_num or e.r_num could be NULL, because the outer join.

  • SQL select statements

    Hey everybody,

    First of all, Yes, I searched through the 8.5 database schema guide.  As I went through the scheme, I've developed some ideas on how to collect the data you want.  However, if someone has already developed or found the SQL statements (which I'm sure that someone already has) it would help by reducing to the minimum of the buggs in my data collection program.

    All these statistics must be grouped by CSQ and selected for a certain time interval ( and ).  That is, levels of 1 hour.  I have no problem to get a list of results and then perform v.f. to achieve the desired final result.  Also, if I need to run several select statements for tables of essentially two join, please include two statements.  Finally, I saw the RtCSQsSummary table, but I need to collect data for the past, not at this time.

    1 total calls presented by the CSQ

    2. total number of calls answered by the CSQ

    3 total number of calls abandoned by the CSQ

    4. percentage of calls abandoned by CSQ (if it is not stored in the database, I think: /)

    5. average abandon time in seconds (if it is not stored in the DB, I think: sum () /)

    6. service level - % calls answered in 90 seonds by a set of skills (I have seen metServiceLevel in the ContactQueueDetail table; however, I need to find how to configure this threshold for application)

    7. average speed of response by CSQ

    8 average conversation by CSQ calls

    9. the aggregates connected full-time resources or agents CSQ

    10. resources/agents of CSQ ready time

    I realize that some of them should be easy to find (as I always am search in the guide of db schema), but I was reading how a new record is created for each step of the call so I could easily see how I could get inaccurate information without properly developed select statements.

    Any help will be greatly appreciated.

    Brendan

    Brendan,

    I read your message very well.

    You have the schema of database with tables and description. each table has its associated tables (connected with primary and foreign keys). I think you should start the tables to determine what you need.

    Cisco uses the stored procedure to prepare the reports. the stored procedure is 'sp_csq_interval' to create the report.

    Activity report of Queue Service contact"

    HTH

    Anas

    Please note all useful posts

  • uniol all in the select statement

    Hi I have a situation where I have to return the value based on the if statement, is it possible to put union all in the select statement

    My use case is

    IN the column State

    If column01 > 0 to condtion 't'

    IF column02 > 0 that the condition of 'Y '.

    Condition IF COLUMN03 > 0 THAN 'w '.

    If COLUMN04 > 0 that the condition of "Z".

    Select 't'

    TableName

    where column01 > 0

    Union of all the

    Select "y".

    TableName

    where column02 > 0

    Union of all the

    Select 'W '.

    TABLENAME

    WHERE COLUMN03 > 0

    I have what it takes to show value as it

    EmpName, condition, empno

    Jerry, T, 0158754585

    TOM, Y, 0054789568

    Am in oracle database 11 g 2

    Yes you can put all THE UNION here

    Select empname, 't' State, empno from tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno from tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, condition of "Z", empno FROM tablename WHERE COLUMN04 > 0

    and if you are looking for how to remove duplicates because your line might have satisfied all the conditions and my happen 4 times in your result set, you just need to give them an order and filter it.

    For example, you want this

    If column01 > 0 to condtion 't'

    ELSE IF column02 > 0 that the condition of 'Y '.

    Another condition of THAN > 0 IF COLUMN03 'w '.

    otherwise if COLUMN04 > 0 that the condition of "Z".

    Select empname, condition, empno, in

    (

    Select a.*, row_number() over (partition by empno arrested by myorder) rn

    Of

    (

    Select empname, 't' State, empno, 1 myorder tablename where column01 > 0

    Union of all the

    Select empname, 't' State, empno, 2 myorder tablename where column02 > 0

    Union of all the

    Select empname, condition of "W", empno 3 myorder FROM tablename WHERE COLUMN03 > 0

    Union of all the

    Select empname, empno, condition of 'Z', 4 myorder FROM tablename WHERE COLUMN04 > 0

    ) a

    ) where rn = 1

  • Skip and capture the Oracle SQL record dirty in a select statement

    Hello

    I have the Oracle Oracle 11.2.0.4 database when I run a select query.

    Question:

    10 columns have given Date format. When I try to execute this query into a FROG he says, a month not valid. Since the records are billion in nature, I am not able to know which line has this problem.

    Is there a way I can capture the failed row and add it to other tables and continues with the select statement regardless of this error

    OK, you have several TO_DATE functions fed a string that is built on the fly.  At least part of the time, the chain that is built does not match the date format mask used.

    For example:

    TO_DATE (SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID), 0, 8). » -'|| SUBSTR (TO_CHAR (SQ_W_PURCH_CYCLNS_ORA. (LAST_SUBMITTED_ON_DTTM_WID), 9, 6), "YYYYMMDD-HH24MISS")

    "SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' does not have a string where characters 5-6 are in the range 01-12.  You'll have to do an analysis on this column.  From its data and how that is managed by to_char.  What ARE the data type of ' SQ_W_PURCH_CYCLNS_ORA. LAST_SUBMITTED_ON_DTTM_WID' and what is a typical value?

    As others have said, this is simply an impossibility for a column of a table to actually have invalid month (or day, or year, or hour or minute or second).  ONLY, you get this error during the conversion of a string to a date with the TO_DATE function.

  • SELECT statement

    Dear all,

    We hope that all are doing well.

    I need your help once again, my requirement is to write a trigger for "select statement" on a particular table, the name and the date of the user who executed.

    your help will be appreciated.

    Thanks in advance.

    OS: RHEL 6.1

    DB: 11.2.0.3

    Trigger is not possible on the SELECT statement, you can audit only by database.

    Or can save your select queries to application level.

  • Need help with the use of GROUP BY in a select statement UNION

    I am writing a query that allows to combine a legacy system that interfaces it is trial balance in the Oracle of R12 GL.  It was only meant to continue for a month or two, but it is likely to continue for 6 months. Please Auditors Auditors, to provide proof that the system is in balance with Oracle GL.  By my verification requirements, I need to make a full reconciliation from the month of conversion (life in the amount of date), then PTD for each month. 

    The legacy account is placed in attribute1 on the lines of the journals. Uses of the old system balancing segments that are also used on the platform in Oracle for this division, i.e., Procure-to-Pay has been cut over Oracle, but not everything yet.  So, I can't count on the GL_BALANCES table for the info, I get from the JE_LINES.

    My problem is not the only request for the month.  But when I try to combine the queries with a Union, to aggregation of each measurement period in its own column, the group is necessary after each selected instruction rather than allowing me to put at the end of the UNION.  (When I put the group by at the end of the UNION, I have the 'not one group' function)

    So I get duplicate for each month of discrete measure accounts. When I duplicate in my Oracle database accounts, I can't count on the VLOOKUP function in excel to exactly match an account of inheritance.  I know there are more sophisticated ways to provide this output, but I'm hoping to get this info in a simple query.

    Thank you in advance for any advice you can provide

    Example of data output (the goal for me is to get the two rows to appear as one based on common points on the LEGACY_ACCOUNT and the ORACLE ACCOUNT

    The LEGACY ACCOUNT ORACLE ACCOUNT JUN_15 JUL_15 AUG_15 SEP_15 OCT_15 NOV_15 DEC_15
    010000001109000003584190-600552-1001-100231-000-0000-0000-000000-242961.040000
    010000001109000003584190-600552-1001-100231-000-0000-0000-00000192588.0200000

    Here is a simplified version of my code that returns both records.  In my research, I had found a number of conversations where it has been shown that the group could be put at the end of the select statement.  However, when I remove the group from the first select statement I get SQL error: ORA-00937: not a function of simple-group

    Select

    l.attribute1 LEGACY_ACCOUNT,

    C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,

    JUN_15 TO_NUMBER('0').

    JUL_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),

    TO_NUMBER('0') AUG_15.

    TO_NUMBER('0') SEP_15.

    TO_NUMBER('0') OCT_15.

    TO_NUMBER('0') NOV_15.

    DEC_15 TO_NUMBER('0')

    Of

    b GL.gl_je_batches,

    GL.gl_je_headers h,

    GL.gl_je_lines l,

    GL.gl_code_combinations c,

    GL.gl_je_sources_tl j

    where b.je_batch_id = h.je_batch_id

    and h.je_header_id = l.je_header_id

    and l.code_combination_id = c.code_combination_id

    and h.je_source = j.je_source_name

    and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)

    ('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')

    and j.language = 'en '.

    and h.PERIOD_NAME ("JUL-15'")

    Group

    l.attribute1,

    C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8

    UNION

    Select

    l.attribute1 LEGACY_ACCOUNT,

    C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | COMBINATION OF C.SEGMENT8,

    JUN_15 TO_NUMBER('0').

    TO_NUMBER('0') JUL_15.

    AUG_15, sum (NVL(l.accounted_dr,0.00)-NVL(l.accounted_cr,0.00)),

    TO_NUMBER('0') SEP_15.

    TO_NUMBER('0') OCT_15.

    TO_NUMBER('0') NOV_15.

    DEC_15 TO_NUMBER('0')

    Of

    b GL.gl_je_batches,

    GL.gl_je_headers h,

    GL.gl_je_lines l,

    GL.gl_code_combinations c,

    GL.gl_je_sources_tl j

    where b.je_batch_id = h.je_batch_id

    and h.je_header_id = l.je_header_id

    and l.code_combination_id = c.code_combination_id

    and h.je_source = j.je_source_name

    and c.segment1 ('190 ', '191', '192', '193', '194', ' 195 ', ' 196',' 197', ' 198 ', ' 199',)

    ('200 ', '203', ' 205', '206 ', '330', '331', '332',' 333 ', ' 334',' 335', ' 336 ', ' 337')

    and j.language = 'en '.

    and h.PERIOD_NAME ("AUG-15'")

    Group

    l.attribute1,

    C.SEGMENT1: '-' | C.SEGMENT2: '-' | C.SEGMENT3: '-' | C.SEGMENT4: '-' | C.SEGMENT5: '-' | C.SEGMENT6: '-' | C.SEGMENT7: '-' | C.SEGMENT8

    order by 1

    Is there a good reason to make this period both as a series of trade unions?  This looks like a classic pivot for me query.  This will make a way through the tables and should get the desired results.

    Select l.attribute1 legacy_account,

    c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' | c.segment4: '-' |

    c.segment5: '-' | c.segment6: '-' | c.segment7: '-' | combination of c.segment8,

    sum (case when h.period_name = 'JUN-15'

    then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)

    otherwise 0 end) jun_15,.

    sum (case when h.period_name = 'JUL-15'

    then nvl(l.accounted_dr,0.00)-nvl(l.accounted_cr,0.00)

    otherwise 0 end) jul_15,.

    - and similar to DEC - 15

    GL.gl_je_batches b, gl.gl_je_headers h, gl.gl_je_lines l.

    GL.gl_code_combinations c, gl.gl_je_sources_tl j

    where b.je_batch_id = h.je_batch_id

    and h.je_header_id = l.je_header_id

    and l.code_combination_id = c.code_combination_id

    and h.je_source = j.je_source_name

    and c.segment1 ('190', '191', '192', '193', '194', '195',' 196', ' 197',

    '198 ', '199', '200', '203', '205' ', 206',' 330 ', ' 331',

    "332 ', '333', '334', '335',' 336 ', ' 337')

    and j.language = 'en '.

    and h.period_name (' Jun-15', ' 15 JUL', ' AUG-15'... "" ")

    L.attribute1 group,

    c.Segment1: '-' | c.Segment2: '-' | c.segment3: '-' |

    c.segment4: '-' | c.segment5: '-' | c.segment6: '-' |

    c.segment7: '-' | c.segment8

    If you're on the 11G version of the database, you might want to look at the PIVOT keyword that will do the same thing in a more concise expression.

    John

  • How to INSERT a SELECT statement with a GROUP BY clause on a table with an IDENTITY column?

    n an application, I intend to truncate and insertion on a 12 c Oracle database, but have found this problem with a IDENTITY column. Even if the INSERT... SELECT statement works on most SELECT uses I tried, if this statement was also a GROUP BY clause, it does not work, delivering a "ORA-00979: not a GROUP BY expression ' complaint. Some examples of code:

    create table aux ( owner_name varchar2(20), pet varchar2(20) ); 

    insert into aux values ('Scott', 'dog');

    insert into aux values ('Mike', 'dog');

    insert into aux values ('Mike', 'cat');

    insert into aux values ('John', 'turtle'); 


    create table T1 (

    id number generated always as identity,

    owner_name varchar2(20),

    pet_count number );

    select owner_name, count(*) as pet_count from aux group by owner_name; -- works just fine

    insert into T1 (owner_name, pet_count) select owner_name, count(*) as pet_count from aux group by owner_name; -- doesn't work

    The select statement works by itself, but it fails as an INSERT... SELECT statement.

    Appreciate the help!

    Looks like a bug. You must open the SR with Oracle. Meanwhile, you could materialize select:

    SQL > insert into T1 (owner_name, pet_count)
    2 with t as (select / * + materialize * / owner_name, count (*) as pet_count to the owner_name group)
    3. Select owner_name, pet_count t
    4.

    3 lines were created.

    SQL > select * from t1;

    ID OWNER_NAME PET_COUNT
    ---------- -------------------- ----------
    1 John                          1
    Scott 2 1
    3 Mike                          2

    SQL >

    Keep in mind index THAT MATERIALIZE is undocumented.

    SY.

  • DDL lock on the object in a SELECT statement?

    Environment:

    Oracle 11.2.0.4 EE on Solaris

    My client called me when she was trying to create a new index on a table and the process was just hanging.  Also, she was not able to DELETE an existing index on the same table, which deal with hang them as well.

    After reviewing the advice DBA_DDL_LOCKS, I found a DDL lock on the target of the index table.

    The DDL lock is held by a process doing a SELECT on the table and this process worked for several hours.

    There was no entry in V$ LOCKED_OBJECTS for the table.

    I don't know, yet, what other operations prior to the SELECT statement in the offending process, I have not heard of the user yet.

    I realize a DDL lock is placed on objects to prevent changes while specific operations are directed against this object, i.e. the DROP, UPDATE, compile the PACKAGE, etc.

    Question: Is a select also place a DDL lock on a table at a level that would avoid a new index is created or an existing index having fallen?

    Thank you very much for your comments!

    Any reference to the resolution is greatly appreciated.

    I searched some Concepts Developers Guide, SQL, even Google reference Guide.

    -gary

    > My question is now, this lock persists for the duration of the running query?

    Easy enough to show that it is not.

    Session1:

    SQL> create table foo(bar number);     
    
    Table created.                         
    
    SQL> insert into foo values(1);       
    
    1 row created.                         
    
    SQL> commit;                           
    
    Commit complete.                       
    
    SQL> variable x refcursor
    SQL> variable a number
    SQL> begin
      2  open :X for select bar from foo;
      3  end;
      4  /                                 
    
    PL/SQL procedure successfully completed.
    

    Session 2:

    SQL> drop table foo;
    
    Table dropped.     
    

    Note that I was able to remove the table even if select is still 'in progress' - the cursor is open.

    If you really want to blow your mind, go back to the session 1:

    SQL> begin
      2  fetch :X into :a;
      3  end;
      4  /                                
    
    PL/SQL procedure successfully completed.
    
    SQL> print a                          
    
             A
    ----------
             1       
    

    The picture has gone, but I can always look for him. However, try again:

    SQL> /
    begin
    *
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00942: table or view does not exist          
    

    Note that the forum software is stupid. is: followed by x. seems it's really important to have a smiley to lovey eyes in a technical forum.

    Edit - and when you format the SQL code, it is removed completely and render invisible... silly.

    I edited my code to use: X and the problem disappeared...

  • How to format the output of a .sql script that has select statements.

    Hello

    I have a .sql script which is having several select statements. Each Select statement is to have hundreds of Table columns.

    When we run the .sql script, we are unable to read the output.

    Please let know us the commands that we include for better readable output format.

    You work with the lin standard set 80.
    Increase this setting to set lin 3000 or more.

  • SELECT statement in the script output window

    Hello

    SQL Dev 4.0.3

    is it possible to include select statements from the command run the Script in the Script Output window?

    Is the result in the window:

    Select 1... ;

    results

    Select 2... ;

    results

    Joop

    try to put "set echo on" (without the quotes) as the first line and make sure that you use F5 to run the script... like sqlplus.

  • executes a select statement, each minute for half an hour

    Hi all

    I want to run a SELECT statement on a table every minute for half an hour.

    Something like this:

    Begin

    Do all the 1 minute for 30 Min

    Select col1, col2 from mytable

    End

    I thought about PL/SQL loop. But no matter what example with timekeeping.

    I don't care?

    Thank you and best regards.

    Hello

    As John said, you can use DBMS_SCHEDULER for this. That being said, you just can't run a query and do nothing with its result. You must do something with it.

    Here is an example showing how to create a task that runs every minute for a total of 30 min

    BEGIN

    DBMS_SCHEDULER. Create_Job (job_name-online 'MY_JOB',

    job_type-online "PLSQL_BLOCK."

    job_action => ' DECLARE val1 number; val2 number; BEGIN SELECT 1, 2 INTO val1, val2 FROM DUAL; END;',

    start_date => SYSDATE,

    End_date => SYSDATE + 30 /(24*60),

    repeat_interval => ' FREQ = MINUTELY ",

    auto_drop => TRUE,

    enabled-TRUE online

    );

    END;

    /

    It will start immediately and end 30 minutes later (it will be automatically abandoned). As you can see, the result of the query is placed in the variables. Thus, this work is useless.

  • SELECT statement to return a type in Oracle objects

    Hi all, I have created a small system for Uni using oracle objects and types. I have a table person with type of seller under the person table and the type of claimant to the title of the person table. I need the select statement to return data of the person, table, but only the type of applicant data. for example, SELECT * FROM person_tab, WHERE the type is applicant_t. I know it's probably simple, but just can't get the syntax right. The code all series just may not get the right to choose. Thanks for your time.

    create type appointment_t;
            
    create type property_t;
    
    create type telephone_t as object (
        weekdayDaytime varchar2(15),
        weekdayEveningAndWeekend varchar2(15));
    
    create type person_t as object (
        person char(6))
        not final;
    
    create type appointment_list_t as table of ref appointment_t;
    
    create type property_list_t as table of ref property_t;
    
    create type salesperson_t under person_t (
        sSurname varchar2(20),
        sForename varchar2(20),
        dateOfBirth varchar2(12),
        makes appointment_list_t,
        member function appointments_made return number );
    
    create type applicant_t under person_t (
        aSurname varchar2(20),
        aForename varchar2(20),
        dateOfBirth varchar2(12),
        aAddressLine1 varchar2(25),
        aAddressLine2 varchar2(25),
        aTown varchar2(20),
        telephoneNums telephone_t,
        maxPrice number(10),
        desiredArea varchar2(20),
        attends appointment_list_t,
        member function appointments_attended return number );
    
    create or replace type body salesperson_t as
    member function appointments_made return number is
        total number;
    begin
        total := self.makes.count;
        return total;
        end;
    end;
    
    create or replace type body applicant_t as
    member function appointments_attended return number is
        total number;
    begin
        total := self.attends.count;
        return total;
        end;
    end;
    
    create or replace type appointment_t as object (
        appointment char(10),
        appdate date,
        apptime varchar2(15),
        appointmentType varchar2(15),
        levelOfInterest integer(3),
        offerMade number(10),
        is_made_by ref salesperson_t,
        is_attended_by ref applicant_t,
        is_related_to ref property_t);
        
    create or replace type property_t as object (
        property char(10),
        dateOfRegistration date,
        propertyType varchar2(15),
        bedrooms integer(2),
        receptionRooms integer(2),
        bathrooms integer(2),
        garage varchar2(5),
        garden varchar2(6),
        regionArea varchar2(20),
        pAddressLine1 varchar2(20),
        pAddressLine2 varchar2(20),
        pTown varchar2(20),
        askingPrice varchar2(20),
        relatesTo appointment_list_t);
    
    create table person_tab of person_t (
        person primary key );
        
    create table property_tab of property_t (
        primary key(property))
        nested table relatesTo store as relates_to_table;
        
    create table appointment_tab of appointment_t (
        primary key (appointment),
        scope for (is_made_by) is person_tab,
        scope for (is_attended_by) is person_tab,
        scope for (is_related_to) is property_tab);
        
        
    
    insert into person_tab
    values (salesperson_t('s001', 'Fontigue', 'Farquar', '22-feb-1980', appointment_list_t()));
    
    insert into person_tab
    values (salesperson_t('s002', 'Richmond', 'Neil', '30-feb-1983', appointment_list_t()));
    
    insert into person_tab
    values (salesperson_t('s003', 'Devere', 'Jeremy', '03-mar-1977', appointment_list_t()));
    
    insert into person_tab
    values (salesperson_t('s004', 'Schofield', 'Paul', '07-dec-1969', appointment_list_t()));
    
    insert into person_tab
    values (salesperson_t('s005', 'Johnson', 'Richard', '04-jul-1992', appointment_list_t()));
    
    insert into person_tab
    values (salesperson_t('s006', 'Stevens', 'Rupert', '22-may-1989', appointment_list_t()));
    
    
    
    insert into person_tab
    values (applicant_t('ap007', 'Hadfield', 'Linda', '22-nov-1981', '3 Duckdoo Avenue', 'Rosemont', 'Neath Port Talbot',
    telephone_t('01639877103', '07756338175'), '110000', 'Mumbles', appointment_list_t()));
    
    insert into person_tab
    values (applicant_t('ap008', 'Walsh', 'Riley', '18-sep-1974', '12 George Street', 'Taibach', 'Neath Port Talbot',
    '01639890337', '075982228741', '125000', 'Ten Acre Wood', appointment_list_t()));
    
    insert into person_tab
    values (applicant_t('ap009', 'Kennedy', 'Shaun', '11-dec-1972', '101 Granada Close', 'Waun Wen', 'Swansea',
    '01792558447', '07894558123', '150000', 'Central Swansea', appointment_list_t()));
    
    insert into person_tab
    values (applicant_t('ap010', 'Redgrave', 'Steven', '30-jun-1988', '47 Victoria Gardens', 'City Apartments', 'Neath',
    '01639770183', '07774273391', '95000', 'Neath', appointment_list_t()));
    
    insert into person_tab
    values (applicant_t('ap011', 'Hopkins', 'John', '07-feb-1979', '130 Flanders Court', 'Richfield', 'Bridgend',
    '01656889227', '05589337123', '137500', 'Brechfa', appointment_list_t()));
    
    insert into person_tab
    values (applicant_t('ap012', 'Glover', 'Germaine', '14-aug-1983', '32 Regent Crescent', 'Cranforth', 'Cardiff', 
    '01210887336', '07975625195', '170000', 'Cardiff West', appointment_list_t()));
    
    

    
    

    The one I am running made the telephone_t in all households.

    Happy that you have your code working but that was not my point

    It comes to you providing us with the correct instructions to actually run the test case and help you efficiently.

    Regarding your last question, use the function of REGAL to caster level being superior in one of its subtype.

    for example

    SQL> select person
      2       , treat(object_value as applicant_t).aSurname as surname
      3       , treat(object_value as applicant_t).aForename as forename
      4  from person_tab
      5  where object_value is of (applicant_t) ;
    
    PERSON SURNAME              FORENAME
    ------ -------------------- --------------------
    ap007  Hadfield             Linda
    ap008  Walsh                Riley
    ap009  Kennedy              Shaun
    ap010  Redgrave             Steven
    ap011  Hopkins              John
    ap012  Glover               Germaine
    
    6 rows selected.
    
  • a simple select statement once again

    What is the meaning of the one below select statement, pay attention to (sysdate + 1.1)

    Select (sysdate + 1.1) of the double

    Hello

    a_cute_person wrote:

    Lo, seriously, dude you do not make to_char thing, when I select sysdate, sysdate + 1.1 double I see clearly there is time change, I wanted to know what the weather has changed when I do sysdate + 1.1, and why there is no change in time sysdate + 1. hope you have the hand on what I ask

    Understand this:

    When you add 1 to SYSDATE, a full day is added. So, if the current time i.e. SYSDATE is January 22, 2015 16:55 ', by adding 1, it will be named January 23, 2015 16:55 '. Simple.

    But, 1.1 means one-tenth day and fractional hour comes in picture.

    Yes, day 1.1

    = 1 + 1/10 of the next whole day

    = 24 * 60 * 60 seconds + (1/10) * 24 * 60 * 60 seconds

    and here the time portion changes.

    HTH.

    -Nordine

  • using the function - how to use the values of the input variables on the table select statement names

    Hello community, I have a problem when creating a function. The purpose of this function is to check the table of weather gave yesterday or not. We must check this on different tables on different sachems. We are creating a function with input variables.

    CREATE OR REPLACE FUNCTION IN_SCHEMA.IS_YDAYDATA_TO_TABLE

    (

    in_schema IN VARCHAR2,

    in_tablename IN VARCHAR2,

    in_datefield IN VARCHAR2,

    )

    RETURNS INTEGER

    AS

    -Declaring variables

    v_is_true INTEGER.

    BEGIN

    SELECT

    CASE

    WHEN MAX (in_datefield) = TRUNC(SYSDATE-1)

    THEN 1

    ON THE OTHER

    0

    END

    IN

    v_is_true

    Of

    in_schema.in_tablename

    ;

    RETURN v_is_true;

    END;

    /

    When creating, I got error: [error] ORA-00942 (44:19): PL/SQL: ORA-00942: table or view does not exist

    How to use the values of the input variables on the table select statement names?

    Hello

    Here's a way you can use dynamic SQL statements for this task:

    CREATE OR REPLACE FUNCTION IS_YDAYDATA_TO_TABLE

    (

    in_schema IN VARCHAR2,

    in_tablename IN VARCHAR2,

    in_datefield IN VARCHAR2,

    in_first_date DATE DEFAULT SYSDATE - 1,.

    in_last_date DATE by DEFAULT NULL

    )

    RETURNS INTEGER

    AS

    -IS_YDAYDATA_TO_TABLE returns 1 if in_schema.in_tablename.in_datefield

    -contains all the dates in the in_first_date of the range through included in_last_date

    - and it returns 0 if there is no such lines.

    -If in_last_date is omitted, the search only the data on in_first_date.

    -If in_first_date is omitted, it defaults to yesterday.

    -Time parts of the in_first_date and in_last_date are ignored.

    -Declaring variables

    sql_txt VARCHAR2 (1000);

    v_is_true INTEGER.

    BEGIN

    sql_txt: = 'SELECT COUNT (*).

    || 'FROM ' | in_schema | '.' || in_tablename

    || 'WHERE ' | in_datefield | ' > =: d1'

    || «AND» | in_datefield | '< >

    || 'AND ROWNUM = 1';

    dbms_output.put_line (sql_txt |) '= sql_txt in IS_YDAYDATA_TO_TABLE");  -For debugging

    Sql_txt EXECUTE IMMEDIATE

    IN v_is_true

    With the HELP of TRUNC (in_first_date) - d1

    TRUNC (NVL (in_last_date

    in_first_date

    )

    ) + 1                -- d2

    ;

    RETURN v_is_true;

    END is_ydaydata_to_table;

    /

    DISPLAY ERRORS

    If you must use dynamic SQL statements, put all the SQL statement in a single string variable, such as sql_txt in the example above.  In this way, you can easily see exactly what will be executed.  Comment out the call to dbms_output under test is completed.

    Try to write functions that will address not only the question that you have now, but similar questions that you may have in the future.  For example, now that interest you only to the verification of the data of yesterday, but later, you might want to check another day or range of days.  The above function combines the convenience of a function simple (looks like yesterday data if you don't tell him otherwise) with the power of a more complex function (you can use the same function to check any day or range of days).

Maybe you are looking for

  • my serial number is replaced!

    We're sorry, but this is a serial number for a product that has been replaced. Please check your information and re-enter your serial number. If your information is correct, you may need to

  • 15 - r254nu: hp 15-r254nu no driver for the wireless card

    Hello I have installed all the other drivers for my r254nu 15, but neither driver wireless Web site work. Please can you help me with a valid link to a driver for this laptop's wireless work Best regards Ilev

  • What is the cost of Windows 7 upgradation

    I want to improve the business professional vista upgrade to windows 7 or windows 7 Professional, what will be the cost. and how can update the same thing...?

  • Check firewall setting

    Over the years of using SonicWall I made all configurations of myself.  Does anyone know of a familiar service with SonicWall who can verify my settings? Besides that Dell offers this service?

  • Image of the Webcam on the side

    I have a new T420 with integrated webcam. My problem is that my webcam image is always on the side. For example, this happens when I press Fn + F6 to bring up Lenovo's Communications Utility, which displays the image of the webcam and allows me to co