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

Similar Messages

  • A simple query in My SQL what is the similer query for that in Oracle ???

    hello friends
    In My Sql if i have 1000 records in a table and i want to get the records from 400 to 550 then it is posible by giving the following query
    Select * from Table a , table b where condition "List 400,550" gives the records from 400 to 550
    what is the coresponding query for this in oracle database
    any one help me pls
    mail me to [email protected]

    Genericly, if you want records N through M from a SELECT statement, there's a wonderful article on asktom.oracle.com
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064
    Justin

  • Oracle 8.1.5.1 upgrade to 9.2.0.6 sql - Oracle change or bug ?

    The following query is working on Oracle 8.1.5.1 (result 1 record), but not on Oracle 9.2.0.6 (result 0 record).
    We don't have the source to this application, and we then have to solve it on the Oracle side - it looks like an Oracle change/bug ?
    I've turned on Oracle tracing to trace the actual sql and also running explain seeing no difference.
    SELECT UNIQUE change_log.pkey_val1, customer.customer_name, customer.brief_name,
    change_log.user_id, trunc(change_log.created_date, 'DD'), change_log.auth_status,
    trunc(change_log.auth_status_date,'DD'), trunc(change_log.print_date,'DD'),
    change_log.print_status FROM customer, change_log WHERE customer.customer_id=change_log.pkey_val1
    AND auth_status = '0' AND change_log.pkey_val1 like '5334073' ORDER BY 5;
    SELECT STATEMENT_ID, operation, options, object_name, object_type, id, parent_id FROM plan_table
    WHERE STATEMENT_ID = 'QUERY1' ORDER BY id;
    Oracle 8.1.5.1
    QUERY1 SELECT STATEMENT
    QUERY1 SORT UNIQUE
    QUERY1 NESTED LOOPS
    QUERY1 TABLE ACCESS BY INDEX ROWID CHANGE_LOG
    QUERY1 INDEX RANGE SCAN DX_971_01 NO
    QUERY1 TABLE ACCESS BY INDEX ROWID CUSTOMER
    QUERY1 INDEX UNIQUE SCAN U128_13 UN
    Oracle 9.2.0.6
    QUERY1 SELECT STATEMENT
    QUERY1 SORT UNIQUE
    QUERY1 NESTED LOOPS
    QUERY1 TABLE ACCESS BY INDEX ROWID CHANGE_LOG
    QUERY1 INDEX RANGE SCAN DX_971_01 NO
    QUERY1 TABLE ACCESS BY INDEX ROWID CUSTOMER
    QUERY1 INDEX UNIQUE SCAN U128_13 UN

    Please refer [url http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/conditions10a.htm
    ]'Patterns Without % Example' on Oracle9i SQL Reference.
    Here is [url http://download-west.oracle.com/docs/cd/F49540_01/DOC/server.815/a67779/operator.htm#997970]Oracle8i SQL Reference.
    If a pattern does not contain the "%" character, the condition can be TRUE only if both operands have the same length.
    So... there are bugs on 8.1.x, 9.2.0.4...
    SQL> select * from v$version where rownum <= 1;
    BANNER
    Personal Oracle7 Release 7.3.2.3.1 - Production Release
    SQL> create table tab1 (col1 char(6));
    Table created.
    SQL> insert into tab1 values ('xyz');
    1 row created.
    SQL> select * from tab1 where col1 like 'xyz';
    no rows selected
    SQL> select * from v$version where rownum <= 1;
    BANNER
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    SQL> create table tab1 (col1 char(6));
    Table created.
    SQL> insert into tab1 values ('xyz');
    1 row created.
    SQL> select * from tab1 where col1 like 'xyz';
    COL1
    xyz
    SQL> select * from v$version where rownum <= 1;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
    SQL> create table tab1 (col1 char(6));
    Table created.
    SQL> insert into tab1 values ('xyz');
    1 row created.
    SQL> select * from tab1 where col1 like 'xyz';
    COL1
    xyz
    SQL> select * from v$version where rownum <= 1;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    SQL> create table tab1 (col1 char(6));
    Table created.
    SQL> insert into tab1 values ('xyz');
    1 row created.
    SQL> select * from tab1 where col1 like 'xyz';
    no rows selected

  • SQL Query works in SQL Developer, but not always in MII

    Hi all,
    I encountered a strange behaviour with a query in MII 12.0.2. Maybe someone has a guess what happens.
    I have created a SQL query which runs against Oracle 10g tables. I have tested the query using SQL Developer, and it throws a couple of lines, depending on the contents of the where clause.
    Next I have copied the query to a MII SQL Query (FixedQuery). However, the output is empty most of the time, without showing any errors. After some testing I got the impression that older data are not displayed, but there is no time or date setting in MII.
    As the SQL Developer always returns rows, I am unsure where to search for the error.
    Regards
    Michael

    Michael,
    I would imagine that you have sub-select statements in your FixedQuery, all which will fall subject to the RowCount property of the query template (SQL defaults to 100), which is issued through the driver and typically honored by the database when returning the data from your request.
    Most of the native database query tools allow you to make unbound query requests with no limit on rows, which would probably account for the difference between SQL Developer and the query template.
    For SQLServer it's ROWCOUNT:  http://msdn.microsoft.com/en-us/library/ms188774.aspx
    For Oracle it's ROWNUM:  http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
    So the answer would be not to make the query template row count some rediculous number, but more appropriately refine the way that the database request is issued.
    Regards,
    Jeremy

  • Open Query issue in SQL server 2005

    I am running following query in SQL Server 2005, remote connection is Oracle. Query runs perfect in oracle.
    Any help would be greatly appreciated.
    Error is:  
    OLE DB provider "MSDAORA" for linked server "ORACLEROSTER" returned message "ORA-00911: invalid character ".
    select 
    EMPLOYEEID,
    TermDate,
    UserName,
    ACTION,
    DEPTID,
    DESCR
      from OPENQUERY(ORACLEROSTER,
    'SELECT DISTINCT substr(A.EMPLID, 1,10) "EMPLOYEEID" 
    , TO_CHAR(A.EFFDT,"yyyy-mm-dd") "Term Date"
    , SUBSTR(A.NAME, 1, 25) "User Name"
    , SUBSTR(A.ACTION, 1, 10) "ACTION"
    , SUBSTR(A.DEPTID, 1, 10) "DEPTID"
    , SUBSTR(B.DESCR, 1, 20) "DESCR" 
      FROM sysadm.PS_PERSONNEL_HIST A, sysadm.PS_EMPLMT_SRCH_QRY A1, sysadm.PS_DEPT_TBL B, sysadm.PS_SET_CNTRL_REC B2 
      WHERE B.DEPTID = A.DEPTID 
     AND B2.SETCNTRLVALUE = A.BUSINESS_UNIT 
    AND B2.RECNAME = "DEPT_TBL" 
     AND B2.SETID = B.SETID 
     AND A.EMPLID = A1.EMPLID 
     AND A.EMPL_RCD = A1.EMPL_RCD 
     AND A1.ROWSECCLASS = "DPPDIFLD" 
     AND ( A.EFFDT = 
          (SELECT MAX(A_ED.EFFDT) FROM sysadm.PS_PERSONNEL_HIST A_ED 
           WHERE A.EMPLID = A_ED.EMPLID 
           AND A.EMPL_RCD = A_ED.EMPL_RCD 
           AND A_ED.EFFDT <= SYSDATE) 
        AND A.EFFSEQ = 
            (SELECT MAX(A_ES.EFFSEQ) FROM sysadm.PS_PERSONNEL_HIST A_ES 
            WHERE A.EMPLID = A_ES.EMPLID 
              AND A.EMPL_RCD = A_ES.EMPL_RCD 
              AND A.EFFDT = A_ES.EFFDT) 
         AND A.ACTION = "TER" 
         AND A.LOCATION IN ("500","600") 
         AND A.JOBCODE IN ("SR5","SR3","ASR","ASRS","IBP5","IBP3","I53610","I53630","053610","053630") 
         AND A.EFFDT BETWEEN SYSDATE - 7 AND SYSDATE 
         AND A.ACTION_REASON <> "ZNS" 
         AND A.EMPL_STATUS = "T" 
         AND B.EFFDT = 
            (SELECT MAX(B_ED.EFFDT) FROM sysadm.PS_DEPT_TBL B_ED 
            WHERE B.SETID = B_ED.SETID 
              AND B.DEPTID = B_ED.DEPTID 
              AND B_ED.EFFDT <= A.EFFDT) )
      order by 2;')
    s

    How about if you make the query into a view on ORACLE and SELECT from the view?
    Kalman Toth SQL SERVER 2012 & BI TRAINING
    New Book: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2012

  • 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

  • Query DB2 tables from oracle using normal view

    This is with regard to querying db2 tables using oracle views. The view is created using dblink. The querying is not an one time activity.querying will be done once in a day. Can i use normal view (will it work ) or should i use materialised view. will i be able to view the added records in db2 table using normal view?
    thanks,
    vinodh

    Vinodh2 wrote:
    This is with regard to querying db2 tables using oracle views. The view is created using dblink. The querying is not an one time activity.querying will be done once in a day. Can i use normal view (will it work ) or should i use materialised view. will i be able to view the added records in db2 table using normal view?How can the SQL select statement via a dblink not work for a view, but the same SQL select statement work for a materialised view?
    Do you think the database link or remote database care whether the select SQL that hits it, comes from a PL/SQL procedure, a view, a materialised view, a job or whatever else? It has no idea what/who is behind that select SQL - and nor does it care.
    As for the benefits of a view vs. a materialised view - that depends on the requirements for needing to use that foreign database's data in the local database.

  • 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

  • Can i Use two qery hints in one SQL(Oracle)?

    Hi,
    Can i Use two Query hints in one SQL(Oracle)? USE_HASH and No_Merge
    Thanks

    user10916886 wrote:
    Can I use like
    /*+ USE_HASH(X,Y) NO_MERGE(X) */
    will this work?Not really: NO_MERGE relates to mergeable views, not base tables. So whilst the USE_HASH may result in a hash join between the tables X and Y, USE_MERGE will be ignored for X.
    As hoek says, however, HINTs should be a last resort only, and if they're to be used at all you're best to stay with those that don't involve explicit objects, like ALL_ROWS, FIRST_ROWS_10, etc.
    user10916886 wrote:
    Im my database, if i don't use query hints. The expalin plan uses Nested loops, hence the query takes a lot of time.You would be better trying the ALL_ROWS hint here, instead of USE_HASH.
    Edit
    The optimizer, however, will have chosen NESTED LOOPs where it did because it believed that to be the most efficient data retrieval path with the information that it had to hand. So, if your statistics are comprehensive and up-to-date, yet the optimizer is continually opting for the less efficient plan, there's something else wrong, and HINTs are only masking that problem in the short-term.

  • Difference   LDAP & SQL & ORACLE

    Hi All
    I'm currently working in a messaging environment which
    includes LDAP Server and here i want to know the difference
    bettween LDAP - SQL - ORACLE.
    The Read access is faster in LDAP than write ? is it correct ??
    & i think in SQL write access is faster that read acess ?? is it correct??
    My Ques..
    1) If Any body know difference between LDAP,SQL & ORACLE ?
    kindly let me know ??
    Thanks in Advance.

    LDAP is a standard defined at IETF (RFC 4510 and associated)
    It is derived from the ISO-ITU standard X.500 and has a hierarchical, object oriented model.
    Sun Directory Server implements LDAP.
    SQL is a query language to access relational databases.
    Oracle is a company which has several products including a relational database, an LDAP server (Oracle OID).
    For more details, I would suggest a simple search on the internet for "LDAP vs RDBMs". There are many well written articles available.
    Regards,
    Ludovic.

  • Visual query  builder in SQL developer ...

    hi
    Thank you for reading my post
    when we can expect a visual query builder in sql Developer ?
    also , how i can make an auto increment field in SQL develoepr ?
    Thanks

    I can't answer your first question.. but the second has been hashed over a few times. In short, there are no auto-increment fields in Oracle. Instead there are sequences which are more complicated to use, but much more versitile.
    Auto increment trigger
    Auto Increment
    Eric

  • Query help in sql commands

    using apex 4.1 i'm entering the following query in the sql command window and I keep getting a pop-up for Entering Bind Variable. I'm not using bind variables though, anyone else see this issue before?
    SELECT A.FIRST,A.LAST,A.COMPANY AS CNAME,
    J.TOT_MAN_HOURS,
    J.ACREAGE,
    W.NUM_WORKERS,
    W.START_DT
    FROM EW_ACCOUNTS A, EW_WORK_ORDER W, EW_JOBS J
    WHERE A.ID = J.ACCT_ID
    AND J.JOB_ID = W.JOB_ID
    AND W.START_DT >= SYSDATE
    AND W.START_DT < SYSDATE+1
    ORDER BY W.START_DT

    I tried that and it didn't seem to help either.
    Funny though, if I write a new query against just one of the tables and write out each column name. it works. If I use the * instead of writing each column name, I have the same issue.
    This is in apex.appshosting.com free demo environment. I sent them an email asking about it and they told me it was a code issue and they don't support the demo environment.

  • Query can run in Oracle 10g but very slow in 11g

    Hi,
    We've just migrated to Oracle 11g and we noticed that some of our view are very slow (it takes seconds in 10g and takes 30 minutes in 11g), and the tables are using the local table.
    Do any of you face the same issue?
    This is our query:
    SELECT
    A.wellbore
    ,a.depth center
    ,d.MD maxbc
    ,d.XDELT xbc
    ,d.YDELT ybc
    ,e.MD minac
    ,e.XDELT xac
    ,e.YDELT yac
    from
    table_A d,table_A e, table_B a
    where a.wellbore = d.WELLBORE (+)
    and a.wellbore = e.WELLBORE(+)
    and d.MD = (select max(MD) from table_A b where b.MD < a.depth and
    d.wellBORE = b.wellBORE)
    and e.md = (select min(md) from table_A c where c.MD > a.depth and
    e.wellBORE = c.wellBORE);

    Thanks I will move to the correct one..
    Rafi,
    Build the Indexes and it is still slow. I am querying from a view from another database, which is in 10g instances.
    Moved: Query can run in Oracle 10g but very slow in 11g
    Edited by: 924400 on Apr 1, 2012 6:03 PM
    Edited by: 924400 on Apr 1, 2012 6:26 PM

  • 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

  • How to Implement KFF Range (Low and High) in query find form in oracle apps

    Hi,
    Please provide some sample script for using KFF range LOV (Low and High) in one of the query find form in Oracle apps R12.
    I need to customize one of the standard form and add this range functionality for that search form.
    Thanks,
    Prasanna

    Yuvaraaj,
    Your request is unique to the Oracle Enterprise Business Suite (EBS). Please post your question in the General EBS Discussion forum. If you have a general Forms question, by all means, ask it here! ;-)
    Craig...

Maybe you are looking for

  • One lockbox for multiple company codes

    Is it possible to have one lockbox for multiple company codes?

  • Exception: ORABPEL-05007 No messages being delivered

    Can any one help me with the following errors? I have a number of composites deployed into an environment and all composites have stopped delivering messages. I can see from the EM console that the end point is being called when I run a test from the

  • Quantity reconcilation for lost material

    Hello Need suggestion on subcontractor quantity reconciliation. Scenario is, subcontract PO is made, material is transferred to subcontractor, material is lost at vendor end. User has created subcontract PO, material transferred using Transfer Postin

  • NetConnection.Connect.Closed event not triggered in Vista FF3 when in fullscreen mode

    Hello Pals - I'm trying to handle the net connection drop and provide some kind of visual cue to user. For this I'm listening to NetConnection.Connect.Closed event and when its triggered, I take further steps. The events are triggered in Vista FF3(wi

  • Why won't InDesign download?

    I paid for Indesign CC and tried to download it. I get the list of apps with Indesign listed under "Your Apps".  It says "up to date".  I cannot download the app.