Tricky query needing clever SQL...

A table called alt_websearch_log records the time it takes to complete each search performed on a website. I am therefore able to write something like this:
select to_char(search_date,'DD/MON/YYYY'), count(*), avg(searchtime_secs), max(searchtime_secs)
from alt_websearch_log
group by to_char(search_date,'DD/MON/YYYY')
order by to_char(search_date,'DD/MON/YYYY') desc
...and it works fine, giving me a daily average search time over a period of weeks or months for reporting to management. The trouble is that I have to periodically rebuild the indexes that make this search work, and during the time that the rebuild is taking place -not surprisingly- search performance slows down quite a bit.
(Incidentally, I know not to rebuild indexes routinely, but these two are special, because they're Context indexes and the table on which they're built is itself completely reconstructed at weekends. It's a weird system, but we have to do it that way, for lots of reasons I ask you to take on trust, at least for now!)
My rebuilding code has been modified to insert a line into the alt_websearch_log table, so that I can select from it and see this sort of thing:
SESSION_ID SERVERNAME SEARCHTERMS SEARCHDATE
99999999999 LOCALDBSRVR START REBUILD 15/7/2008 16:00
And when the rebuild completes, I put a very similar line that says 'STOP REBUILD' at (say) 15/7/2008 18:00
So what I would like to be able to do is to run the same sort of query as I started with, but with all the searches that take place between a start and stop rebuild marker being ignored for the purposes of computing the average and maximum.
My problem is that I cannot conceive of a query that discards rows between a start and stop time that happens repeatedly (for example, I would have a START/STOP pair on 8th July, 1st July, 23 June and so on, but because manual rebuilds might sometimes happen, there's no definite pattern for when such pairs occur).
In other words, if the sorted data ran;
1/7/08 10:00 1.3secs
1/7/08 10.05 1.4 secs
1/7/08 10:10 start rebuild
1/7/08 10:11 2.5 secs
1/7/08 10:12 4.5 secs
1/7/08 10:15 stop rebuild
1/7/08 10:16 1.1 secs
2/7/08 11:00 1.1secs
2/7/08 11.03 1.1 secs
2/7/08 11:05 start rebuild
2/7/08 11:14 3.1 secs
2/7/08 11:16 3.6 secs
2/7/08 11:25 stop rebuild
2/7/08 11:36 1.2 secs
...I would want 1.3, 1.4 and 1.1 to be averaged to a total of 1.267 for 1/7/08, and the two 2 second plus searches on that to be ignored for reporting purposes. And then I'd need the average for 2/7/08 to be reported as 1.13 seconds, with the two 3+ second response times ignored, because they were recorded between that day's start/stop rebuild markers.
Whilst it is theoretically possible that a 'start' could begin at, say 5 to midnight and its corresponding 'stop' wouldn't be recorded until 5 past midnight, if it makes it any easier, you can assume that a start and a stop always share the same date.
It is also possible in real life that we might do more than one rebuild per day, but if it makes it any easier, it's OK to assume only one start/stop marker will be recorded per day. (Actually, it would be nice if you didn't have to assume that, because this is a situation I know we would definitely face at some point in the future).
I'd very much appreciate some insight into any SQL techniques that can be used to deal with this issue. I am guessing some of the modelling commands might be useful, but I don't know where to begin on that. I'm using 10.2.0.3 on Windows.
Sorry for the long question. Grateful for any help.

OK build a sample table,
create table alt_websearch_log
(search_date date,
search_time_secs numeric(9,2),
searchterms varchar2(50));
insert into alt_websearch_log values (to_date('1/7/08 10:00','dd/mm/yy hh24:mi'),1.3,'bob,sally');
insert into alt_websearch_log values (to_date('1/7/08 10:05','dd/mm/yy hh24:mi'),1.4,'dev');
insert into alt_websearch_log values (to_date('1/7/08 10:10','dd/mm/yy hh24:mi'),null,'start rebuild');
insert into alt_websearch_log values (to_date('1/7/08 10:11','dd/mm/yy hh24:mi'),2.5,'code');
insert into alt_websearch_log values (to_date('1/7/08 10:12','dd/mm/yy hh24:mi'),4.5,'nugget');
insert into alt_websearch_log values (to_date('1/7/08 10:15','dd/mm/yy hh24:mi'),null,'stop rebuild');
insert into alt_websearch_log values (to_date('1/7/08 10:16','dd/mm/yy hh24:mi'),1.1,'random');
insert into alt_websearch_log values (to_date('2/7/08 11:00','dd/mm/yy hh24:mi'),1.1,'search');
insert into alt_websearch_log values (to_date('2/7/08 11:03','dd/mm/yy hh24:mi'),1.1,'term');
insert into alt_websearch_log values (to_date('2/7/08 11:05','dd/mm/yy hh24:mi'),null,'start rebuild');
insert into alt_websearch_log values (to_date('2/7/08 11:14','dd/mm/yy hh24:mi'),3.1,null);
insert into alt_websearch_log values (to_date('2/7/08 11:16','dd/mm/yy hh24:mi'),3.1,null);
insert into alt_websearch_log values (to_date('2/7/08 11:25','dd/mm/yy hh24:mi'),null,'stop rebuild');
insert into alt_websearch_log values (to_date('2/7/08 11:36','dd/mm/yy hh24:mi'),3.1,null);
insert into alt_websearch_log values (to_date('2/7/08 11:39','dd/mm/yy hh24:mi'),1.1,'tube');
commit;then try this..
col av_stime for 99.99
col max_s_time for 99.99
select trunc(search_date),avg(SEARCH_TIME_SECS) av_stime,max(search_time_secs) max_s_time from
(select search_date,search_time_secs,
nvl((LAST_VALUE(decode(searchterms,'stop rebuild','stop rebuild','start rebuild','start rebuild',null) IGNORE NULLS) over
(ORDER BY search_date ROWS BETWEEN UNBOUNDED PRECEDING AND current row)),'stop rebuild') AS term
from alt_websearch_log) a
where term = 'stop rebuild'
group by trunc(search_date)
order by trunc(search_date) desc;
TRUNC(SEA AV_STIME MAX_S_TIME
02-JUL-08     1.60       3.10
01-JUL-08     1.27       1.40this work accross days and with multiple rebuilds, randolphs comments apply if
the logic is broken and a rebuild deosn't get logged correctly this will return odd
results. It may be safer to add an additional column to log the rebuilds as you will
have a problem is a user searches for one of the two key terms. Also I have
assumed the search_time_secs will be null when you log the rebuilds.
Chris

Similar Messages

  • SQL query needed to identify cancelled invoice where distribution lines

    SQL query needed to identify cancelled invoice where distribution lines Debit is not equal Credit line item in particular
    Is there a way from back end FROM ap_invoice_distributions_all where we can find for the cancelled invoice where distribution lines Debit is not equal Credit line item
    Regards,
    Prakash Ranjan

    Hello Prakash
    Can you please see if this query helps you?
    SELECT i.invoice_id, i.invoice_amount, nvl(sum(d.amount),0)
    FROM ap_invoice_distributions_all d, ap_invoices_all i
    WHERE i.org_id = <you org_id>
    AND i.invoice_id = d.invoice_id
    AND d.line_type_lookup_code not in ('PREPAY')
    AND i.cancelled_date IS NOT NULL
    GROUP BY i.invoice_id, i.invoice_amount
    HAVING (i.invoice_amount <> nvl(sum(d.amount),0))
    ORDER BY i.invoice_id asc
    Octavio

  • Need a SQL query(Pls Its urgent)

    Hi,
    I want a SQL query for the foll..
    Details r below..
    Table AFPFTRAN
    BU TRansactiondate Amt
    13202 10-04-05 10,000
    13203 11-05-05 20,000
    13202 20-04-05 5,000
    Table AFGENCOD
    BU Clerk Name Clerk Code
    13202 Amit TFBG
    13203 Anand TFMG
    I want a query to get data as below..
    Tr Date TFBG TFMG
    Apr 15,000 0
    May 0 20,000
    JUn 0 0
    Jul 0 0
    Aug
    Sep
    Aug
    Nov
    DEc
    Jan
    Feb
    Mar
    I want this to achieve using a single query...?How can I achive this?
    Pls give the sol...
    Adios...
    Prashanth Deshmukh

    Does it look like you need ?
    SQL> select * from t;
            BU TDATE           AMT
         13202 10.04.05      10000
         13203 11.05.05      20000
         13202 20.04.05       5000
    SQL> select * from t1;
            BU NAME  CODE
         13202 Amit  TFBG
         13203 Anand TFMG
    SQL> SELECT pivot_month.mname, tops.TFBG, tops.TFMG
      2  from
      3  (
      4  select to_char(t.tdate,'MM') month_no,
      5  sum(decode(t1.code,'TFBG',t.amt,0)) TFBG,
      6  sum(decode(t1.code,'TFMG',t.amt,0)) TFMG
      7  from t1, t
      8  where t.bu=t1.bu
      9  and to_char(t.tdate,'yyyy') = 2005
    10  GROUP BY t1.code, to_char(t.tdate,'MM')
    11  ) tops,
    12  (select rownum mn, to_char(to_date(rownum,'MM'),'MON') mname,
    13  case when rownum between 1 and 3 then rownum + 9
    14  else rownum - 3 end rn
    15  from dict where rownum < 13) pivot_month
    16  where pivot_month.mn = tops.month_no (+)
    17  order by pivot_month.rn
    18  /
    MNA       TFBG       TFMG
    APR      15000          0
    MAY          0      20000
    JUN
    JUL
    AUG
    SEP
    OCT
    NOV
    DEC
    JAN
    FEB
    MAR
    12 rows selected.Rgds.

  • List the count of each schema objects.. schema wise sql query needed

    Hi Friends,
    i need a sql query which has to list the schema name along with the count of schema objects like tables,views,triggers.... order by schemaname
    Regards,
    DB

    Hi
    You can try this option if you use 11g .
    Get all the object types in your db.
    SELECT DISTINCT object_type
                 FROM dba_objects;Then include all the object types in to the below query.
    select *
      from (select owner, object_type, 1 CNT
              from dba_objects ) e
            pivot( sum(CNT) for object_type in
              ( 'INDEX','TYPE','VIEW','LIBRARY','TRIGGER','DIRECTORY','PACKAGE','QUEUE','PACKAGE BODY','TABLE PARTITION','PROCEDURE',
                'WINDOW','CLUSTER','LOB','FUNCTION','CONSUMER GROUP','CONTEXT','RULE','XML SCHEMA','SEQUENCE','INDEX PARTITION','OPERATOR',
                'EVALUATION CONTEXT','SCHEDULE','JOB','SCHEDULER GROUP','LOB PARTITION','JOB CLASS','INDEXTYPE','TABLE','TYPE BODY','RESOURCE PLAN',
                'TABLE SUBPARTITION','UNDEFINED','DESTINATION','SYNONYM','EDITION','PROGRAM','RULE SET' ) )       
    order by owner;Cheers
    Kanchana

  • 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

  • How much UNDO does a query need?

    It seems that due to a gigantic delete, I am running out of UNDO. How can I see exactly how much undo a query needs?
    Searching on the web, I found this:
    select sq.sql_text sql_text, t.USED_UREC Records, t.USED_UBLK Blocks, (t.USED_UBLK*8192/1024) KBytes from v$transaction t,
    v$session s,
    v$sql sq
    where t.addr = s.taddr
    and s.sql_id = sq.sql_id
    and s.username = 'blah'
    , which is fine, but it seems to be returning results for only running queries. In other words, when the delete query I am investigating is executed, the above select returns no rows. Is there a way to modify it to return also queries that have been executed?
    Any help is welcome.
    Message was edited by:
    user622271

    Hi,
    It seems that you need to make an outer join between v$sql and v$session views [s.sql_id = sq.sql_id(+)] ... For more information is if this [url http://forums.oracle.com/forums/thread.jspa?messageID=1756927&#1756927]thread can help you.
    Cheers
    Legatti

  • 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.

  • How to find which query need to tuned

    Hi ,
    How can i find , which query need to tuned . Is there any mechanism behind it?

    The mechanisms behind it are depending on your database version.
    For example:
    Oracle 9i has STATSPACK that helps you to identify possible problem queries.
    Oracle 10g has AWR - Automatic Workload Repository
    Oracle 11g has SPA - Database Replay SQL Performance Analyzer
    but there are many more tools/mechanisms...trace/tkprof for example.
    Go to http://tahiti.oracle.com and do a search on 'performance tuning guide', and pick the one that matches your (sofar unknown) database version, read a bit every now and then and see what tools are at your disposal and fit your requirement and situation.
    Besides the links that Blu already posted, searches on http://asktom.oracle.com also give lots of pointers and explanations regarding the (neverending) tuning process (at least: helped me tremendously in understanding the tuning process, the do's and dont's).
    Make sure you don't get CTD (Compulsive Tuning Disorder) from all this... ;)

  • 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

  • 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 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

  • Defining more parameters than a query needs

    Hi.
    When I run the following code, I get the error "ORA-01036: illegal variable name/number" .
    The problem is that I currently define more parameters than the query needs. Thats because I don't know how many bind variables the query uses, and I would not like to parse the query ...
    I don't understand why I have to define exactly the same number of parameters, and in the exact order ... It doesn't make sense. As bind variables have names, there should be no problem passing more parameters or parameters in a different order: the binding should be done by name...
    I'm currently using Oracle10g, ODP.NET and .NET Framework 2.0.
    I would appreciate any help ...
    Thank you.
    Ricardo Coimbras
    ===== BEGIN VB.NET CODE =====
    Sub Execute_Query(ByVal SqlString as String)
    Dim ObjCmd As OracleCommand
    Dim DataAdap As OracleDataAdapter
    Dim outDsCorpo As DataSet
    Dim Constroi_Conn_String_Oracle As String
    Dim mObjConnOracle As OracleConnection
    Constroi_Conn_String_Oracle = "User ID=uuu" & _
    ";Password=ppp" & _
    ";Data Source=bd" & _
    ";Pooling=false"
    mObjConnOracle = New OracleConnection(Constroi_Conn_String_Oracle)
    mObjConnOracle.Open()
    ObjCmd = mObjConnOracle.CreateCommand()
    ObjCmd.CommandType = CommandType.Text
    ObjCmd.CommandText = SqlString
    ObjCmd.Parameters.Add("p1", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    ObjCmd.Parameters.Add("p2", OracleDbType.Char, 3, "001", ParameterDirection.Input)
    DataAdap = New OracleDataAdapter(ObjCmd)
    outDsCorpo = New DataSet()
    DataAdap.Fill(outDsCorpo)
    GridView1.DataSource = outDsCorpo
    GridView1.DataBind()
    DataAdap = Nothing
    ObjCmd = Nothing
    mObjConnOracle.Close()
    mObjConnOracle.Dispose()
    mObjConnOracle = Nothing
    End Sub
    Execute_Query "select * from map.t_mapa_def where mapa_def_cod = :p1 order by mapa_def_cod"
    ===== END VB.NET CODE =====

    Hi,
    BindByPosition is the default behavior as per the docs, and you can change that by setting cmd.BindByName=true which adds a little bit of extra overhead.
    That wont fix the error seen when binding a random number of parameters to the statement though. You need to bind the correct number and types of parameters.
    Greg

  • Need pl/sql stmnts. for this simple logic

    Hi,
    I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace
    out ..
    select * from GSR03_PO_DTL;
    PO_NUM
    L53177000 -- > no changes reqd (only one entry with new format)
    L00041677 --> to be updated to L41677000(only one entry with OLD format)
    L43677000 -- > no change reqd (exists one row with new format and old format like below)
    L00043677 -- > to be deleted this is old format (and new format like above already exists)
    EX:
    L00012345 --- old format
    L12345000 --- new format
    Hope question is clear. I written the following program.
    update is working fine but delete is not working.
    Please help.
    Thanks in Advance
    Devender
    declare
    Cursor c_test is
    (select po_num from GSR03_PO_DTL);
    BEGIN
    FOR r_test in c_Test
    LOOP
    dbms_output.put_line (r_test.po_num);
    IF ('L'||substr(r_test.po_num,5,5)) = ('L'||substr(r_test.po_num,2,5)) then
         dbms_output.put_line ('delete stmnt');
    END IF;     
    EXIT WHEN c_test%NOTFOUND;
    END LOOP;
    FOR r_test in c_Test
    LOOP
    IF r_test.po_num like 'L000%' then
    IF ('L'||substr(r_test.po_num,5,5)) is not NULL then
         update GSR03_PO_DTL set PO_NUM = 'L'||substr(po_num,5,5)||'000'
         where po_num like 'L000%' ;
         dbms_output.put_line ('update stmnt');
    END IF;     
    END IF;
    END LOOP;
    END;
    *********************

    No need for PL/SQL, man.
    SQL> SELECT po_no FROM po1
      2  /
    PO_NO
    L53177000
    L00041677
    L43677000
    L00043677
    SQL> UPDATE po1 y
      2  SET    y.po_no = 'L'||substr(y.po_no,5,5)||'000'
      3  WHERE  y.po_no LIKE 'L000%'
      4  AND    NOT EXISTS ( SELECT null FROM po1 x
      5                      WHERE x.po_no =  'L'||substr(y.po_no,5,5)||'000')
      6  /
    1 row updated.
    SQL> DELETE FROM po1 y
      2  WHERE  y.po_no LIKE 'L000%'
      3  AND    EXISTS ( SELECT null FROM po1 x
      4                  WHERE x.po_no =  'L'||substr(y.po_no,5,5)||'000')
      5  /
    1 row deleted.
    SQL> SELECT po_no FROM po1
      2  /
    PO_NO
    L53177000
    L41677000
    L43677000
    SQL> Cheers, APC

  • 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.

Maybe you are looking for

  • Can't access Aperture support forum

    Hi all, not sure whether this is the right place to report a problem with the Aperture Support forum - I couldn't find anywhere to report the problem so posted here. When I try to enter it I get the following error message "Unsupported Browser detect

  • Windows 7 install hangs while loading

    Been trying to install Windows 7 64 to my MBP through Boot Camp, but it hangs when loading files from the DVD. It'll get through the progress bar saying "Windows is loading files..." but then stops after that. Any ideas on what to do?

  • 10G on 32 bit Windows to 11GR2 on 64 bit windows using DBUA

    Scenario is this: I am upgrading a 10.2.0.3.0 database running on 32 bit server 2003 to 11.2.0.1 running on server 2008 64 bit. I normally use export/import for this, but I was thinking about using DBUA if possible this time, is it possible to copy d

  • Third Party Scenario

    Hi all We are configuring Third Party sale process . In short it will be as follows Sales Order - PR in Back ground> PO with reference to PR> Delivery to customer directly>MIRO > Customer invoicing At any point we are not going to take GR and we will

  • Role Profile in FICAX

    Hi, We are unto FICAX . I have 2 questions: 1. Business Process requires write off to be done using FPE1 transaction by posting document manually. They need to know whether authorisation to post documents for write off can be restricted amount wise.