ABAP SQL: Multiplication in Select-Statement

Hi everybody,
in native SQL it should be possible to use a statement like:
SELECT preisstueck, (anzahl*preisstueck) as gesamtpreis FROM kaufteile
in ABAP I tried:
  SELECT profile
     (SUM( val2300 ) AS val2300    ) + ( SUM( val2315 ) AS val2315    ) + ( SUM( val2330 ) AS val2330 )    + (SUM( val2345 ) AS val2345 )
But I get an Error: Unknown row: (
Could anybody pls help?
Thanks
Regards
Mario

I would never recommend using native SQL. Please try to use OpenSQL so that other abapers can easily understand the code (in future). Suppose in future the customer decides to migrate from Oracle to DB2 or HANA then the sql has to be changed too.
but if you still insist in using it here is a sample code. Please note that it works only for transparent tables.
REPORT demo_native_sql.
DATA: BEGIN OF wa,
        connid   TYPE spfli-connid,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF wa.
DATA c1 TYPE spfli-carrid VALUE 'LH'.
EXEC SQL PERFORMING loop_output.
  SELECT connid, cityfrom, cityto
  INTO   :wa
  FROM   spfli
  WHERE  carrid = :c1
ENDEXEC.
FORM loop_output.
  WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.
Please note:
Native SQL statements bypass the R/3 database interface. There is no table logging, and no synchronization with the database buffer on the application server. For this reason, you should, wherever possible, use Open SQL to change database tables declared in the ABAP Dictionary. In particular, tables declared in the ABAP Dictionary that contain long columns with the types LCHR or LRAW should only be addressed using Open SQL, since the columns contain extra, database-specific length information for the column. Native SQL does not take this information into account, and may therefore produce incorrect results. Furthermore, Native SQL does not support automatic client handling. Instead, you must treat client fields like any other.
See native SQL syntax for
Oracle:Native SQL for Oracle (SAP Library - ABAP Programming (BC-ABA))
Informix: Native SQL for Informix (SAP Library - ABAP Programming (BC-ABA))
DB2: Native SQL for DB2 Common Server (SAP Library - ABAP Programming (BC-ABA))

Similar Messages

  • ABAP Joins or Separate select statements?

    Hi,
       I am working on a simulation of an implementation project as part of my in-house training programme. I am a rookie to ABAP and am now doing a print program that requires master data selection from tables ANLZ, LFA1, MSEG and CSKT, and also related line items from ANLA.
      As a former Java/.NET programmer I used to play with database joins. Now since ABAP joins are much simpler to use, I take the best advantage of them. For instance, in this particular program, I fetched related data from ANLZ, ANLA, LFA1 and CSKT into one internal table using a single select statement with ABAP joins.
      Now I happen to hear (in bits and pieces) that one should limit the use of nested joins to a certain extend. Instead, for the above program, I was advised to use 4 internal tables and to select data separately using FOR ALL ENTRIES. But in this case, we need to use 4 select statements, which means 4 database operations in place of just one.
      From ABAP documentation, I read that we can link upto 24 tables in a single select statement using ABAP joins.
    Can anyone clarify more about this? Which is high on performance?
    Using a single select statement using joins
    or
    Using multiple selects -- FOR ALL ENTRIES?
    Thanks and regards,
    Arun

    Hi Arun,
    you keep reading in these forums that FOR ALL ENTRIES is more performant, but this is simply not true.
    In your example, joining four tables for one DB operation is better than storing a lot of redundant data in internal tables just to perform four separate DB operations using FOR ALL ENTRIES.
    Make sure you join the tables correctly, i.e. link dependent tables giving their full primary key.
    FOR ALL ENTRIES can be used where effective join statements are not possible, e.g. when cluster tables are involved (like BSEG).
    Cheers
    Thomas
    Edit: check this out too: Inner Join or For All Entries

  • PL/SQL Function in Select statement

    Hi
    I am calling a function in select statement. The query works in Toad and PL/SQL developer except SQL plus and disconnecting Oracle connection.
    The error is “ERROR at line 1: ORA-03113: end-of-file on communication channel”.
    When I called the same query from BC4J View Object the error message is “java.sql.SQLException: No more data to read from socket”.
    Can any one advise me please?
    Thanks
    Srini

    Srini
    I've seen similar cases in the past with 9.2.0.x (x <= 5). What Oracle version are you using? It's worth checking the bug database (I can't just now - I don't have a valid support id in my current contract). And as Warren says, post your SQL query.
    HTH
    Regards nigel

  • Sql Error in Select statement when doing subquery

    Hi,
    I am trying to see what the error is in the subquery part of the select statement.
    Subquery should be fetching the safety_stock_quantity based on the MAX(effectivity_date).
    Any suggestions?
    SELECT kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size,
                   (SELECT msc.safety_stock_quantity
    FROM mtl_safety_stocks msc
    WHERE msc.effectivity_date = (select MAX(msc2.effectivity_date)
                   from mtl_safety_stocks msc2
                                            where msc2.inventory_item_id = itm.inventory_item_id
                                                 and msc2.organization_id = itm.organization_id)
                   AND msc.inventory_item_id = itm.inventory_item_id
         AND msc.organization_id = itm.organization_id                                        
    FROM mtl_system_items_b itm
    ,mtl_onhand_quantities_detail moqd
              ,mtl_safety_stocks msc
              ,mtl_kanban_card_activity kbn
    WHERE itm.inventory_item_id = kbn.inventory_item_id
    AND itm.organization_id = kbn.organization_id
    AND itm.inventory_item_id = moqd.inventory_item_id
    AND itm.organization_id = moqd.organization_id
    AND moqd.subinventory_code = kbn.source_subinventory
         AND kbn.card_status = 1
         AND kbn.supply_status = 5
         AND msc.inventory_item_id = itm.inventory_item_id
         AND msc.organization_id = itm.organization_id     
    GROUP BY
    kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size;
    Thanks
    Pravn

    Hi, Pravn,
    Remember the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate fucntion, then every item in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can "SELECT TO_CHAR (TRUNC(dt), 'Mon-DD')").
    There's a GROUP BY clause in your main query, so every item in the main SELECT clause must be one of the above. The last item, the unnamed scalar sub-query, is none of the above.
    How can you fix this problem? That depends on your data, the results you want, and perhaps on your Oracle version. If you'd like help, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (including, but limited to, actual code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL column as select statement to be referenced into a group by

    Is there a notation or solution to be able to reference a column that is a inline select statement within a group by as detailed below? The group by will not accept the alias. I also tried to make the SQL a MAX to remove the need for the group by reference and this returned invalid expression.
    SELECT DISTINCT hdr.BUSINESS_UNIT,
    hdr.SESSN_ID,
    hdr.STREAM_ROOT_ID,
    hdr.SESSN_STS_CD,
    hdr.SESSN_CRE_DTTM,
    CASE
    WHEN C.OPRID <> ' ' THEN C.OPRID
    ELSE S.OPERATOR
    END OPRID,
    strm.QS_APP_CONTEXT,
    RECV.QTY_SH_RECVD Quantity_Received,
    CASE
    WHEN hdr.BUSINESS_UNIT = 'MFG01' THEN MAX(G.MFDS_SGRP_SIZE)
    ELSE MAX(S.SESSN_SGRP_SIZE)
    END Quantity_Inspected,
    MAX(S.QS_VALUEREADING_1) Defect_Count,
    CASE
    WHEN MAX(S.QS_VALUEREADING_1) = 0 THEN ' '
    ELSE MAX(G.MFDS_NAME)
    END Characteristic,
    MAX(CMNT.QS_COMMENT2) COMMENTS,
    strm.INV_ITEM_ID,
    itm.DESCR,
    strm.WORK_CENTER_CODE,
    strm.VENDOR_ID,
    *(SELECT V.NAME1 FROM PS_VENDOR V WHERE strm.VENDOR_ID = V.VENDOR_ID AND V.SETID = (SELECT SETID FROM PS_SET_CNTRL_REC*
    WHERE  RECNAME = 'VENDOR'
    AND SETCNTRLVALUE = strm.BUSINESS_UNIT)) VENDOR_NAME,
    strm.PRDN_AREA_CODE,
    strm.COMPL_OP_SEQ,
    strm.PRODUCTION_TYPE,
    C.RECEIVER_ID,
    C.RECV_LN_NBR,
    RECV.PO_ID,
    RECV.LINE_NBR,
    RECV.SCHED_NBR,
    C.PRODUCTION_ID,
    C.SERIAL_ID,
    C.INV_LOT_ID
    FROM PS_QS_SESSN_HDR8 hdr
    LEFT OUTER JOIN PS_QS_SESSN_TRACE8 C
    ON hdr.BUSINESS_UNIT = C.BUSINESS_UNIT
    AND hdr.SESSN_ID = C.SESSN_ID
    LEFT OUTER JOIN PS_RECV_INSPDTL_VW RECV
    ON C.BUSINESS_UNIT = RECV.BUSINESS_UNIT
    AND C.RECEIVER_ID = RECV.RECEIVER_ID
    AND C.RECV_LN_NBR = RECV.RECV_LN_NBR
    LEFT OUTER JOIN PS_QS_STREAM_ROOT strm
    ON hdr.STREAM_ROOT_ID = strm.STREAM_ROOT_ID
    AND hdr.BUSINESS_UNIT = strm.BUSINESS_UNIT
    LEFT OUTER JOIN PS_QS_STREAM8_VW G
    ON strm.STREAM_ROOT_ID = G.STREAM_ROOT_ID
    AND strm.BUSINESS_UNIT = G.BUSINESS_UNIT
    LEFT OUTER JOIN PS_QS_SUBGROUP S
    ON hdr.BUSINESS_UNIT = S.BUSINESS_UNIT
    AND hdr.SESSN_ID = S.SESSN_ID
    AND S.STREAM_ID = G.STREAM_ID
    LEFT OUTER JOIN PS_QS_SESSN_COMM8 CMNT
    ON S.BUSINESS_UNIT = CMNT.BUSINESS_UNIT
    AND S.SESSN_ID = CMNT.SESSN_ID
    AND S.STREAM_ID = CMNT.STREAM_ID
    AND C.SAMPLE = CMNT.SAMPLE
    LEFT OUTER JOIN PS_MASTER_ITEM_TBL itm
    ON itm.INV_ITEM_ID = strm.INV_ITEM_ID
    LEFT OUTER JOIN PS_SET_CNTRL_REC cntrl
    ON itm.SETID = cntrl.SETID
    AND cntrl.RECNAME = 'MASTER_ITEM_TBL'
    AND cntrl.SETCNTRLVALUE = strm.BUSINESS_UNIT
    WHERE S.QS_VALUEREADING_1 = (SELECT MAX(S2.QS_VALUEREADING_1)
    FROM PS_QS_SUBGROUP S2
    WHERE S2.BUSINESS_UNIT = S.BUSINESS_UNIT
    AND S2.SESSN_ID = S.SESSN_ID
    AND S2.STREAM_ID = S.STREAM_ID)
    GROUP BY hdr.BUSINESS_UNIT,
    hdr.SESSN_ID,
    hdr.STREAM_ROOT_ID,
    hdr.SESSN_STS_CD,
    hdr.SESSN_CRE_DTTM,
    C.OPRID,
    S.OPERATOR,
    strm.QS_APP_CONTEXT,
    RECV.QTY_SH_RECVD,
    strm.INV_ITEM_ID,
    itm.DESCR,
    strm.WORK_CENTER_CODE,
    strm.VENDOR_ID,
    VENDOR_NAME,
    strm.PRDN_AREA_CODE,
    strm.COMPL_OP_SEQ,
    strm.PRODUCTION_TYPE,
    C.RECEIVER_ID,
    C.RECV_LN_NBR,
    RECV.PO_ID,
    RECV.LINE_NBR,
    RECV.SCHED_NBR,
    C.PRODUCTION_ID,
    C.SERIAL_ID,
    C.INV_LOT_ID

    Hi,
    Assign the alias in a sub-query. Then you'll be able to use it wherever you want to, and how many times you want to, in a super-query.
    For example:
    WITH     got_vendor     AS
         SELECT     hdr.business_unit
                  SELECT  v.name1
                  FROM    ps_vendor     v
                  WHERE   strm.vendor_id     = v.vendor_id
                  AND     v.setid          = (
                                                SELECT  setid
                                        FROM    ps_set_cntrl_rec
                                        WHERE   recname          = 'VENDOR'
                                        AND     setcntrlvalue      = strm.business_unit
              )           AS vendor_name
         FROM      ps_qs_sessn_hdr8     hdr
    SELECT       business_unit          -- NOTE: no hdr.; all columns are from got_vendor now
    ,       vendor
    FROM       got_vendor
    GROUP BY  business_unit
    ,       vendor
    ;When you define an alias (such as vendor) in a query, you can use that alias in the ORDER BY clause of that same query, but that's the only place in that same query where you can use it. If you want to use the alias anywhere else (e.g., in the GROUP BY clause, as in your example, the WHERE clause, or elsewhere in the SELECT clause), then you probably want to compute it in a sub-query, as shown above.
    There's probably a better way to compute vendor, but that's a separate problem.
    Edited by: Frank Kulash on Jan 3, 2012 10:37 AM
    Added example

  • Calling PL/SQL code from Select statement

    Hi
    I have a PL/SQL function to calculate a value.
    create or replace procedure "SR_GROSS_MARGIN"
    (netsales IN NUMBER,
    margin IN NUMBER,
    GM OUT NUMBER)
    is
    BEGIN
        IF NETSALES = 0 THEN
           GM := 0;
        ELSIF
           NETSALES < 0 THEN
           GM := 0;
        ELSE
           GM := NETSALES / MARGIN;
        END IF;
    END;How do I call this from a SELECT statement?
    Regards
    Adam

    here you go:
    create or replace function SR_GROSS_MARGIN
    (netsales IN NUMBER,
    margin IN NUMBER)
    return number
    is
    gm number;
    BEGIN
        IF NETSALES = 0 THEN
           GM := 0;
        ELSIF
           NETSALES < 0 THEN
           GM := 0;
        ELSE
           GM := NETSALES / MARGIN;
        END IF;
    return gm;
    END;then you can:
    select gm(2500,20) from dual;

  • SQL insert with select statement having strange results

    So I have the below sql (edited a bit). Now here's the problem.
    I can run the select statement just fine, i get 48 rows back. When I run with the insert statement, a total of 9062 rows are inserted. What gives?
    <SQL>
    INSERT INTO mars_aes_data
    (rpt_id, shpdt, blno, stt, shpr_nad, branch_tableS, csgn_nad,
    csgnnm1, foreign_code, pnt_des, des, eccn_no, entity_no,
    odtc_cert_ind, dep_date, equipment_no, haz_flag, schd_no,
    schd_desc, rec_value, iso_ulti_dest, odtc_exempt, itn,
    liscence_no, liscence_flag, liscence_code, mblno, mot,
    cntry_load, pnt_load, origin_state, airline_prefix, qty1, qty2,
    ref_val, related, routed_flag, scac, odtc_indicator, seal_no,
    line_no, port_export, port_unlading, shipnum, shprnm1, veh_title,
    total_value, odtc_cat_code, unit1, unit2)
    SELECT 49, schemaP.tableS.shpdt, schemaP.tableS.blno,
    schemaP.tableS.stt, schemaP.tableS.shpr_nad,
    schemaP.tableM.branch_tableS, schemaP.tableS.csgn_nad,
    schemaP.tableS.csgnnm1, schemaP.tableD.foreign_code,
    schemaP.tableS.pnt_des, schemaP.tableS.des,
    schemaP.tableD.eccn_no, schemaP.tableN.entity_no,
    schemaP.tableD.odtc_cert_ind, schemaP.tableM.dep_date,
    schemaP.tableM.equipment_no, schemaP.tableM.haz_flag,
    schemaP.tableD.schd_no, schemaP.tableD.schd_desc,
    schemaP.tableD.rec_value,
    schemaP.tableM.iso_ulti_dest,
    schemaP.tableD.odtc_exempt, schemaP.tableM.itn,
    schemaP.tableD.liscence_no,
    schemaP.tableM.liscence_flag,
    schemaP.tableD.liscence_code, schemaP.tableS.mblno,
    schemaP.tableM.mot, schemaP.tableS.cntry_load,
    schemaP.tableS.pnt_load, schemaP.tableM.origin_state,
    schemaP.tableM.airline_prefix, schemaP.tableD.qty1,
    schemaP.tableD.qty2,
    schemaC.func_getRefs@link (schemaP.tableS.ptt, 'ZYX'),
    schemaP.tableM.related, schemaP.tableM.routed_flag,
    schemaP.tableM.scac, schemaP.tableD.odtc_indicator,
    schemaP.tableM.seal_no, schemaP.tableD.line_no,
    schemaP.tableM.port_export,
    schemaP.tableM.port_unlading, schemaP.tableS.shipnum,
    schemaP.tableS.shprnm1, schemaP.tableV.veh_title,
    schemaP.tableM.total_value,
    schemaP.tableD.odtc_cat_code, schemaP.tableD.unit1,
    schemaP.tableD.unit2
    FROM schemaP.tableD@link,
    schemaP.tableM@link,
    schemaP.tableN@link,
    schemaP.tableS@link,
    schemaP.tableV@link
    WHERE tableM.answer IN ('123', '456')
    AND SUBSTR (tableS.area, 1, 1) IN ('A', 'S')
    AND entity_no IN
    ('A',
    'B',
    'C',
    'D',
    'E',
    AND TO_DATE (SUBSTR (tableM.time_stamp, 1, 8), 'YYYYMMDD')
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'
    AND tableN.shipment= tableD.shipment(+)
    AND tableN.shipment= tableS.shipnum
    AND tableN.shipment= tableM.shipment(+)
    AND tableN.shipment= tableV.shipment(+)
    <SQL>
    Edited by: user11263048 on Jun 12, 2009 7:23 AM
    Edited by: user11263048 on Jun 12, 2009 7:27 AM

    Can you change this:
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'To this:
    BETWEEN TO_DATE('01-Mar-2009', 'DD-MON-YYYY')
    AND TO_DATE('31-Mar-2009','DD-MON-YYYY')That may make no difference but you should never rely on implicit conversions like that, they're always likely to cause you nasty surprises.
    If you're still getting the discrepancy, instead of and INSERT-SELECT, can you try a CREATE TABLE AS SELECT... just to see if you get the same result.

  • SQL Insert and Select statements on same page

    Newbie here.
    Is it possible to insert data from a form to a database and then get data from the database using "select" from the same page.
    I have a form that submits the authors details to an Access database but I need to get the AuthorID (which is an autonumber in the table) to show on the same page.
    <%@ page language="java" contentType="text/html" import="java.sql.*" %>
    <html>
    <head>
    <title>Confirm Details Submission</title>
    </head>
    </body>
    <%
    String title = request.getParameter("title");
    String surname = request.getParameter("surname");
    surname = surname.replaceAll("'", "''");
    String forename = request.getParameter("forename");
    forename = forename.replaceAll("'", "''");
    String address = request.getParameter("address");
    address = address.replaceAll("'", "''");
    String address2 = request.getParameter("address2");
    address2 = address2.replaceAll("'", "''");
    String town = request.getParameter("town");
    town = town.replaceAll("'", "''");
    String postcode = request.getParameter("postcode");
    String email = request.getParameter("email");
    email = email.replaceAll("'", "''");
    String dob = request.getParameter("dob");
    String telephone = request.getParameter("telephone");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection Conn = DriverManager.getConnection("jdbc:odbc:Novbase","","");
    Statement Stmt = Conn.createStatement();
    String Query = ("INSERT INTO Author (Title, Surname, Forename, Address, Address2, Town, Postcode, EMail, DOB, TelNo) VALUES ('" + title + "', '" + surname + "', '" + forename + "', '" + address + "', '" + address2 + "', '" + town + "', '" + postcode + "', '" + email + "', '" + dob + "', '" + telephone +"')");
    //Stmt.executeUpdate(Query) is where the records are inserted.
    int SQLStatus = Stmt.executeUpdate(Query);
         if(SQLStatus != 0)
    %>
    Thank you. Your Author ID number is ??
    <%
    else
    %>
    Error - Your details have not been submitted</font></h4>
    <br>
    Please click back on your browser and try again. If you experience further difficulties please go to our <a href ="help.html">help</a> pages.<br>
    <%
    Stmt.close(); Conn.close();
    %>
    </body>
    </html>

    Hi,
    You could execute queries as many times as you want using the same connection.
    For ex;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection Conn = DriverManager.getConnection("jdbc:odbc:Novbase","","");
    Statement Stmt = Conn.createStatement();
    String Query = ("INSERT INTO Author (Title, Surname, Forename, Address, Address2, Town, Postcode, EMail, DOB, TelNo) VALUES ('" + title + "', '" + surname + "', '" + forename + "', '" + address + "', '" + address2 + "', '" + town + "', '" + postcode + "', '" + email + "', '" + dob + "', '" + telephone +"')");
    //Stmt.executeUpdate(Query) is where the records are inserted.
    int SQLStatus = Stmt.executeUpdate(Query);
    if(SQLStatus != 0)
    Query = "SELECT Forname FROM Author;";
    ResultSet name = stmt.executeQuery(Query);
    //Now name will have all the Forname fields in the database. You could retrieve that using the get methods.
    %>
    Thank you. Your Author ID number is ??
    <%
    else
    %>
    Error - Your details have not been submitted</font></h4>
    <br>
    Please click back on your browser and try again. If you experience further difficulties please go to our <a href ="help.html">help</a> pages.<br>
    <%
    Stmt.close(); Conn.close();
    %>
    I hope that can help you.
    Rajesh

  • ABAP WD, Multiple Row selection in table control without using Crtl key

    Hi all,
    I am displaying the records using the table control, i have to select the multiple records in the list <b>without using Crtl key</b>.
    How do i solve this?
    Thanks

    Hi,
    you should set the table parameter selectionMode to multi or multinolead
    than you can select multiple records,
    these you can retrieve: lt_selected_elements = node->get_selected_elements( ).
    also see this <a href="https://forums.sdn.sap.com/click.jspa?searchID=4209200&messageID=3544158">thread</a> for info
    grtz,
    Koen

  • ABAP WD, Multiple Row selection in table control

    Hi all,
            I am populating and displaying the records using the table control, i have to select the multiple records in the list and want do some deletion,selection,so i could not select the more than one record.
    How do i solve this?
    Please give me your valuable suggestions.
    Thanks

    Hi ulli,
    thanks for your quick reply,
    now its working for me but i have to press the 'CTRL' key and select the row, for selecting the multiple rows.
    one more thing i wanted some methods for "DELETION", "SELECTING ALL RECORDS","DESELECTING",in the displayed list.
    plz suggest me..,
    thanks and regards
    kamal

  • Creating a Job for publication in Sql Server with select statement for passing a parameter

    I am creating a job for adding article to a publication.  the second step (e.g. for adding article) gives me error. I pass the name of the table as follow:
         EXEC sp_addarticle
               @publication = 'TTB', --THE NAME OF MY PUBLICATION
               'select top (1)' @article = 'Name from TableAdded Order by create_date Desc',
               'select top (1)' @source_object = 'Name from TableAdded Order by create_date Desc',
                @force_invalidate_snapshot = 1;
    TableAdded is a table I have in my publisher which contains the name of the newly added table.
    I believe it fails because the way I pass the name of the article to the store procedure is not correct. Can anyone please help me on that?
    Kind regards
    Amin

    Yes, the way you add article is wrong.
    you may try the below and let us know if you have any issues:
    while loop begin (Get the values from TableAdded with status IsAdded=0)
              Assign the values to variables like @article = Select top 1 Name from TableAdded where IsAdded=0
              Call the sp_addarticle assigning the variable
              update the Isadded flag in tableAdded for the name to 1 
     end while 
    BTB, Article configuration is supposed to be a one time configuration. Having said, you can easily configure through API. Caution, not sure what are you trying here, for adding new article, you may need to synch the data first in the above approach and should
    carried out in the downtime.

  • Error while retrieving data from PL/SQL Table using SELECT st. (Urgent!!!)

    Hi Friends,
    I am using Oracle 8.1.6 Server, & facing problems while retrieving data from a PL/SQL Table:
    CREATE or REPLACE PROCEDURE test_proc IS
    TYPE tP2 is TABLE of varchar2(10); --declared a collection
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST(dt2 as tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    While executing the above procedure, I encountered foll. error:
    ERROR at line 1:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL execution], [], [],
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [], [], [], [], []
    ORA-06553: PLS-801: internal error [0]
    Can anyone please help me, where the problem is??
    Is it Possible to retrieve data from PL/SQL TABLE using SELECT statement? & How ?
    Thanks in advance.
    Best Regards,
    Jay Raval.

    Thanks Roger for the Update.
    It means that have to first CREATE TYPE .. TABLE in database then only I can fire a Select statement on that TYPE.
    Actually I wanted to fire a Select statement on the TABLE TYPE, defined & declared in PLSQL stored procedure using DECLARE TYPE .. TABLE & not using CREATE TYPE .. TABLE.
    I was eager to know this, because my organization is reluctant in using CREATE TYPE .. TABLE defined in the database, so I was looking out for another alternative to access PL/SQL TABLE using Select statement without defining it database. It would have been good if I could access a PLSQL TABLE using Select statement Declared locally in the stored procedure.
    Can I summarize that to access a PL/SQL TABLE using SELECT statement, I have to first CREATE TYPE .. TABLE?
    If someone have any other idea on this, please do let me know.
    Thanks a lot for all help.
    Best Regards,
    Jay Raval.
    You have to define a database type...
    create type tP2 is table of varchar2(10)
    CREATE OR REPLACE PROCEDURE TEST_PROC
    IS
    dt2 tP2 := tP2('a','b','c');
    i NUMBER(8);
    begin
    SELECT COUNT(*) INTO i FROM TABLE(CAST (dt2 AS tP2));
    DBMS_OUTPUT.PUT_LINE('**'||i);
    end;
    This will work.
    Roger

  • Why report is always select statement...

    hi guys,
    when we are dragging the columns from Business Area or in any reporting tool, and when we see the SQL, why it gives always select query.
    this question is raised by one of my manager having 15+ years of experience in Oracle Apps.
    Any suggestions?

    Ok, if I understand it, he wants to know why any query tool uses SQL (ie: select) to display the data.
    And the answer is actually really simple - it's the only way to get data from an Oracle database.
    That's it ... there's absolutely, positively no other way of getting data back from an Oracle (ie: relational) database.
    It doesn't matter if you use Discoverer, Cognos, Brio, Business Objects, Microsoft products via ODBC, etc., everything boils down to a SELECT statement eventually.
    So in Discoverer, the workbook / worksheets that you create keep information about the 'presentation' of that data - ie: colors, fonts, titles, graphs, etc. but the retrieval of data will always be in SQL - and as it sounds like you noticed - you can view the SQL in Discoverer if you desire.
    Look at it this way - in Discoverer you're saying "go get me AP_Invoice information, where I want the invoice number, the invoice date, the invoice amount, the vendor name, the vendor number, etc. ... and I want the total of the invoice amount when I enter a date range".
    That's the coding in Discoverer. The minute you invoke that code - ie: run the worksheet - badda' bing ... badda' boom ... it initiates a SQL command to the Discoverer database tables (via a folder in the EUL) probably something like: select invoice_number, invoice_date, invoice_amount, vendor_name, vendor_number from ap_invoices where invoice_date between '01-JAN-2008' and '03-JAN-2008'.
    The Oracle database comes back with the data, dumps it into Discoverer and Discoverer does all the fancy layouts, colors and totals ... and everyone's happy.
    So again, the only way to communicate with an Oracle database using ANY TOOL is via SQL (and the SELECT statement is the fundamental way of retrieving data). And for the Oracle Apps guy you mentioned, that includes all the Oracle Apps Forms (screens), Oracle Apps reports, changing user passwords, the concurrent manager ... etc.
    It's a SQL Select world when it comes to Oracle!
    Russ

  • Multiple Select statements in EXECUTE SQL TASK in SSIS

    Can we write multiple select statements in execute sql task(SSIS).
    If possible how to assign them to variables in result statement

    Hi ,
    You can use below steps to set result set to variable.
    1.In the Execute SQL Task Editor dialog box, on the General page, select the Single row, Full result set, or XML result set type(According to your result set).
    2.Click Result Set.
    3.To add a result set mapping, click Add.
    4.From the Variables Name list, select a variable or create a new variable.
    What is multiple selection ? May be below can be used in your scenario !
    http://stackoverflow.com/questions/17698908/how-to-set-multiple-ssis-variables-in-sql-task
    What you want to achieve ?
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • How to generate mutiple Results for multiple SQL SELECT statements

    I just downloaded SQL Developer 1.5 and play around with it.
    On a daily basis, I need run 4 different SELECT statements and dump the output of each SELECT into an CSV file and send to some users. In SQL Navigator, I can select all 4 SELECT statements and execute them at same time. Once all complete, I will see 4 tabs, each represent the output for each SELECT statement. Then I can export output from each tab into a CSV file.
    It seems that SQL Developer 1.5 still can't run mutiple SELECT statements and display the output of each statement into a separate "Results" tab so that I can export the data into multiple CSV files easily.
    Right now, I have to hightlight each SELECT statement and press F9, then export the output data into CSV.
    I wish I can execute 4 SELECT statements all in once on SQL Developer and get all the output data and export 4 times into 4 CSV files.
    Thanks!
    Kevin

    How about doing it as a set of tabs within the Resuls Tab?
    So you would have your Top row of tabs:
    Results, Script Output, Explain, AutoTrace, DBMS Output and OWA Output
    Then When you have the Results tab selected you could have a row of tabs beneath the Top row with one tab for each result set. Switching between result sets should switch which section of SQL is highlighted as the "Current SQL".
    A similar mechinism could be employed for each of the top level tabs where it makes sense to have multiple output tabs.
    A further refinement of this feature might be to allow the result tabs to be dockable within the parent tab so that multiple result tabs can be viewed simultaneously. This way 2 or more explain plans (for example) could be visually compared without requiring the code to exist in two separate code panes.

Maybe you are looking for