Sql  query  not suporing group by

hi expert all  ,
i want  to  use  group by in this query  but it is not suporting.
SELECT DISTINCT
T0.DocEntry,
(SELECT DISTINCT ISNULL(SUM(BaseSum), 0)
FROM          dbo.INV4
WHERE      (staType = 1) AND (DocEntry = T0.DocEntry) AND (LineNum = T1.LineNum))as value1
FROM         dbo.OINV AS T0 INNER JOIN
                      dbo.INV1 AS T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
                      dbo.INV4 AS T3 ON T1.DocEntry = T3.DocEntry
WHERE     (T3.StaCode LIKE '%vat%4%')
the result  is
doc entry   value
45              100
46                 80
  46                70
  47                100
  47                  90
but i want to show 
doc entry   value
45              100
46               150
  47                190
please help me.

Hi,
Try this:
SELECT T0.DocEntry,SUM(T3.BaseSum) as 'Value1'
FROM dbo.OINV T0 INNER JOIN
dbo.INV4 T3 ON T0.DocEntry = T3.DocEntry
AND T3.staType = 1 AND T3.StaCode LIKE '%vat%4%'
GROUP BY T0.DocEntry
ORDER BY SUM(T3.BaseSum) DESC
Thanks,
Gordon

Similar Messages

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • SQL query not calculating

    SQL query not calculating
    gross_amount is giving the value of extended_amount and the gross_price_rc is giving the value of unit_selling_price
    select customer_trx_line_id,
    ( extended_amount / 1- (decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) GROSS_AMOUNT,
    ( unit_selling_price /1-(decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) gross_price_rc
    from ra_customer_trx_lines_all
    where attribute6 is not null or attribute7 is not null or attribute8 is not null or attribute9 is not null
    whats the isuue here??
    Thanks

    decode(attribute7,null,0)Looking at it again, this always returns 0 or NULL, so it not really surprising
    DECODE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions040.htm#i1017437
    CASE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions004.htm#i1033392

  • SQL Query Not working

    Hi All,
    Please help with the error ORA-00923: FROM keyword not found where expected.
    I am trying to execute the following SQL query.
    SELECT
    CASE
    WHEN (Grouping("PRICECATEGORY"."PriceCategoryName")=1) THEN "PriceCatTotal"
    ELSE "PRICECATEGORY"."PriceCategoryName"
    END AS "PRICECATEGORY"."PriceCategoryName",
    CASE
    WHEN (Grouping("LINEITEM"."LineDescription")=1) THEN "LineTotal"
    ELSE "LINEITEM"."LineDescription"
    END AS "LINEITEM"."LineDescription" ,
    *"INVOICE"."InvoiceDate",*
    Sum("TRANSACTION"."TotalPrice") as "TotalPrice",
    Sum("INVOICE_CHILD"."QUANTITY") as "Quantity"
    FROM "LINEITEM","INVOICE","TRANSACTION","PRICECATEGORY", "INVOICE_CHILD"
    WHERE "TRANSACTION"."InvoiceID"="INVOICE"."InvoiceNumber"
    and      "TRANSACTION"."PriceCategoryID"="PRICECATEGORY"."PriceCategoryID"
    and      "INVOICE_CHILD"."INVOICEID"="INVOICE"."InvoiceID"
    and      "PRICECATEGORY"."PriceCategoryID"="TRANSACTION"."PriceCategoryID"
    and      "TRANSACTION"."PriceCategoryID"="PRICECATEGORY"."PriceCategoryID"
    and      "PRICECATEGORY"."PriceCategoryID"="TRANSACTION"."PriceCategoryID"
    and      "LINEITEM"."LINEITEMID"="TRANSACTION"."LineItemID"
    and      "LINEITEM"."PRICECATEGORYID"="PRICECATEGORY"."PriceCategoryID"
    and     "INVOICE"."InvoiceDate" >= :STARTDATE and "INVOICE"."InvoiceDate" <= to_date(:ENDDATE,'DD-MON-YY')+1
    GROUP BY "PRICECATEGORY"."PriceCategoryName", "LINEITEM"."LineDescription" WITH ROLLUP
    I am using a from keyword at the right place and all the aliases are properly used.
    Please advice.
    Regards,
    Sandeep Reddy

    Jaydip and Jeff are correct:
    <li>Jaydip points out that <tt>"PRICECATEGORY"."PriceCategoryName"</tt> and <tt>"LINEITEM"."LineDescription"</tt> are not valid column alias names. They must be unqualified, nonquoted/quoted identifiers.
    <li>Jeff indicates that <tt>WITH ROLLUP</tt> is not Oracle SQL syntax, and provides a sample of the required ROLLUP/CUBE clauseOracle SQL <tt>ROLLUP/CUBE clause</tt>.
    Additionally, <tt>TRANSACTION</tt> is an Oracle keyword and therefore a poor choice as a database identifier: change the name of this table as soon as possible.
    You're having this problem because not all "SQL" is created equal. Your OdeToCode source appears to be a site dealing with Microsoft technologies (SQL Server in this case). Unless you are very familiar with Oracle and SQL Server and the inherent differences between them you'd be advised to stick to purely Oracle resources (I know I do). There are plenty of good Oracle resources out there.
    You'll also find it a lot easier to write, read and spot problems in SQL and PL/SQL code if you avoid using quoted identifiers (please tell us the database objects don't have case-sensitive names?) and use short table aliases rather than full table names. And we'll find it easier to help you on this forum if you post code samples wrapped in \...\wrapped in <tt>\...\</tt> tags.

  • ORA-00904 ON A PLSQL QUERY RETURNING SQL QUERY ( NOT ALWAYS )

    Running a classic report , we sometimes face the error :
    <pre>failed to parse SQL query:
    ORA-00904: : invalid identifier
    Even when using the same parameters, sometimes the report runs and some others we get the error.
    The report is called by a url from a different page
    f?p=&APP_ID.:500:&APP_SESSION.:FLOW_EXCEL_OUTPUT_R&P503_RUN_REGION_ID._el:NO::P500_RUN_RG,P500_RG11_FILTER1:1,&P503_FILTER1.
    THE EVNVIRONMENT IS THE FOLLOWING
    ORACLE DATABASE 11g      Enterprise Edition Release 11.2.0.2.0 -64bit
    Apex                     Application Express 4.1.0.00.32
    In the apex on the same workspace we have 2 copies of the same application having different schema.
    We did not face this problem in Oracle 10g

    hello,
    I send you the function. rs_check_limit .
    In one case when i tried to debug in order to understand the error, the function was not fired.
    FUNCTION rs_check_limit ( p_trade_date_from date
    , p_trade_date_to date, p_session_id number , p_user_id varchar2
    , p_pct_sum_prcp_cd number
    ,p_rs_list_exclude varchar2 default ' '
    return rs_check_limit_tb PIPELINED
    is
    v_data rs_check_limit_tp :=rs_check_limit_tp ( null, null,null, null,null, null,null, null,null, null );
    CURSOR exec_trades_prcp_cur (vc_risk_date_from date
    , vc_risk_date_to date
    , vc_rs_list_exclude varchar2
    is
    select PRCP_CD
    , clr_sys_cd
    , clr_acc_cd
    ,avg( exec_trades_value_mkt ) avg_exec_trades_prcp
    ,SUM( exec_trades_value_mkt ) sum_exec_trades_prcp
    from
    select trd_dt, PRCP_CD , clr_sys_cd
    , clr_acc_cd , sum ( exec_trades_value_mkt ) exec_trades_value_mkt
    from
    select lst_cmpt_dt trd_dt , PRCP_CD , clr_sys_cd
    , clr_acc_cd
    ,SUM (BUYS_VALUE+ SELLS_VALUE) exec_trades_value_mkt
    from rs_mm_rsk_lmts_dtls
    where 1=1
    and lst_cmpt_dt > vc_risk_date_from -1
    and lst_cmpt_dt <= vc_risk_date_to
    and instr( vc_rs_list_exclude, TRIM(clr_acc_cd)|| '.')= 0
    group by lst_cmpt_dt , PRCP_CD , clr_sys_cd
    , clr_acc_cd
    UNION ALL
    select trunc ( apx_rs_risk_info.get_d_n_cur (lst_cmpt_dt,- 1) ) trd_dt , PRCP_CD , clr_sys_cd
    , clr_acc_cd, SUM (BUYS_VALUE+ SELLS_VALUE) exec_trades_value_mkt
    from rs_mm_rsk_lmts_dtls
    where trd_dt = apx_rs_risk_info.get_d_n_cur ( lst_cmpt_dt , 2 )
    and lst_cmpt_dt > apx_rs_risk_info.get_d_n_cur (vc_risk_date_from ,1 )-1
    and lst_cmpt_dt < vc_risk_date_to
    and instr( vc_rs_list_exclude, TRIM(clr_acc_cd)|| '.')= 0
    group by apx_rs_risk_info.get_d_n_cur (lst_cmpt_dt , -1 ) ,PRCP_CD , clr_sys_cd
    , clr_acc_cd
    group by trd_dt, PRCP_CD , clr_sys_cd
    , clr_acc_cd
    group by PRCP_CD , clr_sys_cd
    , clr_acc_cd
    CURSOR exec_trades_all_cur (vc_risk_date_from date
    , vc_risk_date_to date
    , vc_rs_list_exclude varchar2)
    is
    select SUM( exec_trades_value_mkt ) sum_exec_trades_all -- óõíïëéêÞ çìåñÞóéá áîßá óõíáëëáãùí áãïñÜò
    , avg( exec_trades_value_mkt ) avg_exec_trades_all
    from
    select trd_dt, sum( exec_trades_value_mkt ) exec_trades_value_mkt
    from
    --gia  T : T, T-1 ,  T-2
    select lst_cmpt_dt trd_dt , SUM (BUYS_VALUE+ SELLS_VALUE) exec_trades_value_mkt
    from rs_mm_rsk_lmts_dtls
    where 1=1
    and lst_cmpt_dt > vc_risk_date_from -1
    and lst_cmpt_dt <= vc_risk_date_to
    and instr( vc_rs_list_exclude, TRIM(clr_acc_cd)|| '.')= 0
    group by lst_cmpt_dt
    union all
    --gia  T EPIPLEON: T-3
    select apx_rs_risk_info.get_d_n_cur (lst_cmpt_dt,-1) trd_dt , SUM (BUYS_VALUE+ SELLS_VALUE) exec_trades_value_mkt
    from rs_mm_rsk_lmts_dtls
    where trd_dt = apx_rs_risk_info.get_d_n_cur ( trunc ( lst_cmpt_dt ) , +2 )
    and lst_cmpt_dt > apx_rs_risk_info.get_d_n_cur (vc_risk_date_from ,1 )-1
    and lst_cmpt_dt < vc_risk_date_to
    and instr( vc_rs_list_exclude, TRIM(clr_acc_cd)|| '.')= 0
    group by apx_rs_risk_info.get_d_n_cur (lst_cmpt_dt , -1 )
    group by trd_dt
    exec_trades_prcp_row exec_trades_prcp_cur%rowtype;
    exec_trades_all_row exec_trades_all_cur%rowtype;
    i number := 0;
    tmp varchar2(4) := null;
    procedure feed_table is
    BEGIN
    v_data.prcp_cd := exec_trades_prcp_row.prcp_cd;
    v_data.clr_sys_cd := exec_trades_prcp_row.clr_sys_cd;
    v_data.clr_acc_cd := trim(exec_trades_prcp_row.clr_acc_cd);
    v_data.member_id := RS_GET_PRCP_MEMBER_ID(exec_trades_prcp_row.prcp_cd);
    v_data.member_dsc := RS_GET_PRCP_DSC(exec_trades_prcp_row.prcp_cd);
    v_data.sumTRADES_VALUE_PRCP_CD_T := round( exec_trades_prcp_row.sum_exec_trades_prcp,2);
    v_data.mkt_sumTRADES_VALUE_PRCP_CD_T := round( exec_trades_all_row.sum_exec_trades_all,2) ;
    v_data.avgTRADES_VALUE_PRCP_CD_T := round( exec_trades_prcp_row.avg_exec_trades_prcp,2);
    v_data.mkt_avgTRADES_VALUE_PRCP_CD_T := round( exec_trades_all_row.avg_exec_trades_all,2) ;
    v_data.pct_sum_prcp_cd := round( 100* exec_trades_prcp_row.sum_exec_trades_prcp
    / exec_trades_all_row.sum_exec_trades_all , 2);
    end ;
    begin
    exec_trades_all_row := null;
    open exec_trades_all_cur (vc_risk_date_from => p_trade_date_from
    , vc_risk_date_to => p_trade_date_to
    ,vc_rs_list_exclude => NVL(p_rs_list_exclude ,'.' )
    fetch exec_trades_all_cur INTO exec_trades_all_row;
    close exec_trades_all_cur;
    for exec_trades_prcp_rec in exec_trades_prcp_cur (vc_risk_date_from => p_trade_date_from
    , vc_risk_date_to => p_trade_date_to
    ,vc_rs_list_exclude => NVL(p_rs_list_exclude ,'.' )
    loop
    exec_trades_prcp_row := exec_trades_prcp_rec;
    if exec_trades_all_row.sum_exec_trades_all <> 0 then
    if 100* exec_trades_prcp_row.sum_exec_trades_prcp
    / exec_trades_all_row.sum_exec_trades_all >= p_pct_sum_prcp_cd then
    i := i+1;
    v_data :=rs_check_limit_tp ( null, null,null, null,null, null,null, null,null, null );
    feed_table;
    pipe row ( v_data );
    end if;
    end if;
    end loop;
    end;
    I send you the dll for the type
    CREATE OR REPLACE
    TYPE rs_check_limit_tp as object
    prcp_cd varchar2(10)
    , member_id varchar2(4)
    , member_dsc varchar2(120)
    , clr_sys_cd varchar2(4)
    , clr_acc_cd varchar2(6)
    , avgTRADES_VALUE_PRCP_CD_T number
    , mkt_avgTRADES_VALUE_PRCP_CD_T number
    , sumTRADES_VALUE_PRCP_CD_T number
    , mkt_sumTRADES_VALUE_PRCP_CD_T number
    , pct_sum_prcp_cd number
    and the table dll
    CREATE TABLE rs_mm_rsk_lmts_dtls
    (trd_dt DATE NOT NULL,
    prcp_cd VARCHAR2(10 BYTE) NOT NULL,
    clr_sys_cd CHAR(4 BYTE),
    clr_acc_cd CHAR(10 BYTE),
    sec_isin_cd VARCHAR2(12 BYTE) NOT NULL,
    buys NUMBER(19,0),
    sells NUMBER(19,0),
    buys_value NUMBER(19,6),
    sells_value NUMBER(19,6),
    abs_b_minus_s NUMBER(19,2),
    rsk_prc NUMBER(13,6),
    net_value NUMBER(19,2) NOT NULL,
    sr NUMBER(19,2) NOT NULL,
    mm NUMBER(19,2) NOT NULL,
    lst_cmpt_dt DATE,
    usr_id VARCHAR2(8 BYTE) NOT NULL,
    cmt VARCHAR2(64 BYTE),
    chg_dt DATE,
    gr_b NUMBER(19,2) NOT NULL,
    gr_s NUMBER(19,2) NOT NULL)
    Thank you
    Tonia

  • Inline transform for Sql Query not working in SAP MII 12.1 Version 12.1.8 B

    Hi All,
    I applied an xslt for an sql query which returns an xml file.
    I used inline transform icon in sql query to load an xsl file which has to return me a string
    Any idea why is not working for me..?
    My Sample XML file:
                                     <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="/XMII/CM/BatchDisposition/BatchQueueManagement/StyleSheets/ProductXsl.xsl"?>
    <Rowsets DateCreated="2011-05-05T07:27:45" EndDate="2011-05-05T07:27:45" StartDate="2011-05-05T06:27:45" Version="12.1.8 Build(20)">
         <Rowset>
              <Columns>
                   <Column Description="ProductName" MaxRange="1" MinRange="0" Name="ProductName" SQLDataType="12" SourceColumn="ProductName"/>
              </Columns>
              <Row>
                   <ProductName>Asprin 100mg Tablets 12 x10 strip</ProductName>
              </Row>
              <Row>
                   <ProductName>Asprin 300mg Tablets 12 x10 strip</ProductName>
              </Row>
              <Row><ProductName>Ibprooven 200mg Tablets 12 x 10 strip</ProductName></Row>
              <Row><ProductName>RipTide 50mg Tablets 40 x10 strip</ProductName></Row>
              <Row><ProductName>Seroquel 200mg Tablets 6 x10 strip</ProductName></Row>
              <Row><ProductName>Seroquel 400mg Tablets 12 x10 strip</ProductName></Row>
         </Rowset>
    </Rowsets>
    My Sample XSl File:
                                    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
         <xsl:text>["</xsl:text>
         <xsl:for-each select="Rowsets/Rowset/Row">
              <xsl:value-of select="ProductName"/>
              <xsl:if test="position() &lt; last()">
                   <xsl:text>","</xsl:text>
                    </xsl:if>
              <xsl:if test="position()=last()">
                           <xsl:text>"]</xsl:text>
                    </xsl:if>
         </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Any Suggestions  are Welcome:
    Thanks

    Something like this should work...
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:template match="/">
              <Rowsets DateCreated="{Rowsets/@DateCreated}" Version="{Rowsets/@Version}" StartDate="{Rowsets/@StartDate}" EndDate="{Rowsets/@EndDate}">
                   <xsl:copy-of select="/Rowsets/FatalError"/>
                   <xsl:copy-of select="/Rowsets/Messages"/>
                   <Rowset>
                   <Columns>
                        <Column Description="Mycol1" MaxRange="1" MinRange="0" Name="Mycol1" SQLDataType="12" SourceColumn="Mycol1" />
                   </Columns>
                   <Row>
                   <Mycol1>
                   <xsl:text>["</xsl:text>
                        <xsl:for-each select="/Rowsets/Rowset/Row">
                             <xsl:value-of select="." />
                             <xsl:choose>
                                  <xsl:when test="position() &lt; last()"><xsl:text>","</xsl:text></xsl:when>
                                  <xsl:otherwise><xsl:text>"]</xsl:text></xsl:otherwise>
                             </xsl:choose>
                        </xsl:for-each>
                   </Mycol1>
                   </Row>
                   </Rowset>
              </Rowsets>
         </xsl:template>
    </xsl:stylesheet>

  • Sql query not execute

    Hi Forum
    i made an application which run on JRun server.
    In many of my jsps i used sql query like this:
    " select id, name, rollno from student where add = 'jj';"
    and retrieve the record from resultset like this:
    rs.getString("id");
    rs.getString("name");
    rs.getString("rollno");
    I got no error.
    BUT WHEN I RETRIEVE THE RECORDS LIKE THIS
    rs.getString("name");
    rs.getString("id");
    rs.getString("rollno");
    i got the error:
    java.sql.SQLException: [Oracle][ODBC]Invalid column number <1>.
    I can not understand what is the problem ?
    all the datatypes are correct.
    all coding is correct.
    and everything is correct.
    pls help me & suggest a solution.
    is there any problem of jdbc API OR of JRUN SERVER SETTINGS?
    thanks
    mail me at [email protected]
    Arvind Goel

    I would advise against ever using SELECT * - the order of the columns is undetermined so you're bound to hit this problem sooner or later. Besides, it assumes the column names and you know what happens when you assume things...
    I would recommend retrieving only the columns you need, in the order you want them and to call ResultSet.getXXX for each of the columns, in order.

  • Using Parameters in SQL-Query not only in where clauses

    Hi,
    I try to use Publisher parameters in the SQL Query from a Data Set.
    All of them have default values.
    So far, this is no problem, unless I try to use such a parameter value as an ordinary attribute value:
    >
    select
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."BETR_TEIL"
                                            else :pv_some_Text end                                                                  as Betr_Teil,
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM"
                                            else :pv_some_Text end                                                        as Suva_Nr,
         case when (:pv_Group = 'no') then "DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH"
                                            else sum("DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") end      as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in (:pv_nim100)
         fetch first 65001 rows ONLY
    >
    The parameters 'pv_Group' and 'pv_nim100' are working fine. (when or where clauses)
    The parameter 'pv_some_Text' unfortunately not. (simple literals)
    When I try to validate the above SQL, I get the following Error:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46033] Datatype: 25 is not supported.
    </font>
    After use a cast function:
    >
    else CAST(:pv_some_Text AS CHARACTER)
    >
    I get this ERROR:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 19002] Incorrect use of parameters. The parameters used in CAST cannot be resolved without ambiguity.
    </font>
    We use OBIEE 11.1.1.6.4 on a Win64-System.
    Thank's for any help.

    Hi Alex,
    let's leave away any unnecessary details.
    This is the SQL, inserted in the window 'Edit Data Set' of BIP Data Model:
    >
    select
         '--1'     as Betr_Teil,
         '--2'      as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    Everything is fine when I click OK, the script goes back to the metadata.
    Let's try this script with bind values in ORACLE SQL Developer.
    This SQL is the physical part, found in the OBIEE-Log (Log level 5), except the bind values. Therefore we find, in the where clause, the join. In the logical sql, we don't have to join, because it's handled in the Common Enterprise Information Model (CEIM)
    >
    with
    sawith0 as
    select
    sum(t39617.ris_vollbesch) as c1
    from
    dm15d_betriebsteil t39455,
    dm15k_ris_fakten_pro_btt_jhr t39617
    where
    t39455.id_betriebsteil = t39617.id_betriebsteil
    and t39455.suva_nr_form = '122-4.4'
    select
    d1.c1 as c1,
    d1.c2 as c2,
    d1.c3 as c3
    from
    select
    :pv_some_text as c1,
    :pv_some_text as c2,
    sum(d1.c1) as c3
    from
    sawith0 d1
    d1
    where
    rownum <= 65001
    >
    This SQL works fine, even with bind values for 'pv_some_text'.
    But, when using the following SQL in the BIP Data Model:
    >
    select
         :pv_Text as Betr_Teil,
         :pv_Text as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    The following ERROR occurs:
    <font color="red">java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46008] Internal error: File server\Query\Optimizer\ServiceInterfaceMgr\Utility\Src\SQOIUTypeVisitor.cpp, line 643.</font>
    In my opinion, either I use a wrong syntax, or BIP has a problem with parsing the script.
    Thank you for your most welcome help.

  • Sql query not executed using recordset

    Hi All,
    I am trying to first format and then execute SQL query statement using recordset object with DI API. the issue is with vb.net's string formatting. I want to use 'USE [DB_Name]' statement in SQL and then 'Alter Procedure ..' statement. as this has to be the first statement in sql , I am using 'GO' in between and seperating each sentence with following syntax.
      Dim AltProc  as string
      AltProc = " USE [DB_name]" & Environment.NewLine
      AltProc = AltProc & " GO " &  Environment.NewLine
      AltProc = AltProc & " ALTER proc [proc_name] " &  Environment.NewLine
    '---------------------and so on
    Orec.DoQuery(AltProc)
    this formatting does not recognize new line and gives 'incorrect syntax near 'Go'' error.  strange thing is, if I take this query in SQL, it runs perfectly and I can see it getting formatted with each new line created. I tried even VbcrLf but it didnt work.
    any one has any idea?
    thanks in advance,
    Binita

    HI Binita
    The reason:
    GO is the "command" delimiter of MS Query Editor.
    It is not working with RecordSet Object.
    In MS SQL 2008 version you can define the schema before the procedure name but in SQL server 2000/2005 it is not possible.
    IN SQL 2008 use the Fully Qualified name instead of GO:
    Dim AltProc  as string
      AltProc = " ALTER proc [DB_name].[dbo].[proc_name] "  + vbcrlf
    '---------------------and so on
    Orec.DoQuery(AltProc)
    it is not working on MS SQL 2008 i have tried.
    'CREATE/ALTER PROCEDURE' does not allow specifying the database name as a prefix to the object name.'
    Regards,
    J.
    Edited by: Janos  Nagy on Jun 22, 2009 2:55 PM

  • URGENT (sql query not execute)

    Hi Forum
    i made an application which run on JRun server.
    In many of my jsps i used sql query like this:
    " select id, name, rollno from student where add = 'jj';"
    and retrieve the record from resultset like this:
    rs.getString("id");
    rs.getString("name");
    rs.getString("rollno");
    I got no error.
    BUT WHEN I RETRIEVE THE RECORDS LIKE THIS
    rs.getString("name");
    rs.getString("id");
    rs.getString("rollno");
    i got the error:
    java.sql.SQLException: [Oracle][ODBC]Invalid column number <1>.
    I can not understand what is the problem ?
    all the datatypes are correct.
    all coding is correct.
    and everything is correct.
    pls help me & suggest a solution.
    is there any problem of jdbc API OR of JRUN SERVER SETTINGS?
    thanks
    mail me at [email protected]
    Arvind Goel

    " select id, name, rollno from student where add =
    'jj';"
    BUT WHEN I RETRIEVE THE RECORDS LIKE THIS
    rs.getString("name");
    rs.getString("id");
    rs.getString("rollno");
    You are retrieving the fields in a different order than what is specified in the select statement.
    Some drivers don't allow that (I don't believe it matters what version of the driver you have.)

  • SQL Query (not OMBPlus) to get Join- and Filter-Conditions

    Hallo,
    I allready used the Views ALL_IV_XFORM_... to get serveral informations on my mappings using SQL-Queries,
    but how can I retrieve the Conditions of an Join- or Filter-Transformation using SQL and not OMBPLUS?
    Thanks in advance
    Frank

    but how can I retrieve the Conditions of an Join- or Filter-Transformation using SQL and not OMBPLUS?if i understood the question correctlly then
    join will be written as
    select * from table_1 , table_2  where table_1.col1=table_2.col2;filter will be written as
    select * from table_1  where table_1.col1='A';

  • Executing sql query(not through sqlfile) from batchfile

    Hi,
    I have written a batchfile below which should execute the sql query. Can someone please help me in modifying the below code. I know we can make use of sql file ,but wanted it to be more robust and hence everything in a single batch file instead of having combination of sqlfile and batchfile.
    @echo off
    set ORACLE_HOME=%RAMBOH%
    set ORACLE_SID=%RAMBSID%
    set path=%RAMBOH%\bin;%RAMBOH%\admin\Ramb_Scripts;%path%
    sqlplus sys/XXX as sysdba
    @echo SET SERVEROUTPUT ON;
    @echo DECLARE
    @echo     v1   DATE;
    @echo BEGIN
    @echo     SELECT SYSDATE INTO V1 FROM DUAL;
    @echo     DBMS_OUTPUT.PUT_LINE(v1);
    @echo END;
    @echo /

    I used the below syntax to execute a procedure
    set ORACLE_SID=orcl
    echo exec MyProcedure;
    echo exit
    )|sqlplus system/manager >MyProcedure.log
    Try making modifications to this and see if this helps you in executing the SQL from the batch file

  • SQL Query - Max Date - Group By

    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of records
    SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
    TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
    SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
    SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
    SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
    SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
    SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
    SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
    SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
    SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
    SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
    SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
    SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
    SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
    SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM FACT_RESULT_VW a,
    PLAN_VW b,
    SUB_VW c ,
    CUST_VW d,
    FACT_TRANS e,
    WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )+
    AND a.PP_KEY = b.PP_key
    AND a.ID = c.ID
    AND c.CUST_ID = d.CUST_ID
    AND c.ID = E.ID
    AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND a.DATE_KEY = 20100601
    AND A.PEF_ID = 1
    GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
         TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')

    Hi,
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Simplify the problem as much as possible.
    Would you have the same problem if only two tables, fact_result_vw and fact_trans, were involved? Then post a question involving only those two tables. Once you have a solution for the simplified problem, adding the other tables will be easy.
    Would the problem be essentially the same if you were pivoting only 2 or 3 columns, instead of 13? Then post a question where you're only pivoting 2 or 3 columns. Once you have a solution, adding the others will be easy.
    787771 wrote:
    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of recordsDo you want only the latest transaction from the fact_trans table, or the latest transaction for each customer ?
    What if there's a tie, and the same customer has two (or more) transactions at the same date, and none later?
    Since you're not using any of the data from the fact_trans table, the effect is just to eliminate customers who are not in fact_trans. You can do that more simply with an IN or EXISTS sub-query.
    If you really do need something from the fact_trans table in the main table, then one way you can get the results you want is to use the analytic RANK (or ROW_NUMBER) function to number the rows in fact_trans by trans_date (latest first), with a separate set of numbers (1, 2, 3, ...) for each customer, like this:
    WITH     fact_trans_1     AS
         SELECT     id     -- all columns that you need
         ,     RANK () OVER ( PARTITION BY  id
                          ORDER BY          date_trans     DESC
                        )     AS r_num
         FROM     fact_trans
    SELECT        TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
           SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
           SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
           SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
           SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
           SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
           SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
           SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
           SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
           SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
           SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
           SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
           SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
           SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM        FACT_RESULT_VW      a,
           PLAN_VW           b,
           SUB_VW           c,
           CUST_VW           d,
           FACT_TRANS_1          e,
    WHERE        e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )
    AND       e.r_num     = 1
    AND        a.PP_KEY      = b.PP_key
    AND        a.ID           = c.ID
    AND       c.CUST_ID      = d.CUST_ID
    AND       c.ID           = E.ID
    AND       c.DATE_JOIN       >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       c.DATE_JOIN      <  To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       a.DATE_KEY = 20100601
    AND       A.PEF_ID = 1
    GROUP BY  TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')I hope this answers your question.
    If not, post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.

  • Function used in SQL query not showing the desired results

    I have created a function that gives me the client id but when i am using the function in the query its not giving me any result i.e. 0 rows but if I execute the function sepreatly and put the result of that function in the qurey it is giving me the desired result please have a look on the following and please reply with you expert opinion:
    FUNCTION CODE:
    create or replace function j2
    (usid in varchar2)
    return varchar2
    is
    cidn_in varchar2(4000) := '';
    ls_sep varchar2(1) := ',';
    cursor predicate_cidn
    is
    select
    logical_schema_id
    from
    CLIENT_REGISTRY cr,
    MEMBER_ROLE_CLIENT_ASSIGNMENT mrca,
    MEMBER m
    where
    mrca.base_client_id = cr.base_client_id and
    mrca.member_id = m.member_id and
    cr.schema_in_use_in = '1' and
    m.active_status_id = 'A' and
    upper(mrca.member_id) = upper(usid);
    BEGIN
    for GET_CIDN in predicate_cidn
    loop
    cidn_in := cidn_in || ls_sep || '''' || GET_CIDN.logical_schema_id || '''';
    end loop;
    cidn_in := substr(cidn_in, 2);
    cidn_in := '('||cidn_in||')';
    --dbms_output.put_line(cidn_in);
    return cidn_in;
    END ;
    SQL> select j2('qaa@adp') from dual;
    J2('QAA@ADP')
    ('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
    K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
    G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
    NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
    1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
    AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
    ','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
    O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
    NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
    ,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
    ','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
    EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
    CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
    3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
    ,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
    TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
    ','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
    INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
    ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
    G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
    3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
    WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
    'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
    ','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
    CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS')
    Now if i put the results (cut and paste )in the query it gives me the results
    SQL> select count(*) from baseclient.address_detail where cidn in ('BASE18','SDK1TEST','SEETHA1CONFIG','BASE09','KAREN2','SIVACONFIG','BASE19','SD
    2 K1CTEST','VASU1','KAREN5','EVENTS1CTEST','SDK1','ADA1CONFIG','BASE10','VRB1CONFI
    3 G','CRU2CONFIG','BASE20','SIVATEST','PCOMCONFIG','KP1CONFIG','KAREN4CONFIG','EVE
    4 NTS1TEST','SUZ3CONFIG','DONG2CONFIG','ED2CONFIG','SIVACTEST','APDCONFIG','EVENTS
    5 1CONFIG','ESSCONFIG','SIVA','SDK2CONFIG','ED3CONFIG','RAJ4CONFIG','CBRCONFIG','N
    6 AMRATA2CONFIG','EMIL1','NAMRATA1CONFIG','SDK2CTEST','BVT2CONFIG','MURUGAN1CONFIG
    7 ','COB1CONFIG','GABY1TEST','CHR1CONFIG','ED4CONFIG','USE1CONFIG','SDK2TEST','DEM
    O1CONFIG','BERNIE1CONFIG','XA1','CAR2TEST','SDK2','ED5CONFIG','PAY1TEST','PAYXCO
    8 9 NFIG','KP1TEST','SEAN1CONFIG','CAR2CTEST','VASU1CONFIG','SEAN2CONFIG','KP1CTEST'
    10 ,'MAU1CONFIG','CONWCONFIG','PAN1CONFIG','MERAJ2','PRA3CONFIG','SEAN5CONFIG','KP1
    11 ','PRA4CONFIG','CAR2CONFIG','PRA2CONFIG','SEAN6CONFIG','PRA3TEST','RPT','GABY1CT
    12 EST','SDK3CONFIG','PRA2TEST','SEAN9CONFIG','CAR2','LV1CONFIG','PRA3CTEST','DONG1
    13 CONFIG','TE1CONFIG','MERAJ2CONFIG','VIV1CONFIG','GABY1','SEAN2','PRA2CTEST','PRA
    14 3','RPTCONFIG','PRA4CTEST','SEAN3','MITA1CONFIG','PRA2','RPTCTEST','PCOM1CONFIG'
    15 ,'SS2CONFIG','PAY1CONFIG','SEAN7','ANNCONFIG','BASE11','BASE02','LV2CONFIG','RPT
    16 TEST','IMPECONFIG','SUR1CONFIG','SREEK2CONFIG','BASE03','SRINU3CONFIG','BDCONFIG
    17 ','JAY1CONFIG','AMMAN1','PRA1TEST','WPGCONFIG','BASE12','MP5CONFIG','MERAJ1','SR
    18 INU2CONFIG','XA1CONFIG','RAJ1CONFIG','WPGCTEST','BASE04','CHRIS','RAJSCONFIG','P
    19 ANKAJ','BASE13','WPGTEST','RAJ3CONFIG','WPG','BASE14','VASU2CONFIG','SRINU1CONFI
    20 G','BASE05','PRA4TEST','VASU1TEST','PRA5CONFIG','NISH1CONFIG','CHRISCONFIG','SDK
    21 3TEST','RAJ3TEST','KP2CONFIG','BASE06','DEFPCONFIG','NISH2CONFIG','CHRISCTEST','
    22 WPSCONFIG','VASU2TEST','BASE15','GABY1CONFIG','PRA5TEST','MITA2CONFIG','BASE07',
    23 'VASU1CTEST','KP2TEST','VASU2CTEST','LAURA3CONFIG','BASE16','CHRISTEST','WPSTEST
    24 ','VASU2','KP2CTEST','EVENTS1','BASE17','RAJ2CONFIG','WPSCTEST','BASE08','SREEK1
    25 CONFIG','ADVE','PRA4','SDK1CONFIG','KP2','KAREN1','CRU1CONFIG','WPS');
    COUNT(*)
    228
    BUT if I user the function it gives me no results
    0 rows selected and its taking a loon time to reurn

    This appears to be a duplicate of the question in this thread
    Re: VPD issue Need Assistance ASAP
    where I wrote
    "Your function returns a single string that happens to have a bunch of commas and quotes in it. An IN list generally requires a list of strings, which your function doesn't return.
    You could rewrite the function to be a pipelined table function and then do
    select count(*)
    from baseclient.address_detail
    where cidn in (SELECT cidn
    FROM TABLE(<<your pipelined table function>>))
    However, I would expect it to be easier not to wrap all this into a function and just have your IN clause be the logic in your predicate_cidn cursor.
    Justin
    "

  • SQL query not retrieving special characters in like O', M÷ and û

    Hi,
    I have a sql script to query database. The output is a string. When I execute this script through a Korn shell script to send the query result to a .csv file, it is showing some characters of the output as below.
    The characters O’ is displayed as ?
    The characters M÷ is displayed as ?
    The characters û is displayed as u
    I am able to retrieve the data as it is while running the script through SQL * Plus and spooling the output to a .csv file.
    If anybody is having solutions for this please reply.
    Thanks in advance for your kind help
    Regards,
    Sreesha
    Edited by: user530278 on Oct 18, 2008 2:56 PM

    user530278 wrote:
    Hi,
    I have a sql script to query database. The output is a string. When I execute this script through a Korn shell script to send the query result to a .csv file, it is showing some charcters of the output as below.
    The characters O’ is displayed as ?
    The characters M÷ is displayed as ?
    The characters û is displayed as uThis sounds like an NLS client setting issue.
    Note that there are scenarios where the data is "incorrectly" stored in the database but can be retrieved "successfully" from some clients. This is the case if you specify the same character set at your client as you have as database character set and this client character set setting is wrong, which means you ought to have specified a different client character set than you have in the database.
    Specifying the same character set on client and server prevents any conversion from taking place, so as long as the database can store the data (e.g. multi-byte characters won't be stored correctly in single-byte character set database no matter what you do) it will be stored "as is". If you now retrieve the data using the same setting, it looks correct, but if you use a client with a different character set setting that requires conversion the data will be mangled.
    The database character set can be identified using the dictionary view NLS_DATABASE_PARAMETERS, parameter "NLS_CHARACTERSET".
    The client character set can be identified by issuing the following at the SQL*Plus prompt:
    SQL> @[%NLS_LANG%]You'll get a message similar to:
    "Unable to open file [AMERICAN_AMERICA.WE8MSWIN1252]"
    The string after the dot represents the client character set.
    If you get this:
    Unable to open file "[%NLS_LANG%]"
    then the NLS_LANG client setting is undefined.
    Please follow this very useful link regarding client NLS issues and how to resolve them, in particular to determine what is your correct client NLS_LANG setting:
    http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm
    I am able to retreive the data as it is while running the script through SQL * Plus and spooling the output to a .csv file.You mean that when using SQL*Plus interactively the data is shown/spooled correctly, whereas if you run a script non-interactively then the data is mangled?
    Note that if you e.g. use "cron" to schedule/execute your script that you need to take care of the Oracle specific environment variables yourself because no logon scripts are executed when cron forks the process to run. May be you need to define the NLS_LANG variable explicitly or call/source the corresponding script to define your default Oracle environment that includes the NLS_LANG setting.
    It probably depends on your environment, operating system, etc. and how you set the Oracle specific settings, e.g. environment variables under Unix, registry settings under Windows etc.
    Use the above mentioned check regarding NLS_LANG setting in the different cases that you encounter to get started.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

Maybe you are looking for

  • How do i use panorama on the 4th generation ipod?

    i saw it said that the ipod touch gets the panorama mode but does anyone know if does work with 4th generation ipod touch?

  • I want to add image name with the extension to db after upload, Can any body help?

    Hello there, Earlier in the week I created PHP photo/image upload form so clients will be able to upload to my site, it worked very well uploading image to designated directory to the C:/path/ but there is more that I would like to do with the form,

  • Odd Airport Extreme Issues

    Hi I'm new to these discussion boards but I was wondering if someone could possibly help me with some airport issues I've been having. My roommate and I both share use an Extreme with Comcast and as far as internet goes everything is great. However o

  • JAXB ERROR

    HI I have DTD that has 2 tags by name BORROWER and _BORROWER. When I try to use the xjc tool of JAXB, both the tags result to BORROWER and I get the following error while parsing- parsing a schema... [ERROR] A class/interface with the same name "com.

  • Powermac G5 shuts down frequently

    I have a dual 2.3GHz G5 that has been been shutting down during normal use. I have come to think it may be related to audio hardware, as it frequently occurs when I try to start iTunes, Audacity(audio editor) and it seems to happen randomly while vie