Query in PL/SQL Help

Hi All!
I want to write following type of query in PL/SQL
How can I write one which will work.
SELECT count(1) INTO v_count2 from TRJ_TRAN_REJ_T a and PEU_PUR_ENRL_UNT_T b
where a.TRJ_CVRG_PER_DATE IN (b.PEU_EFF_DATE AND b.PEU_END_DATE) AND
a.purik = b.purik AND a.peuik = b.peuik
Above query is not working correctly. Any changes?? DATE stored in database is like 01/01/2001
v_count2 is NUMBER variable declared in PL?SQL.
SA

I'd also watch out for the TIME part of the date matching, best to do a TRUNC on them, but make sure also [purik] and [peuik] are indexed. This is the format I use for a select. Some parts were removed but you get the idea.
--[START]
--[SELECT]
SELECT
--/*+ choose */
/*+ RULE */
--/*+ first_rows */
--/*+ all_rows */
count(1)          --[C1]
--[INTO]
INTO
v_count2          --[V1]
--[FROM]
FROM
trj_tran_rej_t T1,
peu_pur_enrl_unt_t T2
--[WHERE]
WHERE
TRUNC(T1.trj_cvrg_per_date) = TRUNC(T2.peu_eff_date)
OR
TRUNC(T1.trj_cvrg_per_date) = TRUNC(T2.peu_end_date)
AND
T1.purik = T2.purik
AND
T1.peuik = T2.peuik
--[ABORT]
AND 1=1;
--[END]
Tyler Durden

Similar Messages

  • Crosstab query using  PL/SQL [HELP]

    hi all,
    i got this output after execute my query:
    week no | department | item | budget
    1 | 0901 | salary | 25000
    1 | 0901 | stationery | 5000
    1 | 5501 | salary | 45000
    2 | 0901 | salary | 25000
    2 | 5501 | salary | 25000
    2 | 5501 | stationery | 100
    i hope to get the output like below:
    dept/week no 1 2 3
    =========================================
    0901 30,000 25,000 800 (A)
    5501 45,000 25,100 100 (B)
    variance 45,000 70,000 70,800 (C)
    =========================================
    Grand total - 75,000 - 50,100 - (D)
    ======================================
    NOTE:
    the week is from week 1 until week 52, is it advisable to use looping or??.
    It is more than 2 departments and items as well. the user is allowed to passing in more than 1 selection of the items (salary,stationary,hardware and software, etc) to get this report.
    I need to display the output on the screen/spool into file after the execution.
    ==========
    Definition
    ===========
    Grant total (D1) by week =(A1 + B1)
    Variance (C1) for the 1st week of the year will always take the (B1) values as the based values for the next calculation. whereas (C2) = (C1) + (A2) and (C3) =(C2)+(A3) and the same formular apply up to week 52.
    the pivot method not a suitable solution to produce this output.
    anyone can suggest the shorter and more intelligent solution?
    this is very urgent, pls help!! thank

    You can get your basic data by,
    SELECT department, week_no, sum(budget) AS budget
      FROM your_table
    GROUP BY department, week_no;Then you'll just pivot the above data by week. Then you can use an analytic SUM() to get your weekly totals.
    WITH your_table AS (
    SELECT '0901' AS department, 1 AS week_no, 1000 AS budget FROM dual
    UNION ALL
    SELECT '1234' AS department, 1 AS week_no, 500 AS budget FROM dual)
    SELECT v.*,
           SUM(budget) OVER (PARTITION BY week_no) AS week_total
      FROM (
    SELECT department, week_no, sum(budget) AS budget
      FROM your_table
    GROUP BY department, week_no
    ORDER BY department, week_no
           )  v;I have to admit I'm a bit confused about your definition of variance.

  • How do tune sql query? Can somebody help me in this? Atleast prescribe book

    how do tune sql query? Can somebody help me in this? Atleast prescribe a reference book.
    I am not able understand How to analyze tkproof output.

    Check out asktom.oracle.com
    Lot's of threads on interpreting tkprof output - no simple easy solution here.
    You need to understand what is happening and THINK. Then you can be a good engineer.
    As for good books...
    Tom Kyte's books are really, really good.
    http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_3?ie=UTF8&s=books&qid=1266783471&sr=8-3
    http://www.amazon.com/Expert-Oracle-Database-Architecture-Programming/dp/1590595300/ref=sr_1_1?ie=UTF8&s=books&qid=1266783471&sr=8-1
    Good luck!

  • PIVOT sql help

    Hi again
    I need some PIVOT sql help
    In this query:
    SELECT
    SUM([RATES]) as RATES
    ,SUM([CONVERSION])as CONVERSION
    FROM REPORTING
    outputs
    RATES CONVERSION
    23 234
    How would change this query to display a table like:
    Name Amount
    RATES 23
    CONVERSION 234
    Keep up the good work !

    nikos101 wrote:
    > How would change this query to display a table like:
    Do you *HAVE* to change the query... you could just display
    it in the
    desired format if that it the ultimate and only goal.
    <table>
    <tr>
    <td>name</td>
    <td>amount</td>
    </tr>
    <cfoutput query="sumQry">
    <tr><td>Rates</td><td>#rates#</td></tr>
    <tr><td>Conversion</td><td>#conversion#</td></tr>
    </cfoutput>
    </table>

  • Query in PL/SQL code is slower

    I have a very strange issue within my development database, I'm using Oracle 10g.
    I created a query to read some data from a large collection of tables -OFDM tables- I have tested and tuned the performance of the query from (PL/SQL Developer 7 ), it takes only 2 minutes to finish but when I use the same query as a cursor in a database procedure it consume a lot of time around 15 min to get the data.
    Your help is appreciated

    [url http://groups.google.de/group/comp.databases.oracle.server/browse_frm/thread/df893cf9be9b2451/54f9cf0e937d7158?hl=de&tvc=1&q=%22Beautified%22+code+runs+slower#54f9cf0e937d7158]Recently somebody complained about slow performance after code was beatified in PL SQL Developer, after recompilation without flag "Add Debug Information" it run faster...
    (just a guess)
    Best regards
    Maxim

  • Re: How to converting from PL/SQL query to T-SQL query

    How to converting from PL/SQL query to T-SQL query... Its Urgent

    Download the
    SQL Server Migration Assistant for Oracle.  It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
    With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
    But you can try
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Data discrepancy between Webi Report and same Query fired on SQL Server 2k5

    Hi ,
    We are facing an issue in BO XI R2.
    We need to run a Webi report in which negative values for forecasting data for year 2011 and 2012 should be displayed.
    When we are running this report for negative values, we are getting message u2018There is no data corresponding to this queryu2019.
    Then we tried executing the same query on Database. Here at db level we got the correct required result.
    So now we are not able to find the reason for data discrepancy .
    Why the same query generated by Webi is providing correct data when fired on reporting database and not when running the Webi Report.
    Checklist we have gone through for this troubleshooting is-
    -Connections of Universe (Is universe pointing to same database or not)
    -Any filter condition present at universe level and at report level.
    Could anyone please help on this.
    Regards,
    Vaibhav

    Vaibhav,
    Have you tried the following when you are in WebI: go under the Edit Query panel, click on the "SQL" icon, and review the query that is getting generated?  At this point you can also click on the "copy" option, then paste this query into your SQL application analyzer and run to see what results are generated.  To me, it sounds like the portion trying to generate the "minus" sign might be getting tripped up causing the disconnect....
    Thanks,
    John

  • Crosstab query using pure SQL only

    Hi all,
    Found a lot of threads on crosstab, but none seems to address what I need. I need to perform crosstab query using pure SQL only & the number of columns are dynamic. From a query, I obtained the below table:
    Name Date Amount
    Alex 2005-06-10 1000
    Alex 2005-06-20 1000
    Alex 2005-07-10 1000
    Alex 2005-07-20 1000
    Alex 2005-08-10 1000
    Alex 2005-08-20 1000
    John 2005-06-10 2000
    John 2005-06-20 2000
    John 2005-07-10 2000
    John 2005-07-20 2000
    John 2005-08-10 2000
    John 2005-08-20 2000
    And I need to transform it into:
    Name 06-2005 07-2005 08-2005
    Alex 2000 2000 2000
    John 4000 4000 4000
    Reason for the columns being dynamic is because they'll be a limit on the date ranges to select the data from. I'd have a lower & upper bound date say June-2005 to August-2005, which explains how I got the data from the above table.
    Please advise.
    Thanks!

    Hi,
    I couldn't resist the intellectual challenge of a pure SQL solution for a pivot table with a dynamic number of columns. As Laurent pointed out, a SQL query can only have a fixed number of columns. You can fake a dynamic number of columns, though, by selecting a single column containing data at fixed positions.
    <br>
    <br>
    If it were me, I'd use a PL/SQL solution, but if you must have a pure SQL solution, here is an admittedly gruesome one. It shows the sum of all EMP salaries per department over a date range defined by start and end date parameters (which I've hardcoded for simplicity). Perhaps some of the techniques demonstrated may help you in your situation.
    <br>
    <br>
    set echo off
    set heading on
    set linesize 100
    <br>
    select version from v$instance ;
    <br>
    set heading off
    <br>
    column sort_order noprint
    column sal_sums format a80
    <br>
    select -- header row
      1        as sort_order,
      'DEPTNO' as DEPTNO ,
      sys_connect_by_path
        ( rpad
            ( to_char(month_column),
              10
          ' | '
        ) as sal_sums
    from
        select
          add_months( first_month, level - 1 ) as month_column
        from
          ( select
              date '1981-01-01' as first_month,
              date '1981-03-01' as last_month,
              months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
            from dual
        connect by level < total_months + 1
      ) months
    where
      connect_by_isleaf = 1
    connect by
      month_column = add_months( prior month_column, 1 )
    start with
      month_column = date '1981-01-01'
    union all
    select -- data rows
      2 as sort_order,
      deptno,
      sys_connect_by_path( sum_sal, ' | ' ) sal_sums
    from
      select
        dept_months.deptno,
        dept_months.month_column,
        rpad( to_char( nvl( sum( emp.sal ), 0 ) ), 10 ) sum_sal
      from
          select
            dept.deptno,
            reporting_months.month_column
          from
            dept,
            ( select
                add_months( first_month, level - 1 ) as month_column
              from
                ( select
                    date '1981-01-01' as first_month,
                    date '1981-03-01' as last_month,
                    months_between( date '1981-03-01', date '1981-01-01' ) + 1 total_months
                  from
                    dual
              connect by level < total_months + 1
            ) reporting_months
        ) dept_months,
        emp
      where
        dept_months.deptno = emp.deptno (+) and
        dept_months.month_column = trunc( emp.hiredate (+), 'MONTH' )
      group by
        dept_months.deptno,
        dept_months.month_column
    ) dept_months_sal
    where
      month_column = date '1981-03-01'
    connect by
      deptno = prior deptno and
      month_column = add_months( prior month_column, 1 )
    start with
      month_column = date '1981-01-01'
    order by
      1, 2
    <br>
    VERSION
    10.1.0.3.0
    <br>
    DEPTNO      | 81-01-01   | 81-02-01   | 81-03-01
    10          | 0          | 0          | 0
    20          | 0          | 0          | 0
    30          | 0          | 2850       | 0
    40          | 0          | 0          | 0
    <br>
    Now, if we substitute '1981-03-01' with '1981-06-01', we see 7 columns instead of 4
    <br>
    DEPTNO      | 81-01-01   | 81-02-01   | 81-03-01   | 81-04-01   | 81-05-01   | 81-06-01
    10          | 0          | 0          | 0          | 0          | 0          | 2450
    20          | 0          | 0          | 0          | 2975       | 0          | 0
    30          | 0          | 2850       | 0          | 0          | 2850       | 0
    40          | 0          | 0          | 0          | 0          | 0          | 0
    <br>To understand the solution, start by running the innermost subquery by itself and then work your way outward.

  • Query to find SQL with changed plans

    I am trying to find out which SQL statements have changed plans since they were first executed.
    I'm trying to run this on all databases from 9i upwards and I am assuming that I have no licensed access to the AWR. However, Statspack is installed on all databases. (So querying things like STATS$SQL_PLAN is fine).
    I am having difficulty understanding what HASH_VALUE, OLD_HASH_VALUE and PLAN_HASH_VALUE are, and how they can be used to help answer the problem. I am also trying not to use SQL_ID, since that column isn't there in 9i (I think), and I'd like something that is generically usable from 9i to 11g, if at all possible.
    Any hints, please.
    Edited by: Catfive Lander on May 14, 2012 12:01 AM

    Hi Sakshi,
    Try out this query if it can help you !
    SELECT a.user_name, a.description, c.responsibility_name, c.creation_date as ASSIGNED_DATE>FROM apps.fnd_user a,
    >apps.fnd_user_resp_groups b,
    >apps.fnd_responsibility_vl c
    >WHERE a.user_id = b.user_id
    >AND b.responsibility_id = c.responsibility_id
    >AND a.creation_date < = '01-JUN-07'
    ORDER BY a.user_name;Thanks,
    Anchorage :)

  • Query in pl/sql oracle

    Hi All!
    I want to write following type of query in PL/SQL
    How can I write one which will work.
    <B>
    SELECT count(1) INTO v_count2 from TRJ_TRAN_REJ_T a and PEU_PUR_ENRL_UNT_T b
    where a.TRJ_CVRG_PER_DATE IN (b.PEU_EFF_DATE AND b.PEU_END_DATE) AND
    a.purik = b.purik AND a.peuik = b.peuik
    <B>
    Above query is not working correctly. Any changes?? DATE stored in database is like 01/01/2001
    v_count2 is NUMBER variable declared in PL?SQL.
    SA

    You don't need to use a PL/SQL, a simple SQL will suffice. I guess you could write it as a function?
    I think your SQL was wrong so I took the liberty of fixing it for you. You seperate tables with commas in a FROM clause, not AND.
    Anyway, on the lines of a SQL Statement you can do the following.
    SELECT     count(1) AS mycount
    FROM     TRJ_TRAN_REJ_T a,
         PEU_PUR_ENRL_UNT_T b
    WHERE     a.TRJ_CVRG_PER_DATE IN (b.PEU_EFF_DATE AND b.PEU_END_DATE)
    AND     a.purik = b.purik
    AND     a.peuik = b.peuik
    Connection conn = DriverManager.getConnection(URL, username, password);
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery( your sql);
    while ( rs.next() )
         int mycount = rs.getInt("mycount");
    close stuff down here

  • Wrong query in pl/sql

    Good Morning,
    i have a string containing a query in pl/sql :
    description varchar2(100) := 'select adeia_id||description,adeia_id from mis_adeia where plafon=1';
    which selects adeia_id and description fron a table and displays them together, but i want to seperate adeia_id and description with a blank or a dot, so i change the string and make it like:
    description varchar2(100) := 'select adeia_id||' || ' ' || 'description,adeia_id from mis_adeia where plafon=1';
    am i doing something wrong?
    thanks for reading.

    thank you peter but it doesn't work. i tried it. the string i pass it as argument in the create_group_from_query function in forms builder, and when i use double quots it gives me the error, that cannot create the group! i don't know what is the fault.

  • SAP query transport error - need help

    hello,
      The system is throwing the following error when importing the query from development to QA client.
    We already have the query imported the first time without errors. This is happening with subsequent transports if there is a change or any modification to the query.
    Below is the error log from SAP regarding the failed transport :
    R3TRAQQUFI was repaired in this system
    Message no. TW104
    Diagnosis
    Object R3TRAQQUFI is in repair status. Therefore, it cannot be imported.
    System Response
    The object is not imported.
    Procedure
    If you still want to import the object, release the relevant repair and repeat the import.
    Please help
    Thanks in advance.

    Hi
    Here I am sending the step by step procedure for the SAP Query. Hope this helps you, if so please issue points.
    1. Go to SQ02 .
    Select Environment -> Query Areas
    Select Standard Area (Client specific) as show below
    2. Select Environment -> Transports
    Select Import radio button
    Check Overwriting allowed (only with import/upload/copy)
    Remove Check for Test Run
    Select Transport InfoSets and queries radio button
    Fill Infoset and Query with corresponding names
    Fill Import option with transport request number.
    3.  Click on Execute button
    With this it will be done.
    Thanks for your patience

  • Edit query results in SQL worksheet

    I can't edit query results in SQL worksheet, I not found any options to "ON" this. I use SQL Developer 2.1.1.64.

    You can't edit results in the worksheet. It's an accepted feature request with no scheduled date. In the mean time you have to go to the table or write an update statement.

  • NVARCHAR (MAX) TO PRINT DYNAMIC SQL QUERY TO A SQL FILE

    Hi 
    I have a requirement where i need to write an SP which would construct a huge query using dynamic SQL and save the Dynamic query to a file. 
    The Dynamic SQL Variable I am using as @NVARCHAR(MAX) but since the query being built is large (>4000 characters), I am not able to select it into a table. PRINT @SQL prints the whole query but SELECT @SQL prints only upto 4000 characterrs. 
    And I need to save this huge dynamix sql to a file using the SP.
    Any thoughts as to how i can achieve this?
    Rajiv

    This is a know problem with dynamic SQL nvarchar(max) concatenation.
    See below for correct assembly of large SQL strings:
    CREATE table #temp(qry nvarchar(max));
    declare @cmd nvarchar(max);
    SELECT @cmd=CONCAT(CONVERT(nvarchar(max),N'SELECT '),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),N'FROM SYS.TABLES'));
    insert into #temp SELECT @cmd;
    select * from #temp;
    select len(qry), datalength(qry) from #temp;
    -- 16022 32044
    drop table #temp;
    Dynamic SQL:  http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Transalate JPQL query to be SQL

    I'm using toplink. I wonder if there is tool to translate toplink JPQL query to be SQL in developer? what I'm looking for is I can type in a JPQL query, IDE will be able to show me the translated SQL. is this can be done in jdeveloper?
    Thanks

    Dear Friends,
    I have done the same thing. We r using PI 7.1.
    I have Sync Proxy ->  Syn JDBC . I tried to execute a simple query at the JDBC adapter by sending it through *access*  field in the XML structure.
    This is the input
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:CoilNoReceive xmlns:ns0="urn:essar-com:production:shearslitpoconfirm">
    - <stmt>
    - <TABLENAME action="SQL_QUERY">
      <access>SELECT coil_no,PARTS_ACT FROM P_INV where fac_index <> 6 and fac_index <>7 and rownum<5</access>
      </TABLENAME>
      </stmt>
      </ns0:CoilNoReceive>
    I am getting this error msg..
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Inbound Message
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>XIAdapterFramework</SAP:Category>
      <SAP:Code area="MESSAGE">GENERAL</SAP:Code>
      <SAP:P1 />
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error 'java.sql.SQLException: ORA-00900: invalid SQL statement ' executing service raw2sql with SQL statement '<?xml version="1.0" encoding="UTF-8"?> <ns0:CoilNoReceive xmlns:ns0="urn:essar-com:production:shearslitpoconfirm"><stmt><TABLENAME action="SQL_QUERY"><access>SELECT coil_no,PARTS_ACT FROM P_INV where fac_index <> 6 and fac_index<>7 and rownum<5</access></TABLENAME></stmt></ns0:CoilNoReceive>'</SAP:AdditionalText>
      <SAP:Stack />
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    What could be the problem. Reply ASAP.
    Thanks
    K. Ramesh

Maybe you are looking for

  • Error during MAIN_NEWBAS/STARTSAP_NBAS

    Hello, We are upgrading from 4.7 to ECC 6.0 EHP 5 and we are getting an error on phase MAIN_NEWBAS/STARTSAP_NBAS. Checks after phase MAIN_NEWBAS/STARTSAP_NBAS were negative! Last error code set: RFC call to subst_get_uvers failed with key RFC_ERROR_C

  • Want to move to FCE HD but have questions before I drop the coin . . .

    I currently have Adobe Premiere 3.0 on a Windows machine, plus I'm primarily a still photographer, so my video experience is limited. I'd rather do all of my video work on my new iMac, so I'm looking at buying Final Cut Express HD instead of returnin

  • How to stop size of JTextField from changing when I change font to bold

    I'm working on a Sudoku solver for a CS project. I've got JTextFields for the input. I want to bold the entries of the begining puzzle, like they are in the magazines. When I set the font to bold, it changes the size of the text field. I'm using the

  • How do I pass SELECT-OPTIONS to another screen via CALL TRANSACTION?

    Good day, everyone! I am writing a program that will be passing PARAMETERS and SELECT-OPTIONS values to another transaction via the CALL TRANSACTION statement.  I'm new at this, and I've run into a problem.  I have several fields that are defined as

  • ICloud uploader stuck

    I purchased the 200GB plan to get all my photos into iCloud, and started the upload around 36 hours ago. So far, only a few hundred images have uploaded. the counter in Photos Preferences has been stuck on the same number most of the day. I even rest