Long Running SQL Queries

We have a customer that runs our Crystal Reports and they have complained that some of the reports cause long running sql queries and they have to kill these queries manually from SQL Management tools. We have changed the code so that we now dispose the report source and viewer objects as we call .dispose() function on them;
reportSource.dispose();
viewer.dispose();
At first this seemed work but customer later complained that the issue still occurs. Can anyone help with why some of these CR queries are still running way after report is generated (with correct set of data), and based on the customer some of them running for more than 2 hours? What else can we do to make sure that all CR related queries cease to exist once report is generated? Appreciate all the help.

1. Run the report from with Crystal designer. You should see the query being sent to DB server. After the report is viewed and you close it in designer, do you see the DB connection being dropped? If not, this may not be a SDK\ API related issue.
2. Try using latest set of CRJ Jars [here|http://downloads.businessobjects.com/akdlm/crystalreportsforeclipse/2_0/crjava-runtime_12.2.213.zip] in your application. Also update the crystalreportviewers folder with the new viewer found at this link.
3. Make sure that you are calling reportClientDocument.close() at the end when user is done viewing the report.
4. When you say logn running queries are seen in DB, are you referring to a DB connection left open? or is it actually running any query and returning results?

Similar Messages

  • Long running sql

    Hi All,
    I have a long running sql which I am tuning for oltp environment.
    Here is the sql
    explain plan for
    SELECT a.* ,rownum as rnm
    FROM ( SELECT /*+ FIRST_ROWS(100) STAR_TRANSFORMATION PARALLEL(PLS,2) */
    /* End of Hint in Query Builder */
    PLD.PRVDR_LCTN_IID AS "ProviderLocationIid", PLD.PRVDR_LCTN_DTL_SID AS "ProviderLocationDetailSid",
    PLD.ENRLMNT_TYPE_CID AS "EnrollMentTypeCid", PLD.PRVDR_TYPE_CODE AS "ProviderTypeCode",
    PLD.MAINECARE_ID AS "Provider Id", PLD.PRVDR_NAME AS "Provider Name",
    PLD.PRVDR_TYPE_CODE || '-' || PLD.PRVDR_TYPE_NAME AS "Provider Type",
    TO_CHAR(PLS.FROM_DATE,'MM/dd/yyyy') AS "Start Date",
    TO_CHAR(PLS.TO_DATE,'MM/dd/yyyy') AS "End Date", PLD.COUNTY_NAME AS "County",
    PLD.CITY_TOWN_NAME AS "Town", PLD.ENRLMNT_TYPE_NAME AS "Enrollment Type",
    PLS.STATUS_CID AS "StatusCid", STSBS.STATUS_NAME AS "Business Status",
    PLD.LCTN_PHONE_NMBR AS "Phone Number", PLD.PRVDR_TYPE_NAME AS "PrvdrTypeName",
    SP.SPCLTY_CODE||'-'||SP.SPCLTY_NAME ||'/'|| SP1.SPCLTY_CODE||'-'||
    SP1.SPCLTY_NAME AS "Specialty/Subspecialty",
    UPPER(SP1.SPCLTY_CODE) AS "SubSpclty", UPPER(SP.SPCLTY_CODE) AS "Spclty"
    FROM /*Query Builder Clause*/
    STATUS STS,
    STATUS STSBS,
    SPECIALTY_SUBSPECIALTY SSP,
    (SELECT PRVDR_LCTN_STATUS_SID, PRVDR_LCTN_IID, PRVDR_LCTN_DTL_SID, FROM_DATE, TO_DATE,
    STATUS_TYPE_CID, STATUS_CID, OPRTNL_FLAG,
    FN_GETANCHORDT(FROM_DATE,TO_DATE) AS ANCHOR_DATE
    FROM PRVDR_LCTN_STATUS
    WHERE STATUS_TYPE_CID = 1
    AND OPRTNL_FLAG = 'A'
    ) PLS,
    PRVDR_LCTN_X_SPCLTY_SUBSPCLTY PXSP,
    PRVDR_LCTN_STATUS PLSBS,
    PROVIDER_LOCATION_DETAIL PLD,
    SPECIALTY SP1,
    SPECIALTY SP
    WHERE
    STS.STATUS_TYPE_CID = 1
    AND STS.STATUS_CID = 2
    AND STSBS.STATUS_TYPE_CID = 15
    AND PLSBS.OPRTNL_FLAG = 'A'
    --          UPPER(UPPER(SP1.SPCLTY_CODE)) LIKE UPPER('1%')
              AND SP1.SPCLTY_CODE LIKE '1%'
    -- AND UPPER(UPPER(SP.SPCLTY_CODE)) LIKE UPPER('1%')
    AND SP.SPCLTY_CODE LIKE '1%'
    AND PLS.OPRTNL_FLAG = 'A'
    AND SP1.OPRTNL_FLAG = 'A'
    AND PXSP.OPRTNL_FLAG = 'A'
    AND PXSP.STATUS_CID = 2
    AND SSP.OPRTNL_FLAG = 'A'
    AND SP.OPRTNL_FLAG = 'A'
    AND PLS.ANCHOR_DATE >= PLSBS.FROM_DATE
    AND PLS.ANCHOR_DATE <= PLSBS.TO_DATE
    AND PLS.STATUS_TYPE_CID = STS.STATUS_TYPE_CID
    AND PLS.STATUS_CID = STS.STATUS_CID
    AND PLD.PRVDR_LCTN_DTL_SID = PLS.PRVDR_LCTN_DTL_SID
    AND PLSBS.PRVDR_LCTN_IID = PLS.PRVDR_LCTN_IID
    AND PLSBS.STATUS_TYPE_CID = STSBS.STATUS_TYPE_CID
    AND PLSBS.STATUS_CID = STSBS.STATUS_CID
    AND PLS.ANCHOR_DATE >= SP1.FROM_DATE
    AND PLS.ANCHOR_DATE <= SP1.TO_DATE
    AND PXSP.PRVDR_LCTN_IID = PLS.PRVDR_LCTN_IID
    AND PXSP.SPCLTY_SUBSPCLTY_SID = SSP.SPCLTY_SUBSPCLTY_SID
    AND PLS.ANCHOR_DATE >= PXSP.FROM_DATE
    AND PLS.ANCHOR_DATE <= PXSP.TO_DATE
    AND SSP.SPCLTY_CODE = SP.SPCLTY_CODE
    -- AND SSP.SUBSPCLTY_CODE = SP1.SPCLTY_CODE
    AND SSP.SUBSPCLTY_CODE = SP1.SPCLTY_CODE
    AND PLS.ANCHOR_DATE >= SSP.FROM_DATE
    AND PLS.ANCHOR_DATE <= SSP.TO_DATE
    AND PLS.ANCHOR_DATE >= SP.FROM_DATE
    AND PLS.ANCHOR_DATE <= SP.TO_DATE
    ORDER BY /*Query Builder Clause*/
    "Provider Id" DESC
    ) A
    WHERE rownum < 101
    Here is the Emplain plan
    SQL> @c:\mohammed\tune\UTLXPLS
    Plan Table
    | Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
    | SELECT STATEMENT | | | | | | |
    | COUNT STOPKEY | | | | | | |
    | VIEW | | | | | | |
    | SORT ORDER BY STOPKEY | | 1 | 358 | 120 | | |
    | SORT ORDER BY STOPKEY | | | | | | |
    | NESTED LOOPS | | 1 | 358 | 117 | | |
    | NESTED LOOPS | | 1 | 313 | 116 | | |
    | NESTED LOOPS | | 1 | 268 | 115 | | |
    | NESTED LOOPS | | 1 | 240 | 114 | | |
    Plan Table
    | NESTED LOOPS | | 1 | 209 | 112 | | |
    | NESTED LOOPS | | 1 | 95 | 111 | | |
    | NESTED LOOPS | | 1 | 74 | 110 | | |
    | NESTED LOOPS | | 7 | 294 | 103 | | |
    | INDEX UNIQUE SCAN |SYS_C00489936 | 1 | 7 | | | |
    | TABLE ACCESS FULL |PRVDR_LCTN_STATUS | 1K| 53K| 102 | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_STATUS | 57K| 1M| 2 | | |
    | INDEX RANGE SCAN |TUNE_PNBS2_1 | 57K| | 1 | | |
    | TABLE ACCESS BY INDEX ROWID |STATUS | 5 | 105 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489936 | 5 | | | | |
    | TABLE ACCESS BY INDEX ROWID |PROVIDER_LOCATION_D | 40K| 4M| 1 | | |
    Plan Table
    | INDEX UNIQUE SCAN |XPKPROVIDER_LOCATIO | 40K| | | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_X_SPCLTY | 1M| 39M| 3 | | |
    | INDEX RANGE SCAN |TUNE_SARWAR_0503200 | 1M| | 2 | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY_SUBSPECIA | 549 | 15K| 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489888 | 549 | | | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY | 11 | 495 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489875 | 11 | | | | |
    | TABLE ACCESS BY INDEX ROWID |SPECIALTY | 11 | 495 | 1 | | |
    | INDEX UNIQUE SCAN |SYS_C00489875 | 11 | | | | |
    32 rows selected.
    I have tried with several hints and several driving tables and tires. Any help in this regard will be highly appreciated.
    Thanks a lot,
    Mohammed Sarwar
    ocp dba
    Email: [email protected]
    [email protected]
    Phone : 301-944-2029 w
    913-484-9204 cell

    This should be better. Any help on tuning the above sql statement using the following explain plan will be highly appreciated.
    Plan Table
    | Operation ------------------| Name -------------| Rows | Bytes| Cost | Pstart| Pstop |
    | SELECT STATEMENT -----------| ------------------| -----| -------|------| | |
    | COUNT STOPKEY --------------|-------------------|------|--------|------| | |
    | VIEW -----------------------|-------------------|----- | -------| -----| | |
    | SORT ORDER BY STOPKEY ------|------------------ |--- 1 | ---358 | 120 -| | |
    | SORT ORDER BY STOPKEY ------| ------------------|----- |------- | -----| | |
    | NESTED LOOPS ---------------|-------------------|--- 1 |--358 -|- 117 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 1 | -313 -| -116 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 1 | 268-- | 115 -| | |
    | NESTED LOOPS--------------- |-------------------| --1- | -240 -| -114 | | |
    Plan Table
    | NESTED LOOPS--------------- |------------------ | ---1 |- 209 -|- 112 | | |
    | NESTED LOOPS--------------- | ------------------|--- 1 |-- 95- | -111 | | |
    | NESTED LOOPS ---------------|----- -------------|--- 1 |-- 74 -| -110 | | |
    | NESTED LOOPS ---------------|----------------- -|--- 7 | -294- |- 103| | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489936------| ---1 |--- 7--|-----| | |
    | TABLE ACCESS FULL ----------|PRVDR_LCTN_STATUS -| --1K | 53K-- | 102 | | |
    | TABLE ACCESS BY INDEX ROWID |PRVDR_LCTN_STATUS- | 57K -|---- 1M|-- 2 | | |
    | INDEX RANGE SCAN -----------|TUNE_PNBS2_1 ------| 57K- |------ |-- 1 | | |
    | TABLE ACCESS BY INDEX ROWID |STATUS------------ | 5 |105----|-- 1 | | |
    | INDEX UNIQUE SCAN---------- |SYS_C00489936 -----| 5--- | ------|-----| | |
    | TABLE ACCESS BY INDEX ROWID-|PROVIDER_LOCATION_D| 40K | 4M----|-- 1 | | |
    Plan Table
    | INDEX UNIQUE SCAN ----------|XPKPROVIDER_LOCATIO| 40K |----- |----- | | |
    | TABLE ACCESS BY INDEX ROWID-|PRVDR_LCTN_X_SPCLTY| 1M -|---39M|--- 3 | | |
    | INDEX RANGE SCAN -----------|TUNE_SARWAR_0503200| 1M -| -----|--- 2 | | |
    |TABLE ACCESS BY INDEX ROWID- |SPECIALTY_SUBSPECIA| 549 |---15K| ---1 | | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489888 -----| 549 |----- | -----| | |
    |TABLE ACCESS BY INDEX ROWID- |SPECIALTY ---------| 11- |---495|--- 1 | | |
    | INDEX UNIQUE SCAN ----------|SYS_C00489875----- | 11 -|----- |----- | | |
    |TABLE ACCESS BY INDEX ROWID -|SPECIALTY ---------| 11- |---495|----1 | | |
    | INDEX UNIQUE SCAN-----------|SYS_C00489875----- | 11 -|----- |----- | | |
    --------------------------------------------------------------------------------

  • Long Running SQL and ORDS Spawns Multiple Database Sessions

    Hi all.
    We have a strange situation when accessing a long running SQL Report (a single APEX Page).
    The SQL takes about 15 mins to run but when I monitor what database sessions are spawned by the APEX Listener, I see multiple sessions all executing the same SQL. It appears that after 6 minutes, the APEX Listener spawns a new database session to execute the same SQL.
    Has anyone seen this before and if so, is there a key setting I am missing as I don't want this to happen. I am new to the APEX Listener and WebLogic so apologies if this is the way it's meant to work but it seems odd that after a certain amount of time (6 minutes in my case) a new database session is spawned to do the same work.
    We are running:
    WebLogic: 10.3.0.6
    APEX_LISTENER_VERSION 2.0.0.354.17.06
    Datadate: 11.2.0.3.0 Production
    APEX: 4.2.1.00.08
    Cheers for any help.
    Duncs

    Hi Duncan,
    With all respect, you should please rethink your interface.  I would never consider writing a Web application with a request that knowingly takes 15 minutes to return the results.  You can consider doing this asynchronously via DBMS_SCHEDULER and then alerting the user (via email, perhaps) that their results are ready.  Or if you can precompute this in advance, consider using materialized views so that the user's response time is sub-second.
    In an era where the patience of the average end-user is measured in single-digit seconds, it is impractical to ever expect an end-user to wait 15 minutes for their resultant Web page.
    Joel

  • Is there a way to get long running SQL Agent jobs information using powershell?

    Hi All,
    Is there a way to get long running SQL Agent jobs information using powershell for multiple SQL servers in the environment?
    Thanks in Advance.
    --Hunt

    I'm running SQL's to fetch the required details and store it in centralized table. 
    foreach ($svr in get-content "f:\PowerSQL\Input\LongRunningJobsPowerSQLServers.txt"){
    $dt = new-object "System.Data.DataTable"
    $cn = new-object System.Data.SqlClient.SqlConnection "server=$svr;database=master;Integrated Security=sspi"
    $cn.Open()
    $sql = $cn.CreateCommand()
    $sql.CommandText = "SELECT
    @@SERVERNAME servername,
    j.job_id AS 'JobId',
    name AS 'JobName',
    max(start_execution_date) AS 'StartTime',
    max(stop_execution_date)AS 'StopTime',
    max(avgruntimeonsucceed),
    max(DATEDIFF(s,start_execution_date,GETDATE())) AS 'CurrentRunTime',
    max(CASE WHEN stop_execution_date IS NULL THEN
    DATEDIFF(ss,start_execution_date,stop_execution_date) ELSE 0 END) 'ActualRunTime',
    max(CASE
    WHEN stop_execution_date IS NULL THEN 'JobRunning'
    WHEN DATEDIFF(ss,start_execution_date,stop_execution_date)
    > (AvgRunTimeOnSucceed + AvgRunTimeOnSucceed * .05) THEN 'LongRunning-History'
    ELSE 'NormalRunning-History'
    END) 'JobRun',
    max(CASE
    WHEN stop_execution_date IS NULL THEN
    CASE WHEN DATEDIFF(ss,start_execution_date,GETDATE())
    > (AvgRunTimeOnSucceed + AvgRunTimeOnSucceed * .05) THEN 'LongRunning-NOW'
    ELSE 'NormalRunning-NOW'
    END
    ELSE 'JobAlreadyDone'
    END)AS 'JobRunning'
    FROM msdb.dbo.sysjobactivity ja
    INNER JOIN msdb.dbo.sysjobs j ON ja.job_id = j.job_id
    INNER JOIN (
    SELECT job_id,
    AVG
    ((run_duration/10000 * 3600) + ((run_duration%10000)/100*60) + (run_duration%10000)%100)
    +
    STDEV
    ((run_duration/10000 * 3600) + ((run_duration%10000)/100*60) + (run_duration%10000)%100) AS 'AvgRuntimeOnSucceed'
    FROM msdb.dbo.sysjobhistory
    WHERE step_id = 0 AND run_status = 1
    GROUP BY job_id) art
    ON j.job_id = art.job_id
    WHERE
    (stop_execution_date IS NULL and start_execution_date is NOT NULL) OR
    (DATEDIFF(ss,start_execution_date,stop_execution_date) > 60 and DATEDIFF(MINUTE,start_execution_date,GETDATE())>60
    AND
    CAST(LEFT(start_execution_date,11) AS DATETIME) = CAST(LEFT(GETDATE(),11) AS DATETIME) )
    --ORDER BY start_execution_date DESC
    group by j.job_id,name
    $rdr = $sql.ExecuteReader()
    $dt.Load($rdr)
    $cn.Close()
    $dt|out-Datatable
    Write-DataTable -ServerInstance 'test124' -Database "PowerSQL" -TableName "TLOG_JobLongRunning" -Data $dt}
    You can refer the below link to refer out-datatable and write-dataTable function.
    http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx
    Once we've the table details, I'm sending one consolidated email to automatically.
    --Prashanth

  • Information on how to run SQL queries on the CUCM itself please

    Good Day All,
    I need to run an sql query on the CUCM to list all of my directory numbers, their partition, and their external mask values.
    I came across this excerpt below earlier so I have a bit of an idea how to do it but iw would be great to see some other examples of sql queries.
    Any assistance is most appreciated.
    Also, is there a document somewhere to tell me how to run these queries?
    Thanks in advance
    Regards
    Amanda
    Currently Being Moderated
    05/04/2011 5:18 AM (in response to Joshua Royle)
    Re: Is there a way of pulling a report off CM showing all phones that have diverts on?
    Try if running this SQL query from the CLI helps you, it should list all DN's that have CFA enabled to VM or a DN:
    run sql select dnorpattern,cfadestination,cfavoicemailenabled from CallForwardDynamic c, numplan n where c.fknumplan = n.pkid and (cfadestination != '' or cfavoicemailenabled ='t')

    Hi Amanda
    Basically it's standard SQL, so it wouldn't hurt to google 'informix select statements' and do a little reading to get the basics. There are millions of permutations of queries so it's a matter of understanding the syntax, and then applying that to the database in question. The only difference when running commands from the CLI are that:
    - You prefix the standard informix SQL statement with 'run sql'
    - You don't get any help from CUCM with the syntax, so you might be well advised to use something that understands SQL a little and colorises it as you type, and then paste the resulting commands into the CUCM SSH window. I use a text editor named JEdit, if you create a text file and save it as a file ending in .sql it will highlight your syntax.
    - Other programs are available that do reasonable syntax highlighting (e.q. SquirrelSQL) that are designed for querying the DB directly, but you can't actually query directly against the DB for security reasons. You'd still have to copy/paste the commands.
    Now... to understand the DB you'll need a reference describing all the tables etc. This is here:
    http://www.cisco.com/en/US/products/sw/voicesw/ps556/products_programming_reference_guides_list.html
    Pick your version of CUCM and download the 'Data Definition' document.
    A few notes on the command:
    run sql : is just the CLI command that tells the shell to run the following text as SQL.
    select : the SQL command to retrieve data
    dnorpattern,cfadestination,cfavoicemailenabled : the column names to retrieve
    callforwarddynamic c, numplan n : the names of two tables, and the abbreviations you want to refer to them as
    where c.fknumplan = n.pkid : this tells SQL to return values from the two tables where these fields match up. In the data definition you'll see notes that c.fknumplan (i.e. the fknumplan column in the callforwarddynamic table, as noted by the c. prefix) refers to the PKID column in the numplan field. This is a very standard type of join in the CCM DB.
    and (cfadestination != '' or cfavoicemailenabled ='t') : another clause, basically in this query we want to see only rows where cfadestination isn't blank or cfavoicefmailenabled is set to 't' for true).
    Most tables are linked in one of two ways in this database:
    - a column prefixed 'fk' refers to the pkid field (there is always only one pkid field per table) in the table following the 'fk' prefix. E.g. above fknumplan refers to the numplan table, pkid field. fkdevice would refer to the device table, pkid field.
    - a column prefiex 'tk' refers usually to an enum table which is prefixed with 'type'. This is a table that maps the number value in the 'tk' field to a string. An example would be tkmodel - this represents the phone physical model type (e.g. 7962), and maps to a table called typemodel, and the 'enum' column in that table.
    Regards
    Aaron HarrisonPrincipal Engineer at Logicalis UK
    Please rate helpful posts...

  • Run sql queries in online sqlplus........is that possible??

    Hi,
    I am a php/mysql programmer.In my office only mysql is installed.And as a junior programmer i have no privilege to install oracle in my machine or in our server.But i want to run some small oracle queries in order to gather knowledge in Oracle.I am looking for an online SQLPLUS...
    If something like that exists...please send me the link...

    You only said to run some oracle queries for that you need oracle, there is nothing like online sqlplusWell, there is some kind of "online SQL*Plus": it's not really SQL*Plus, you have limited privileges and disk space but you can create database objects in a Oracle database and run usual SQL statements using apex.oracle.com online service.
    Message was edited by:
    Pierre Forstmann

  • Running SQL queries through Xpress code

    Hi,
    Please give an idea to run the sql select, update queries through Xpress code.
    The code may be there in workflows or rulelibs...
    Any ideas are appreciated
    Thanks,
    Santoshanand

    There is a set of JDBC methods in the class com.waveset.util.JdbcUtil which certainly allows for selects to take place.
    check out the javadocs from the BFE especially the queryList and queryRecords methods.
    I guess the sql method could be used to run any sort of sql statement you like if you want to modify the database.
    From XPress these methods are invoked
    e.g.
    <invoke name='queryList' class='com.waveset.util.JdbcUtil'>
    </invoke>

  • Error while running sql queries..

    Hi there,
    We are suppose to run gather schema stats..
    but while running the procedure we are getting following error..
    gather_schema.sql:
    exec fnd_stats.gather_schema_statistics('CMWCONN');
    exec fnd_stats.gather_schema_statistics('CMW');
    exec fnd_stats.gather_schema_statistics('ALL');
    SQL> @gather_schema.sql;
    BEGIN fnd_stats.gather_schema_statistics('CMWCONN'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'FND_STATS.GATHER_SCHEMA_STATISTICS' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    BEGIN fnd_stats.gather_schema_statistics('CMW'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'FND_STATS.GATHER_SCHEMA_STATISTICS' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    BEGIN fnd_stats.gather_schema_statistics('ALL'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'FND_STATS.GATHER_SCHEMA_STATISTICS' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Could you give me the correct pl/sql procedure to run the query.
    Thanks,.
    Balu.

    Actually the script was working fine last week..we are using the following script
    SQL> exec fnd_stats.gather_schema_statistics('ALL');     
    but it throws me the following error
    BEGIN fnd_stats.gather_schema_statistics('ALL'); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'FND_STATS.GATHER_SCHEMA_STATISTICS' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

  • SQL Inseting a Set Of Data To Run SQL Queries and Produce a Data Table

    Hello,
    I am an absolute newbie to SQL.
    I have purchased the book "Oracle 10g The Complete Reference" by Kevin Loney.
    I have read through the introductory chapters regarding relational databases and am attempting to copy and paste the following data and run an SQL search from the preset data.
    However when I attempt to start my database and enter the data by using copy and paste into the following:
    C:\Windows\system32 - "Cut Copy & Paste" rem **************** onwards
    I receive the following message: drop table Newspaper;
    'drop' is not recognised as an external or internal command, operable programme or batch file.
    Any idea how one would overcome this initial proble?
    Many thanks for any solutions to this problem.
    rem *******************
    rem The NEWSPAPER Table
    rem *******************
    drop table NEWSPAPER;
    create table NEWSPAPER (
    Feature VARCHAR2(15) not null,
    Section CHAR(1),
    Page NUMBER
    insert into NEWSPAPER values ('National News', 'A', 1);
    insert into NEWSPAPER values ('Sports', 'D', 1);
    insert into NEWSPAPER values ('Editorials', 'A', 12);
    insert into NEWSPAPER values ('Business', 'E', 1);
    insert into NEWSPAPER values ('Weather', 'C', 2);
    insert into NEWSPAPER values ('Television', 'B', 7);
    insert into NEWSPAPER values ('Births', 'F', 7);
    insert into NEWSPAPER values ('Classified', 'F', 8);
    insert into NEWSPAPER values ('Modern Life', 'B', 1);
    insert into NEWSPAPER values ('Comics', 'C', 4);
    insert into NEWSPAPER values ('Movies', 'B', 4);
    insert into NEWSPAPER values ('Bridge', 'B', 2);
    insert into NEWSPAPER values ('Obituaries', 'F', 6);
    insert into NEWSPAPER values ('Doctor Is In', 'F', 6);
    rem *******************
    rem The NEWSPAPER Table
    rem *******************
    drop table NEWSPAPER;
    create table NEWSPAPER (
    Feature VARCHAR2(15) not null,
    Section CHAR(1),
    Page NUMBER
    insert into NEWSPAPER values ('National News', 'A', 1);
    insert into NEWSPAPER values ('Sports', 'D', 1);
    insert into NEWSPAPER values ('Editorials', 'A', 12);
    insert into NEWSPAPER values ('Business', 'E', 1);
    insert into NEWSPAPER values ('Weather', 'C', 2);
    insert into NEWSPAPER values ('Television', 'B', 7);
    insert into NEWSPAPER values ('Births', 'F', 7);
    insert into NEWSPAPER values ('Classified', 'F', 8);
    insert into NEWSPAPER values ('Modern Life', 'B', 1);
    insert into NEWSPAPER values ('Comics', 'C', 4);
    insert into NEWSPAPER values ('Movies', 'B', 4);
    insert into NEWSPAPER values ('Bridge', 'B', 2);
    insert into NEWSPAPER values ('Obituaries', 'F', 6);
    insert into NEWSPAPER values ('Doctor Is In', 'F', 6);

    You need to be in SQL*Plus logged in as a user.
    This page which I created for my Oracle students may be of some help:
    http://www.morganslibrary.org/reference/setup.html
    But to logon using "/ as sysdba" you must be in SQL*Plus (sqlplus.exe).

  • Running SQL Queries in PeopleSoft Application Designer

    Hi,
    I'd like to find out which peoplesoft tables contain two fields x and y. I have the sql query to do that, but I don't know where I can run that query from in application designer. Its quite possible that it will be done from "Query" window in Application Designer.
    Can someone tell me the steps to do this? I'm very new to PeopleSoft.
    thanks.
    Askar

    1. Open the QUERY tool from the AppDesigner.
    2. File/New
    3. Expand the record
    4. Click on PSRECFIELD
    5. Drag and drop to the right part of the window
    6. At the left window, drag and drop the fields RECNAME from the left (from the record PSRECFIELD) into the tab Field at the right
    7. At the left window, expend the record hierarchy of PSRECFIELD
    8. Expand PSRECDEN Record Definition
    9. Right click on PSRECFIELD Field definition, then "New join"
    10. Choose Standard join
    11. At the right, click on tab Criteria
    12. Drag and drop the FIELDNAME field from the first PSRECFIELD (A)
    13. Double click on Expression 2
    14. In the new window, enter one of the first column name you want to retrieve
    15. Drag and drop the FIELDNAME field from the second PSRECFIELD (C)
    16. Double click on Expression 2
    17. In the new window, enter one of the second column name you want to retrieve
    18. Double click on Logical column at the right until to have "AND"
    19. Click on tab Result
    20. Click on Run query (or File/Run current query)
    21. Enjoy with your results.
    Note, QUERY tool will query the Peoplesoft tables, on the other hands, the Peoplesoft metamodel. If you have built objects directly against the database without having used AppDesigner, you won't be able to retrieve the data.
    Nicolas.

  • Running sql queries in Javascript

    Have built a form with numerous rows based on Stefan Cameron's methodology (http://forms.stefcameron.com/2006/10/12/displaying-all-records-from-an-odbc-data-connecti on/) and have gotten that part to work.
    Need to use a sql query to get a subset opf the data, but Stefan's and other examples use Formcalc.  I figure I just need to do a delayed query once I get the query set up and loaded.
    Drawing a blank on how and where to load the sql query string.
    Thanks in advance,
    Patrick

    Stefan's code is very useful when you want to display a single record. Typically I woudl enter a value on a field and use that entered value as part of teh record search in my SQL statement (usually with a delayed open of the DB). If you want to get a subset of records and simply navigate through them that code is not neccessary. You can change the settings when you set up the dataconnection to enter a SQL command and enter it in the 1st panel. Then when the connection is made that SQL statement will run each time.

  • UDM for long running sql

    Hi
    I am planning to use enterprise manager grid control to create a UDM for the following sql that would alert me for the sql that is running for more then a hour for all databases any ideas on how to do this
    SELECT
            substr(swn.sql_text,40),
            ||'SQL is Running on Instance ' ||s.inst_id || 'Since '|| ROUND(sl.elapsed_seconds/60) elapsed_mins,      
    FROM   gv$session_longops sl,
    gv$session s ,
    gv$sql swn
    WHERE  s.sid     = sl.sid
    AND    s.inst_id = sl.inst_id
    AND    s.serial# = sl.serial#
    AND    s.inst_id = swn.inst_id
    AND    s.sql_address = swn.address
    AND    s.sql_hash_value = swn.hash_value
    AND    sl.sofar  <> sl.totalwork
    AND    sl.totalwork <> 0
    AND    round((sl.elapsed_seconds)/60,0) > 60
    order by 7Edited by: user9243284 on Jun 7, 2010 3:48 AM

    I think you should specify:
    SQL query output: two columns
    Metric Type: String
    and the following query:
    SELECT 'NA',0
    from dual
    union
    SELECT distinct '( ' ||i.instance_name ||','|| sl.sid ||','|| sl.serial# ||', ) ' || substr(s.sql_text,1,1000) sql, ROUND(sl.elapsed_seconds/60) mins
    FROM gv$session_longops sl,
    gv$sql s,
    gv$instance i
    WHERE sl.sofar = sl.totalwork
    AND sl.totalwork = 0
    AND sl.inst_id = s.inst_id (+)
    AND sl.sql_address = s.address (+)
    AND sl.sql_hash_value = s.hash_value (+)
    AND sl.inst_id = i.inst_id
    use the select from dual, to make sure your query allways returns at least one row.
    BTW, you will find some examples of UDM creation on my blog.
    Regards
    Rob
    http://oemgc.wordpress.com

  • Killing long running SQl automatically

    I want to put a restriction on my database, if a sql query is running for more then 15 min, then killing this automatically. If this is possible kindly let me know.

    Hi,
    yes you can do that, use Resource Manager for that like described below:
    http://www.pythian.com/blog/oracle-limiting-query-runtime-without-killing-the-session/
    Best regards,
    Nikolay

  • Monitoring Long Running SQL

    Hi all,
    Some users run reports for very large period of time (diffrence of start & end dates 2 years) and they end up scanning the whole database and crashing the application services.
    Is there any way to monitor this kind of queries and kill it before the application hangs??
    thanks in advance.

    If you set up PROFILES in your database (you need to set RESOURCE_LIMIT to true for this), you don't need to monitor any query, the session will be killed automatically when a threshold is exceeded.
    Consult the PROFILE concept and the CREATE PROFILE command in the documentation for further details.
    Sybrand Bakker
    Senior Oracle DBA

  • Long running SQL needs tuning

    We've an SQL procedure that hangs after running for hours. We've identified the SQL that's causing the bottleneck. Pl. find screnshot of the explain plan below.
    Pls. suggest me to improve the performance of this query.
    ===============================================
      SELECT COUNT(DISTINCT reat_elg.prd_hld_id) 
          FROM tl_w_prd_hld prdhld , tl_w_prd_hld_role prdhldrl , tl_w_phlc_cnt_stat prdhldco , tl_w_reat_elg reat_elg
         WHERE reat_elg.prd_hld_id = prdhld.prd_hld_id AND
               prdhld.prd_hld_id = prdhldrl.prd_hld_id AND
               prdhld.prd_hld_id = prdhldco.prd_hld_id AND
               reat_elg.prd_hld_id != '-1' AND
               reat_elg.eligible_ind = 'Y' AND
               prdhldrl.eff_end_date IS NULL AND
               prdhldrl.hms_legown_ind = 'Y' AND
               prdhldco.legown_issue_ind = 'N' AND
               prdhld.jntown_type_ind='N' AND
               reat_elg.prd_hld_id IN
                        (SELECT distinct phr2.prd_hld_id
                          FROM tl_w_prd_hld_role phr2, tl_w_phlc_cnt_stat ph_loi
                          WHERE ph_loi.prd_hld_id=ph_loi.prd_hld_id  AND
                                phr2.prd_hld_id = reat_elg.prd_hld_id AND
                                phr2.eff_end_date IS NULL AND
                                phr2.hms_legown_ind = 'Y' AND
                                (ph_loi.create_source,phr2.prd_hld_id) IN 
                                 (SELECT  DISTINCT                              
                                          (CASE
                                           WHEN (ccntbl_ind='Y' OR ce_legown_issue_ind='N' OR sfc_cntbl_ind='' OR sfc_legown_issue_ind='') AND       ce_hms_legown_ind='Y' THEN ce_create_source
                                           WHEN ccntbl_ind='Y' AND ce_legown_issue_ind='N' AND ce_hms_legown_ind='Y' THEN ce_create_source
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND (sfc_cntbl_ind='Y' AND sfc_legown_issue_ind='N'  AND SFC_hms_legown_IND='Y')    THEN  sfc_create_source
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND ((sfc_cntbl_ind='N' AND sfc_legown_issue_ind='Y')  AND SFC_hms_legown_IND='Y')    THEN  sfc_create_source
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND (sfc_cntbl_ind='Y' AND sfc_legown_issue_ind='N'  AND SFC_hms_legown_IND='N')    THEN  ce_create_source
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND ((sfc_cntbl_ind='N' AND sfc_legown_issue_ind='Y')  AND SFC_hms_legown_IND='N')    THEN  ce_create_source
                                           END
                                          (CASE
                                           WHEN (ccntbl_ind='Y' OR ce_legown_issue_ind='N' OR sfc_cntbl_ind='' OR sfc_legown_issue_ind='') AND       ce_hms_legown_ind='Y' THEN CE_prd_hld_ID
                                           WHEN ccntbl_ind='Y' AND ce_legown_issue_ind='N' AND ce_hms_legown_ind='Y' THEN ce_create_source
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND (sfc_cntbl_ind='Y' AND sfc_legown_issue_ind='N'  AND SFC_hms_legown_IND='Y')    THEN  sfc_prd_hld_id
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND ((sfc_cntbl_ind='N' AND sfc_legown_issue_ind='Y')  AND SFC_hms_legown_IND='Y')    THEN  sfc_prd_hld_id
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND (sfc_cntbl_ind='Y' AND sfc_legown_issue_ind='N'  AND SFC_hms_legown_IND='N')    THEN  ce_prd_hld_id
                                           WHEN ((ccntbl_ind='N' OR ce_legown_issue_ind='Y') AND ce_hms_legown_ind='Y' ) AND ((sfc_cntbl_ind='N' AND sfc_legown_issue_ind='Y')  AND SFC_hms_legown_IND='N')    THEN  ce_prd_hld_id
                                           END
                                          FROM
                                            SELECT
                                            cnteng.prd_hld_id ce_prd_hld_id,
                                            cnteng.cntbl_ind ccntbl_ind,
                                            cnteng.legown_issue_ind ce_legown_issue_ind,
                                            cnteng.hms_legown_ind ce_hms_legown_ind,
                                            cnteng.create_source ce_create_source,
                                            slsfrc.prd_hld_id sfc_prd_hld_id,
                                            slsfrc.cntbl_ind sfc_cntbl_ind,
                                            slsfrc.legown_issue_ind sfc_legown_issue_ind,     
                                            slsfrc.hms_legown_ind     sfc_hms_legown_ind,
                                            slsfrc.create_source sfc_create_source
                                            FROM
                                            (SELECT ph_loi.prd_hld_id,ph_loi.cntbl_ind,ph_loi.legown_issue_ind,prdhldrl.hms_legown_ind,ph_loi.create_source FROM tl_w_phlc_cnt_stat ph_loi,tl_w_prd_hld_role prdhldrl
                                            WHERE
                                            ph_loi.prd_hld_id=prdhldrl.prd_hld_id
                                            AND ph_loi.create_source!='slsfrc'
                                            )cnteng,                            
                                            SELECT ph_loi.prd_hld_id,ph_loi.cntbl_ind,ph_loi.legown_issue_ind,prdhldrl.hms_legown_ind,ph_loi.create_source FROM tl_w_phlc_cnt_stat ph_loi,tl_w_prd_hld_role prdhldrl
                                            WHERE
                                            ph_loi.prd_hld_id=prdhldrl.prd_hld_id
                                            AND ph_loi.CREATE_SOURCE='slsfrc'
                                            )slsfrc where cnteng.prd_hld_id=slsfrc.prd_hld_id
                                             GROUP BY phr2.prd_hld_id
                                             HAVING COUNT(*) > 1
                     ================================================
    Explain plan
    SQL> select * from table(dbms_xplan.display);
    Message was edited by:
    user604968

    Dear user604968
    (Why not give your profile a name?)
    Your explain plan has been removed - which doesn't help - but here's a couple of things
    1) the use of DISTINCT in each of the main query, subquery and sub-sub-query fills me with suspicion. The complexity of the query makes me think that the data model is either misunderstood or (more likely) poorly designed
    2) the outermost subquery is almost certainly incorrectly correlated with the outer query:
        WHERE ph_loi.prd_hld_id=ph_loi.prd_hld_id why compare a column to itself? Presumably this should be something like:
        WHERE ph_loi.prd_hld_id=phr2.prd_hld_id Good luck with puzzling it out...
    Regards Nigel

Maybe you are looking for

  • Defining logicals on VMS

    Actually we put a mechanism in just to do this very thing. On unix when you set an env variable it is only seen by the children and we wanted to get this exact behavior on vms. So we created a new logical name table Forte_prctable. This is a process

  • Only allow x rows to be selected in a jtable

    hi all, i want to only allow a user to select x rows. where x is set in the code. for example if i only allow 2 rows to be selected....and the rows are: a b c d e then if the user selects a then b then c the selection is first ab, then bc (ie a is de

  • Hi SAP FI/CO GURUS ... please tell me what are the activities

    Hai SAP FI/CO gurus Good day to you all. i know the activities of a fi/co consultant in implementation project. i would like to know the responsibilities or activities of a sap fi/co consultant in a development support project. As per my knowledge  t

  • Premiere Elements 8 update 8.0.1 won't install

    I can't get Premiere Elements 8 update 8.0.1 to install.  It claims I need to close "elements 8.exe.". first, but as far as I can see, it isn't open. ALSO I can't get the Adobe techs to answer the phones even though I must have let it ring 50 times o

  • ISync non syncronize after update mac os x 10.6

    Hi. I don't know if the problem is in the phone (Nokia N85) or in the mac os x 10.6 but i can't sync my phone with iSync after update to last one mac os x update. I try to remove and reasociate the phone with the iSync and non error apear in iSinc. N