InterMedia Text Query in Dynamic SQL

I have a query using score and contains interMedia operators that runs without problem from the SQL*Plus command line, but generates a "ORA-01858: a non-numeric character was found where a numeric was expected" error when run via dynamic sql.
The query runs something like this:
select
score(1),
score(2),
a.field1,
b.field2
from
a,
b,
where
b.id (+)= a.id and
b.name (+)= 'test' and
((contains(a.content, 'query', 1) +
(contains(b.valud, 'query', 2)) > 0
I'm trying to avoid an OR clause by adding the two contains clauses together. Could this error be caused by the outer join on table b? If so, why does it run without problems from SQLPlus?
null

Thanks for the help.
Can you give me an example of how I have to specify the url in the database? For my intranet websites, I was able to use the foln. two formats http://host1/asptest/index.html (and)
URL:http://scott:tiger@host1:80/asptest/index.html
where host1 is the name of the host and 80, the port number.
I need to be able to access the oracle website(http://www.oracle.com/index.html) and run the foln. query,
SELECT id, url FROM test WHERE CONTAINS(url, 'Education')>0;
I tried setting the HTTP_PROXY attribute of the URL_DATASTORE, and specified the url as http://www.oracle.com/index.html in the database, but that didn't seem to help.
Thanks.
null

Similar Messages

  • Query with Dynamic SQL

    Hello,
    I would like to create a Dynamic SQL in which change is the name of the table according to the outcome of the first SQL. This is possible?
    'WITH TABLE_X AS(SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL <= 12)' ||
    'SELECT A.COL1, A.COL2, B.COL1, B.COL7'                              ||
    '  FROM TABLE_A' || TABLE_X.LVL || ' A'                              ||
    '     , TABLE_B' || TABLE_X.LVL || ' B'                              ||
    ' WHERE A.COL1 = B.COL1 AND ...    'tables in database
    TABLE_A1
    TABLE_A2
    TABLE_A12
    TABLE_B1
    TABLE_B2
    TABLE_B12let me know how I can do this
    Regards

    Hi,
    Sorry, I don't see what you're trying to do.
    "Dynamic SQL" is really a mis-nomer. The number of tables and columns in a query, and their names, must be spelled out when the statement is compiled. There is nothing dynamic about it.
    In dynamic SQL, a PL/SQL procedure or another query writes all or part of query just milliseconds before it is compiled, typically using data taken from tables or supplied by a user right then.
    For example, consider this static query:
    SELECT     a.col1, a.col2, b.col1, b.col7
    FROM     table_1     a
    ,     table_2 b
    WHERE     a.col1 = b.col1;Now, say the 1 in "table_1" and the 2 in "table_2" are variables, x and y, that you will want to look up from another table every time you run this query. You can make it dynamic like this:
    sql_txt := 'SELECT  a.col1, a.col2, b.col1, b.col7 '
         || 'FROM    table_' || TO_CHAR (x) || ' a '
         || ',       table_' || TO_CHAR (y) || ' b '
         || 'WHERE   a.col_1 = b.col1';Now let's make it really interesting. Say that instead of 2 tables, and 1 join condition, you''ll have n tables and n-1 join conditions, where n has to be computed at (actually a split second before) run-time. That is, if n=4, you might need to construct a static query with 4 tables and 3 join conditions, like this:
    SELECT     a.col1, a.col2, b.col1, b.col7
    FROM     table_1     a
    ,     table_2 b
    ,     table_12 c
    ,     table_2 d
    WHERE     a.col1 = b.col1
    AND     a.col1 = c.col1
    AND     a.col1 = d.col1;You can do that using dynamic SQL, too.
    Post an example of the static query you need to build, and describe what parts of it are dynamic, and how you get the values for those parts, and someone will help you write the dynamic SQL.

  • Rewrite the static query to dynamic SQL

    Can any one please help me to write a dynamic query within a pl/sql for the following SQL??
    This is for the set ('25','04'). the number of list could be n .
    The column_type ranges from(1..6) and
    the column_amt1 ranges from(1..6)
    SELECT t.claim_no, t.cert_no, t.rec_code,
    (NVL(decode(t.column_type1,'25',NVL (t.column_amt1, 0)),0)+
        NVL(decode(t.column_type1,'04',NVL(t.column_amt1, 0)),0 )
      +
       (NVL(decode(t.column_type2,'25',NVL (t.column_amt2, 0)),0)+
        NVL(decode(t.column_type2,'04',NVL(t.column_amt2, 0)),0 )
      +
       (NVL(decode(t.column_type3,'25',NVL (t.column_amt3, 0)),0)+
        NVL(decode(t.column_type3,'04',NVL(t.column_amt3, 0)),0 )
      +
       (NVL(decode(t.column_type4,'25',NVL (t.column_amt4, 0)),0)+ 
         NVL(decode(t.column_type4,'04',NVL(t.column_amt4, 0)),0 )
      +
         (NVL(decode(t.column_type5,'25',NVL (t.column_amt5, 0)),0)+ 
          NVL(decode(t.column_type5,'04',NVL(t.column_amt5, 0)),0 )
      +
          (NVL(decode(t.column_type6,'25',NVL (t.column_amt6, 0)),0)+ 
           NVL(decode(t.column_type6,'04',NVL(t.column_amt6, 0)),0 )) amt from test_detail t;
       Thanks in Advance
    Hena

    user11253970 wrote:
    This is the part of a procedure.NowThe query is only for type '25' and '04' .It could be more in numbers in future.So I want to maintain a dynamic sql irrespective of the number of types I use.Then first thing you must do is rename column case since it is PL/SQL reserved word (I renamed it to case_id). Then you could create a couple of SQL types and a pipelined function:
    CREATE OR REPLACE
      TYPE test_detail_copay_obj
        AS
          OBJECT(
                 case_id char(10),
                 item    char(9),
                 code    char(2),
                 copay   number(10,2)
    CREATE OR REPLACE
      TYPE test_detail_copay_tbl
        AS
          TABLE OF test_detail_copay_obj
    CREATE OR REPLACE
      FUNCTION test_detail_copay(p_type_list varchar2)
        RETURN test_detail_copay_tbl
        PIPELINED
        IS
            v_cur sys_refcursor;
            v_copay_obj test_detail_copay_obj;
        BEGIN
            OPEN v_cur FOR 'select  test_detail_copay_obj(case_id,
                                                          item,
                                                          code,
                                                          case
                                                            when type1 in (' || p_type_list || ') then nvl(amt1,0)
                                                            else 0
                                                          end +
                                                          case
                                                            when type2 in (' || p_type_list || ') then nvl(amt2,0)
                                                            else 0
                                                          end +
                                                          case
                                                            when type3 in (' || p_type_list || ') then nvl(amt3,0)
                                                            else 0
                                                          end +
                                                          case
                                                            when type4 in (' || p_type_list || ') then nvl(amt4,0)
                                                            else 0
                                                          end +
                                                          case
                                                            when type5 in (' || p_type_list || ') then nvl(amt5,0)
                                                            else 0
                                                          end +
                                                          case
                                                            when type6 in (' || p_type_list || ') then nvl(amt6,0)
                                                            else 0
                                                          end
                              from  test_detail';
            LOOP
              FETCH  v_cur
                INTO v_copay_obj;
              EXIT WHEN v_cur%notfound;
              PIPE ROW(v_copay_obj);
            END LOOP;
            RETURN;
    END;
    /Now:
    SQL> select  *
      2    from  table(test_detail_copay('''25'',''04'''))
      3  /
    CASE_ID    ITEM      CO      COPAY
    EML3371015 133761570 10        355
    EML3371015 133761570 10         20
    EML3371015 133761570 10          5
    EMC6369600 140328551 10         54
    EMH6353995 140328551 11      26.04
    SQL> select  *
      2    from  table(test_detail_copay('''25'''))
      3  /
    CASE_ID    ITEM      CO      COPAY
    EML3371015 133761570 10        300
    EML3371015 133761570 10         20
    EML3371015 133761570 10          5
    EMC6369600 140328551 10          0
    EMH6353995 140328551 11       5.52
    SQL> SY.

  • Difference between Static SQL Query and Dynamic SQL Query.

    Hi,
    Please explain the basic difference between static and dynamic sql queries. Please explain with example.

    Static: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/static.htm
    Dynamic: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/dynamic.htm

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

  • Linked server query using Dynamic SQL

    I have a Linked server query that takes forever to run. WHen I hardcode the acct# it runs fast. However I want these acct numbers int he where clause to be generated dynamically. For eg: below is what I need:
    --Get the 11 Loans from this Table A From the FIRST QUERY
    --- Plug those loans numbers in the second query  In the WHERE Clause eg should looks like  where  ACCT in (1,2,3,5)
    DECLARE
    @sSQL varChar(MAX)
    SET @sSQL
    =
    ' SELECT
    [Loan] FROM TableA D
    EXECUTE(@sSQL)
    --2ND QUERY 
    DECLARE
    @sSQL1 varChar(MAX)
    SET @sSQL1
    ='
    SELECT Field1, 
    Field2,
    Field3,
    Field4,
    Field5
       FROM LinkedServer.Dbaname.dbo.TableB a
    where ACCT in ''('''
    +(@sSQL)
    +
    ''')'''--- This needs to look like  where  ACCT in (1,2,3,5)
    select
    @sSQL1

    Ok, so use this.. instead of your first statement.
    DECLARE @sSQL NvarChar(MAX), @output NVARCHAR(100), @ParmDefinition nvarchar(500);
    SET @ParmDefinition = N'@sqlout NVARCHAR(100) OUTPUT'
    SET @sSQL = N'SELECT DISTINCT @sqlout = STUFF((SELECT '',''+CAST(S2.loan AS VARCHAR(100))
    FROM tableA S2
    FOR XML PATH('''')), 1, 1, '''')
    FROM tableA S1'
    EXECUTE sp_executesql @sSQL, @parmdefinition, @sqlout = @output OUTPUT
    and use @output instead of @sSQL in the second statement.
    You can read about STUFF command @
    http://sqlsaga.com/sql-server/how-to-concatenate-rows-into-one-row-using-stuff/.
    Good Luck :)
    Visit www.sqlsaga.com for more t-sql code snippets or BI related how to's.

  • INTERMEDIA TEXT INDEX를 사용하는 QUERY의 TUNING

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-12
    INTERMEDIA TEXT INDEX를 사용하는 QUERY의 TUNING
    ===============================================
    Purpose
    Intermedia text를 사용하는 query의 속도를 향상시킬 수 있는 방안을
    알아보자.
    Explanation
    1. Make analyze all the table in the query
    text index를 이용하는 Query 안의 모든 Table을 analyze 해 주십시요.
    예를 들어 다음의 command를 이용할 수 있습니다.
    ANALYZE TABLE <table_name> COMPUTE STATISTICS;
    or
    ANALYZE TABLE <table_name> ESTIMATE STATISTICS 1000 ROWS;
    or
    ANALYZE TABLE <table_name> ESTIMATE STATISTICS 50 PERCENT;
    2. Using FIRST_ROWS hint
    더 좋은 response time 을 위해서 first_rows hint 를 사용해 보십시요.
    database에 기본적으로 설정된 optimizer mode는 choose mode입니다.
    이것은 전체 처리시간(throughput)을 가장 빠르게 하기 위한(all_rows mode)
    plan을 따르기 때문에 user의 입장에서는 first_rows 보다는 늦다고 느낄 수
    있습니다.
    Query에 다음과 같이 hint를 주고 performance를 확인해 보십시요.
    select /*+ FIRST_ROWS */ pk, col from ctx_tab
    where contains(txt_col, 'test', 1) > 0;
    단, first_rows hint를 이용하는 경우 자동으로 score 순서대로
    ordering 되지 않습니다. 왜냐하면 단어에 부합하는 문서를 찾는대로
    즉시 결과로 나타내 주기 때문입니다.
    3. Make sure text index is not fragmented
    insert, delete 가 많이 되는 table의 경우 index fragment를 제거해 주어야
    합니다. Index fragmentation 은 다음과 같이 확인할 수 있습니다.
    select count(*) from dr$<indexname>$i; -> A
    select count(*) from (select distinct(token_text) from dr$<indexname>$i); -> B
    위의 결과가 A/B 의 값이 3:1 보다 크면 optimize_index 를 실행해 주시는
    것이 좋습니다. 다음과 같은 command로 index optimization을 할 수 있습니다.
    alter index <index_name> rebuild online
    parameters('optimize full unlimited');
    index rebuild중에 online option을 주면 rebuild하는 중에도 계속 index를
    사용할 수 있게 됩니다. 하지만, 가능하면 사용자가 없을 때 rebuild하는 것이
    좋습니다.
    4. Check execution plan and sql trace.
    기본적인 여러 가지 작업들에도 속도가 별로 향상되지 않는다면, 직접
    sql trace를 떠서 Execution plan등을 확인해 보는 것이 필요합니다.
    예를 들어 SQL*PLUS에서 다음과 같이 sql trace를 뜹니다.
    alter session set timed_statistics=true;
    alter session set sql_trace=true;
    select ..... -> execute the query
    실행 후,
    exit
    user_dump_dest 에 지정된 directory에 trace 가 떨어지면 다음과 같은
    command로 tkprof 를 떠서 내용을 확인합니다.
    $ tkprof <tracefilename> <outputfilename> explain=username/password
    Referenc Documents
    Bulletin#10134 : SQL trace와 tkprof 사용 방법

  • 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

  • How to rename C00n generic column names in a Dynamic SQL report

    I have a an interface whereby the user can select 1 to 60 (upper limit) columns out of 90 possible columns (using a shuttle) from one table before running a report.
    To construct the SQL that will eventually execute, I'm using a "PLSQL function body returning SQL query" with dynamic SQL. The only problem is that I have to use "Generic Column Names" option to be able to compile the code and end up with c001 to c060 as the column names.
    How can I use the names of the selected columns as the report headings rather than c001, C002... etc?
    I do not know beforehand which columns, or how many columns or the order of the selected columns.
    I know Denes K has a demo called Pick Columns but I can't access his code. I have a hunch though that he may be just using conditions to hide/show the apropriate columns.
    thanks in advance
    PaulP

    Hi Paul
    I would change the Heading Type in the Report Details screen to PLSQL and use the shuttle item to return the column values. e.g.
    RETURN :p1_shuttle;
    I'm assuming the shuttle already has a colon separated list of the column headings in the correct order?
    I hope that helps
    Shunt

  • Dynamic SQL in table vauled function or CLR

    So I have a query that gives me some analysis on the values in a column, in a table.  It reurns a small data set.
    It gives me the max, min, stdev, avg and some other stats grouped by another column.
    I wanted to create a table valued function from the query, so I could do the same analysis on any numeric column, in any table.  I would just pass in the column name and the table name as paramters to my table-valued function and it would return the
    data set.  Then I could join to it and use in other queries.
    I thought I would build my query using dynamic SQL and execute it within the function, but I got an error and learn that you can not use execute in a function.
    I have never created a CLR function, would this be possible to do it this way?  This would be a decent sized step for me, but am willing to learn if possible.  Or does anyone know how to solve this problem?
    Problem: Pass column name and table name into function and have it reurn a dataset.  Use the dataset as a table in other queries, scripts or procedures like a table valued function.
    Thanks,
    Mike

    Milke
    Take a look into READ only table variable parameter
    Create a user-defined data type with a single column.
    Develop a procedure with a table variable as an input parameter.
    Declare a table variable of the type of the user defined data type.
    Loading 10 records into the table variable and pass the table 
    variable to the stored procedure.
    create type tt_example AS TABLE
     (spid int)
    go
    create procedure usp_example
     @spids tt_example READONLY
    AS
     SELECT *
     FROM @spids
    GO
    declare @spids tt_example
    insert into @spids
    select top 10 spid
    from sys.sysprocesses
    exec usp_example @spids=@spids
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Dynamic SQL - Inner Join

    I just starting to Learn and use Dynamic SQL. 
    I am trying use a inner join query in dynamic SQL 
    for Example say 'Select A.id as Itemid , A.name as Itemname from TableA A inner join TableB B On A.ID = B.ID where B.ID typeid = 1 '
    for some reason this is not working . i for sure know the query works as when i run the query it works fine. when i try to run it dynamically it give me blank values.
    Please let me know if you need more information.
    Appreicate Your help!!
    Thanks,
    Chaitanya 

    Here is an example for dynamic SQL from BOL:
    DECLARE @IntVariable int;
    DECLARE @SQLString nvarchar(500);
    DECLARE @ParmDefinition nvarchar(500);
    /* Build the SQL string one time.*/
    SET @SQLString =
    N'SELECT BusinessEntityID, NationalIDNumber, JobTitle, LoginID
    FROM AdventureWorks2012.HumanResources.Employee
    WHERE BusinessEntityID = @BusinessEntityID';
    SET @ParmDefinition = N'@BusinessEntityID tinyint';
    /* Execute the string with the first parameter value. */
    SET @IntVariable = 197;
    EXECUTE sp_executesql @SQLString, @ParmDefinition,
    @BusinessEntityID = @IntVariable;
    /* Execute the same string with the second parameter value. */
    SET @IntVariable = 109;
    EXECUTE sp_executesql @SQLString, @ParmDefinition,
    @BusinessEntityID = @IntVariable;
    Basically any query can be run as dynamic SQL.  However, static SQL is the first choice. Use dynamic SQL if needed.
    Dynamic SQL examples:
    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

  • Dynamic SQL within a SQL Query ?

    is there any possibility to do like this ?
    SELECT table_name, XXXXXXXX('SELECT Count(*) FROM '||table_name) tot_rows
      FROM dba_tables
    WHERE owner = 'SCOTT';or any other trick to run dynamic SQL within the SQL Query?
    Hoping....that it should be.
    Regards,
    Orapdev

    One small disadvantage: it is executing 202 SQL statements: 3 "user SQL statements" (the one above and the 2 "select count(*)..."), and 199 internal ones ...How did you get to those numbers?
    I just traced this statement and found completely different results:
    TKPROF: Release 10.2.0.3.0 - Production on Tue Jul 10 12:12:10 2007
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: diesl10r2_ora_5440.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    declare  cursor NlsParamsCursor is    SELECT * FROM
      nls_session_parameters;begin  SELECT Nvl(Lengthb(Chr(65536)),
      Nvl(Lengthb(Chr(256)), 1))    INTO :CharLength FROM dual;  for NlsRecord in
      NlsParamsCursor loop    if NlsRecord.parameter = 'NLS_DATE_LANGUAGE' then  
         :NlsDateLanguage := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_DATE_FORMAT' then      :NlsDateFormat := NlsRecord.value;    elsif
      NlsRecord.parameter = 'NLS_NUMERIC_CHARACTERS' then     
      :NlsNumericCharacters := NlsRecord.value;    elsif NlsRecord.parameter =
      'NLS_TIMESTAMP_FORMAT' then      :NlsTimeStampFormat := NlsRecord.value;   
      elsif NlsRecord.parameter = 'NLS_TIMESTAMP_TZ_FORMAT' then     
      :NlsTimeStampTZFormat := NlsRecord.value;    end if;  end loop;end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    SELECT NVL(LENGTHB(CHR(65536)), NVL(LENGTHB(CHR(256)), 1))
    FROM
    DUAL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.01       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=7 us)
    SELECT *
    FROM
    NLS_SESSION_PARAMETERS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0          17
    total        3      0.00       0.00          0          0          0          17
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
         17  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=124 us)
    select PARAMETER,VALUE
    from
    nls_session_parameters where PARAMETER in('NLS_NUMERIC_CHARACTERS',
      'NLS_DATE_FORMAT','NLS_CURRENCY')
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           3
    total        3      0.00       0.00          0          0          0           3
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          3  FIXED TABLE FULL X$NLS_PARAMETERS (cr=0 pr=0 pw=0 time=57 us)
    select to_char(9,'9C')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=2 us)
    SELECT table_name,
           DBMS_XMLGEN.getxmltype ('select count(*) c from ' || table_name).EXTRACT
                                                                    ('//text').getstringval
                                                                          () tot
      FROM dba_tables
    WHERE table_name IN ('EMP', 'DEPT') AND owner = 'SCOTT'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.01       0.02          0         48          0           2
    total        3      0.01       0.02          0         48          0           2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50 
    Rows     Row Source Operation
          2  HASH JOIN  (cr=42 pr=0 pw=0 time=2952 us)
          2   MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=1206 us)
          2    NESTED LOOPS OUTER (cr=42 pr=0 pw=0 time=478 us)
          2     NESTED LOOPS OUTER (cr=36 pr=0 pw=0 time=421 us)
          2      NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=379 us)
          2       NESTED LOOPS OUTER (cr=30 pr=0 pw=0 time=365 us)
          2        NESTED LOOPS  (cr=22 pr=0 pw=0 time=312 us)
          2         NESTED LOOPS  (cr=16 pr=0 pw=0 time=272 us)
          2          NESTED LOOPS  (cr=8 pr=0 pw=0 time=172 us)
          1           TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=56 us)
          1            INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=30 us)(object id 44)
          2           INLIST ITERATOR  (cr=6 pr=0 pw=0 time=111 us)
          2            TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=87 us)
          2             INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=54 us)(object id 37)
          2          TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=98 us)
          2           INDEX UNIQUE SCAN I_OBJ# (cr=4 pr=0 pw=0 time=26 us)(object id 3)
          2         TABLE ACCESS CLUSTER TS$ (cr=6 pr=0 pw=0 time=39 us)
          2          INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=13 us)(object id 7)
          2        TABLE ACCESS CLUSTER SEG$ (cr=8 pr=0 pw=0 time=37 us)
          2         INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=4 pr=0 pw=0 time=21 us)(object id 9)
          0       INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=4 us)(object id 36)
          2      TABLE ACCESS BY INDEX ROWID OBJ$ (cr=6 pr=0 pw=0 time=33 us)
          2       INDEX UNIQUE SCAN I_OBJ1 (cr=4 pr=0 pw=0 time=23 us)(object id 36)
          2     TABLE ACCESS CLUSTER USER$ (cr=6 pr=0 pw=0 time=28 us)
          2      INDEX UNIQUE SCAN I_USER# (cr=2 pr=0 pw=0 time=12 us)(object id 11)
          2    BUFFER SORT (cr=0 pr=0 pw=0 time=716 us)
          1     FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=661 us)
       1436   FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1449 us)
    select count(*) c
    from
    EMP
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT AGGREGATE (cr=1 pr=0 pw=0 time=96 us)
         14   INDEX FULL SCAN EMP_IDX (cr=1 pr=0 pw=0 time=46 us)(object id 61191)
    select metadata
    from
    kopm$  where name='DB_FDO'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          2          0           1
    total        3      0.00       0.00          0          2          0           1
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS   (recursive depth: 1)
    Rows     Row Source Operation
          1  TABLE ACCESS BY INDEX ROWID KOPM$ (cr=2 pr=0 pw=0 time=42 us)
          1   INDEX UNIQUE SCAN I_KOPM1 (cr=1 pr=0 pw=0 time=22 us)(object id 365)
    select count(*) c
    from
    DEPT
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          1          0           1
    total        4      0.00       0.00          0          1          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 50     (recursive depth: 1)
    ALTER SESSION SET sql_trace=FALSE
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Parsing user id: 50 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.00       0.00          0          0          0           1
    Fetch        3      0.01       0.02          0         48          0           6
    total       13      0.01       0.03          0         48          0           7
    Misses in library cache during parse: 0
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      5      0.01       0.00          0          0          0           0
    Fetch        7      0.00       0.00          0          4          0          21
    total       17      0.01       0.00          0          4          0          21
    Misses in library cache during parse: 0
        9  user  SQL statements in session.
        1  internal SQL statements in session.
       10  SQL statements in session.
    Trace file: diesl10r2_ora_5440.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           1  session in tracefile.
           9  user  SQL statements in trace file.
           1  internal SQL statements in trace file.
          10  SQL statements in trace file.
          10  unique SQL statements in trace file.
         132  lines in trace file.
           0  elapsed seconds in trace file.I only see a ratio of 1:9 for user- to internal SQL statements?
    michaels>  select * from v$version
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production                         
    CORE     10.2.0.3.0     Production                                     
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production        
    NLSRTL Version 10.2.0.3.0 - Production  

  • Build stored procedure from a dynamic SQL query

    I have the following method, that receives a string from a textbox and creates a dynamic select command. Since I am using a dataSet I cannot execute a dynamic SQL query by calling a method of a strongly-typed dataset (.xsd). I have been told that the best
    way to do this is to pass an array of values to the stored procedure.
    But I have no clue how to build the stored procedure.
    string[] allWords = txtSearch.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    string sql = "SELECT Books.ISBN, Books.Title, Books.Tag, Books.Image, Books.photoType, Publishers.Name AS publisherName FROM Books INNER JOIN Publishers ON Books.codPublisher = Publishers.codPublisher WHERE ";
    using (SqlCommand command = new SqlCommand())
    for (int i = 0; i < allWords.Length; ++i)
    if (i > 0)
    sql += "OR ";
    string paramName = "@param" + i.ToString();
    sql += string.Format("(Books.Title LIKE {0}) ", paramName);
    command.Parameters.AddWithValue(paramName, allWords[i] + "%");
    command.CommandText = sql;
    //execute the SQL query against the db...

    After hours around this, I have came with this solution.
    private SqlConnection sqlConn = new SqlConnection();
    private System.Data.DataSet dataSet = new System.Data.DataSet();
    private System.Data.DataTable dataTable;
    private System.Data.DataRow dataRow;
    private SqlCommand search(string searchParam, int searchOption)
    SqlCommand command = new SqlCommand();
    string sql;
    string[] allWords = searchParam.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    if (searchOption == 1)
    sql = "SELECT Livros.ISBN, Livros.Titulo, Livros.Tema, Livros.Resumo, Livros.Imagem, Livros.fotoTipo, Editoras.Nome AS nomeEditora FROM Livros INNER JOIN Editoras ON Livros.codEditora = Editoras.codEditora WHERE ";
    else
    sql = "SELECT Livros.ISBN, Livros.Titulo, Livros.Tema, Livros.Resumo, Livros.Imagem, Livros.fotoTipo, Editoras.Nome AS nomeEditora FROM Livros INNER JOIN livrosAutores ON Livros.ISBN = livrosAutores.ISBN INNER JOIN Autores ON livrosAutores.idAutor = Autores.idAutor INNER JOIN Editoras ON Livros.codEditora = Editoras.codEditora WHERE ";
    using (command)
    for (int i = 0; i < allWords.Length; ++i)
    if (i > 0)
    sql += "OR ";
    if (searchOption == 1)
    sql += string.Format("(Livros.Titulo LIKE '%{0}%') ", allWords[i]);
    else
    sql += string.Format("(Livros.Autor LIKE '%{0}%') ", allWords[i]);
    command.CommandText = sql;
    return command;
    protected void Bind()
    sqlConn.ConnectionString = Properties.Settings.Default.BibliotecaConnectionString;
    string connectionString = sqlConn.ConnectionString.ToString();
    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(search(searchText, searchOption).CommandText, connectionString);
    sqlDataAdapter.Fill(dataSet, "livrosTitulo");
    dataTable = dataSet.Tables["livrosTitulo"];
    dataGrid.DataContext = dataTable.DefaultView;

  • Dynamic SQL Query count

    Hi,
    I need to retieve the number of records that will be retrieved by a query as follows.
    How can this be done?
    Is there a method to do it using native dynamic sql (open .. for .. using ) instead of DBMS_SQL (Because Native is faster than dbms_SQL )?
    The following block demostrates what I need to do where v_query will hold the query text.
    declare
    v_query varchar2(32000);
    v_count number;
    begin
    select query_text into v_query from groups_table where id =1;
    dbms_output.put_line('count = '||v_count);
    end;
    Thanks in Advance

    Is there a way to use sql%rowcount to do something similar?
    Afraid not
    I mean if there is a way to get better performance in case of very large query. Like for example in oracle forms, when using Query --> count records it retrieves the nubmer of records that will be fetched.
    I think you'll find forms simply does a select count(*) from the base table (adding and predicates where necessary).
    What are you going to use it for? Maybe there is an alternative route you can take...

  • Need generic dynamic sql query to generate nodes depending on dealer levels

    Input table:
    create table #test(dealerid integer ,dealerlvl integer)
    insert into #test values(1,1)
    insert into #test values(1,2)
    insert into #test values(1,3)
    insert into #test values(1,4)
    insert into #test values(2,1)
    insert into #test values(2,2)
    insert into #test values(2,3)
    insert into #test values(2,4)
    insert into #test values(2,5)
    insert into #test values(2,6)
    go
    create table #test2(dealerid integer,node integer,prntnode integer,dealerlvl integer)
    insert into #test2 values (1,234,124,2)
    insert into #test2 values (1,123,234,1)
    insert into #test2 values (1,238,123,2)
    insert into #test2 values (1,235,238,3)
    insert into #test2 values (1,253,235,4)
    insert into #test2 values (2,21674,124,3)
    insert into #test2 values (2,1233,21674,1)
    insert into #test2 values (2,2144,1233,2)
    insert into #test2 values (2,2354,2144,3)
    insert into #test2 values (2,24353,2354,4)
    insert into #test2 values (2,245213,24353,5)
    insert into #test2 values (2,2213,245213,6)
    Expected result :
    I have two test case here with dealerID1 and dealerID 2 
    Result for DealerID1
    Result needed for DealerID2:
    the levels for dealers might change (Dealer1 has 4 levels, and Dealer 2 has 6 levels) so i need to create an dynamic sql query which lists each node as separate columns depending on the levels. 
    I have hacked the query to give the result I need 
    select a.dealerid,a.node as Lvl1,b.node as lvl2,c.node as lvl3,d.node as lvl4
    from #test2 a 
    join #test2 b on a.node=b.prntnode
    join #test2 c on b.node=c.prntnode
    join #test2 d on c.node=d.prntnode
    where a.dealerid=1 and a.dealerlvl=2
    select  a.dealerid,a.node asLvl1,
    b.node as lvl2,c.node as lvl3,d.node as lvl4,e.node as lvl5,f.node as lvl6--,a.dealerlvl,a.dealerid
    from #test2 a 
    join #test2 b on a.node=b.prntnode
    join #test2 c on b.node=c.prntnode
    join #test2 d on c.node=d.prntnode
    join #test2 e on d.node=e.prntnode
    join #test2 f on e.node=f.prntnode
    where a.dealerid=2 and a.dealerlvl=3
    I am sure there is a better way to do this with dynamic sql. please help.
    Thanks

    -- Dynamic PIVOT
     DECLARE @T AS TABLE(y INT NOT NULL PRIMARY KEY);
    DECLARE
       @cols AS NVARCHAR(MAX),
       @y    AS INT,
       @sql  AS NVARCHAR(MAX);
    -- Construct the column list for the IN clause
     SET @cols = STUFF(
       (SELECT N',' + QUOTENAME(y) AS [text()]
        FROM (SELECT DISTINCT dealerlvl AS y FROM dbo.test2) AS Y
        ORDER BY y
        FOR XML PATH('')),
       1, 1, N'');
    -- Construct the full T-SQL statement
     -- and execute dynamically
     SET @sql = N'SELECT *
     FROM (SELECT dealerid, dealerlvl, node
           FROM dbo.Test2) AS D
       PIVOT(MAX(node) FOR dealerlvl IN(' + @cols + N')) AS P;';
    EXEC sp_executesql @sql;
     GO

Maybe you are looking for

  • Content tab for a fact table

    Hi Please , help me in knowing the use of content tab for a fact table in the repository in OBIEE. Thanks.

  • Sales Comparison by Items Report

    Hello Experts, Is there a report in B1 that compares total sales by item between two periods? If not, could anyone help me with a query? For Example:  Total sales for item A0001 between Jan-Oct 2010 is $10000 and Total sales for item A0001 between Ja

  • Updating Item Description in Lead Change Badi(ORD..ADM_I  and ORDERSAVE)

    Hi I have to update Item(Product/Product category) Description in Lead duriing Creat/Change. 1..I can't do same in CRM_ORDERADM_I_BADI as Ited Guid is geting created after coming out of this Badi... 2..Also in ORDER_SAVE BadI~CHANGE_BEFORE_UPDATE doe

  • Opening PDFs

    Recently I posted the question under How do I make sure that my pdf doc opens in Acrobat X so that I can play with it. At the moment when I open one of my pdf docs ( ones I have just created) it opens in Reader so I am unable to access such things as

  • HT1338 I clicked update since yesterday but the system refused to update

    I clicked update since yesterday but the system refused to update. The massage I got is: (Use of this software is subject to the original software License Agreements that accompanied the software being updated) Now what can I do to stop/terminate the