Select count in view question

The sql view below does not do what I want it to and not sure which string function to use. The goal is to get the two columns with instr to only count the rows that the INSTR actually finds the string. Basically I am looking for a substring function that returns a boolean value and only count those when true. How I go about this in an oracle view.
code:
CREATE OR REPLACE VIEW LOGONREPORT
AS
SELECT USERNAME,
COUNT(*) ATTEMPTS,
COUNT(INSTR(ACTION,'LOG IN SUCCESS',1,1)) SUCCESS,
COUNT(INSTR(ACTION,'LOG IN FAILED',1,1)) FAILED
FROM AUDITRECORD
GROUP BY USERNAME;
--------------------

Hi,
for example:
SQL> select ename, deptno from emp;
&nbsp
ENAME          DEPTNO
SMITH              20
ALLEN              30
WARD               30
JONES              20
MARTIN             30
BLAKE              30
CLARK              10
SCOTT              20
KING               10
TURNER             30
ADAMS              20
JAMES              30
FORD               20
MILLER             10
&nbsp
14 rows selected.
&nbsp
SQL> select deptno, instr(ename,'M') from emp order by 1,2;
&nbsp
    DEPTNO INSTR(ENAME,'M')
        10                0
        10                0
        10                1
        20                0
        20                0
        20                0
        20                2
        20                4
        30                0
        30                0
        30                0
        30                0
        30                1
        30                3
&nbsp
14 rows selected.
&nbsp
SQL> select deptno,
  2  count(decode(instr(ename,'M'),0,null,instr(ename,'M'))) cnt
  3  from emp group by deptno
  4  /
&nbsp
    DEPTNO        CNT
        10          1
        20          2
        30          2Rgds.

Similar Messages

  • Select * vs select count(*)

    I have 2 schemas within a database, one is an exact copy of the other. One of the views that has been created is behaving strangly.
    On schema 1:
    doing a "select * from view" lists all the records.
    doing a "select count(*) from view" gives the correct count of the records
    On schema 2:
    doing a "select * from view" lists all the records.
    doing a "select count(*) from view" gives a count of zero!
    Stats were gathered yesterday for both schemas so are not out of date (not much data has been inserted since).
    The above applies for Toad, sqlplus, isql, etc.
    Oracle Database 10g Release 10.2.0.3.0 - 64bit Production.
    Any ideas what could cause this?
    Thanks.

    Rows are returned from the sql.
    Select count(1) still returns a zero count and recreating the view has no effect.
    Putting a 'where' clause in the select does bring back a count, but the count is again different to the actual number of rows returned when doing a select *.

  • Question of understanding MaxDB 7.6.36 & select count (*)

    Hi all,
    we do a
    SELECT
      COUNT(*)
    FROM
      "/BIC/FTABLE"
    which lasts very long in my opinion.
    The explain shows an index scan with an only index access and a high pagecount.
    TABLENAME     COLUMN OR INDEX     STRATEGY               PAGECOUNT
    /BIC/FTABLE   /BIC/FTABLE~02      INDEX SCAN             79669
                                      ONLY INDEX ACCESSED
    SHOW                              RESULT IS COPIED, COSTVALUE IS 79671
    The file directory counter entries for the table do exist, so why is this access so slow?
    Anybody any idea?
    Thank you.
    Best regards
    Christian

    Hi Ashwath,
    the Version of MaxDB is 7.6. Build 36 as stated in subject
    The operating system is SuSe Linux 9 PL 3 64 Bit.
    Hi Lars,
    yes we are SAP user, the statement was generated in SCM5.0 and directly taken from command monitor using the explain function within DB50.
    By the way ... in DB50 the statement is first shown as
    SELECT
      COUNT(*) INTO ?
    FROM
      "/BIC/FTABLE"
    but the explain shows the statment as
    SELECT
      COUNT(*)
    FROM
      "/BIC/FTABLE"
    maybe there could be a difference...
    So there is no MANDT in the where clause which could be the reason for this.
    If I am right you say, that a select count (*) always uses an index access? Why doesn't use MaxDB the file directory counter? Thats what I expected.
    Best regards
    Christian Götze

  • Sub-Select Count query breaking TOAD

    Oracle 10.2.0.4.0
    Running TOAD 9.1
    I am running some SQL on our eBusiness Suite:
    SELECT pha.segment1
         , pha.type_lookup_code
         , (SELECT COUNT(DISTINCT pha2.po_header_id)
              FROM po.po_headers_all pha2
                 , po.po_lines_all pla
             WHERE pha2.po_header_id = pla.po_header_id
               AND pla.contract_id = pha.po_header_id) po_count
         , (SELECT MAX(pha2.creation_date)
              FROM po.po_headers_all pha2
                 , po.po_lines_all pla
             WHERE pha2.po_header_id = pla.po_header_id
               AND pla.contract_id = pha.po_header_id) latest_cpa_po
      FROM po.po_headers_all pha
         , po.po_vendors pv
         , po.po_vendor_sites_all pvsa
    WHERE pha.vendor_id = pv.vendor_id
       AND pha.vendor_site_id = pvsa.vendor_site_id
    --   AND pv.VENDOR_NAME LIKE 'H%'
       AND pha.vendor_id = 98
       AND pha.type_lookup_code = 'CONTRACT'
       AND pha.org_id IN(7041, 7042);The above query runs quicky (approx. 1 second). If I take out the AND pha.vendor_id = 98 then the query takes a few minutes to run.
    When I try to export it, or scroll down to view > 500 rows, TOAD crashes.
    I know this isn't a TOAD forum, but I think that this is probably an issue with my no doubt rubbish SQL.
    If I take out this sub-select, then the problem doesn't happen:
         , (SELECT COUNT(DISTINCT pha2.po_header_id)
              FROM po.po_headers_all pha2
                 , po.po_lines_all pla
             WHERE pha2.po_header_id = pla.po_header_id
               AND pla.contract_id = pha.po_header_id) po_countHowever, I can't work out a better way of getting the data I need.
    The sub-select counts POs which have been raised where the contractID on the PO line is the same as the PO Header ID from the main query.
    Any advice please, on what I could do to sort this out would be much appreciated.
    Thanks!

    Hi,
    It looks like you can replace both scalar sub-queries with a join, like this:
    WITH     header_lines_summary     AS
         SELECT    pla.contract_id
              ,       COUNT (DISTINCT pha2.po_header_id)     AS po_count
              ,       MAX (pha2.creation_date)          AS latest_cpa_po
              FROM        po.po_headers_all pha2
                 ,        po.po_lines_all   pla
             WHERE        pha2.po_header_id = pla.po_header_id
          GROUP BY       pla.contract_id
    )                                        -- Everything up to this line is new
    SELECT pha.segment1
         , pha.type_lookup_code
         , hls.po_count                              -- Changed
         , hls.latest_cpa_po                         -- Changed
      FROM po.po_headers_all     pha
         , po.po_vendors           pv
         , po.po_vendor_sites_all      pvsa
         , header_lines_summary     hls                    -- New
    WHERE pha.vendor_id          = pv.vendor_id
       AND pha.vendor_site_id     = pvsa.vendor_site_id
       AND pha.po_header_id          = hls.contract_id (+)          -- New
    --   AND pv.VENDOR_NAME      LIKE 'H%'
       AND pha.vendor_id           = 98
       AND pha.type_lookup_code      = 'CONTRACT'
       AND pha.org_id           IN (7041, 7042);Aside from the sub-query (which is entirely new), the query above is just what you posted, with 2 lines changed and 2 lines added, as marked.
    This should be more efficient, but I don't know for certain that it will solve the Toad problem.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    It never hurts to say what version of Oracle you're using.

  • Select a specific view in MM02/MM01

    Hi Abappers,
    I am doing a BDC on MM01 transaction and want to just select the accounting view and extend materials for different valuation types. But the position of accounting view is coming different on different material and my BDC recording is failing to select the accounting view. Does anyone has any idea how we can pinpoint and select the accounting view?
    Thanks,
    David.

    SELECTION_VIEWS_FIND  - This FM Will work depends on material type..
    in your case this FM Is not required and you need to have Accounting view.
    Any way See below program and you will get some idea and uploaded data into Material master change mode and it is applicable to user defined view
    REPORT zjpmuim306 NO STANDARD PAGE HEADING LINE-SIZE 250 MESSAGE-ID
    zjpm001.
    *&   I N B O U N D  V I A   A B A P : Batch input Session method     *
    *&   Development ID: IM_DD_306_LJP                                   *
    *&   Report        : ZJPMUIM306                                      *
    *&   The Purpose of the Object is to interface Create Input Record   *
    *&   for SAP Migration from the Material master of BPCS All the      *
    *&   information received at BPCS is collected into a single record. *
    *&   By using session method upload data from file ,one item is
    *&   created for one record                                          *
    *&   Change Log:                                                     *
    *&   Init       Who              Date         Text                   *
    *&  MALIKDH1   Seshu Reddy    26-07-2003   Initial Version           *
                             Constants                                   *
    CONSTANTS:c_vkorg(4) type c value 'JP20',        " Sales Organization
              c_vtweg(2) type c value 'TR' ,         " Distribution Channel
              c_werks(4) Type c value 'JP01' ,       " Plant
              c_viewlist(15) VALUE 'KDEALBSZXVPCFQG'," View list
              c_scm_view TYPE msichtausw-dytxt VALUE 'SCM View',
              c_sd_view TYPE msichtausw-dytxt VALUE 'SD View',
              c_seq_code(2) VALUE 'Z1',              " Sequential Code
              c_keep(1) TYPE c VALUE  'X',           " Keep
              c_group LIKE apqi-groupid VALUE 'IM306', " Session Name
              c_tcode  LIKE tstc-tcode VALUE 'MM02',  " Transaction Code
              c_blank(1) VALUE ' ',                   " Blank
              c_intls(1) VALUE 'N'.                  " Logistic Status
                  Variables                                      *
    DATA: g_flag1(1),  " Variable to hold
          g_flag(1),   " Variable to hold
          g_file LIKE rlgrap-filename VALUE
         'C:\Documents and Settings\seshur\Desktop\HCLT123.CSV'. " File name
           Internal tables/ Work area                           *
    Internal Table for Delimter
    DATA : BEGIN OF t_delim OCCURS 0,
           text(1000),
           END OF t_delim.
    Internal table for BDC processing
    DATA : t_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
    Internal table for holding the data which has to be uploaded.
    DATA: BEGIN OF t_bpcs OCCURS 0,
          matnr(15) TYPE c,  " material no
          dosage(40) TYPE c, " Dosage form(Local)
          appearance(40) TYPE c, " Appearance
          idcode(6) TYPE c,     " Identification Code
          prostformno(10) TYPE c, "SOP
          weitab(7) TYPE c,    " Weight/tablet
          uom1(2) TYPE c,     " UOM of Carton
          uom2(2) TYPE c,     " UOM of Case
          carsize(14) TYPE c, " Carton size
          cassize(14) TYPE c, " Case size
          rupqty(11) TYPE c,  " Round up
          abvname(3) TYPE c,  " Product short name
          END OF t_bpcs.
    *Internal table for t_bpcs
    DATA: BEGIN OF t_mdata OCCURS 0,
          matnr  LIKE marc-matnr, " Material number
          zzjp_dos_frm LIKE marc-zzjp_dos_frm, " Dosage form(Local)
          zzjp_aprn LIKE marc-zzjp_aprn, " Appearance
          zzjp_con_id LIKE marc-zzjp_con_id," Identification Code
          zzjp_nyu_sop LIKE marc-zzjp_nyu_sop,"SOP
          zzjp_wei_tab(10) type c , " Weight/tablet
          zzjp_bio  LIKE marc-zzjp_bio,"Biologics Indicator
          zzjp_itf LIKE marc-zzjp_itf, " ITF code
          zzjp_car(2) type c, " UOM of Carton
          zzjp_cas(2) type c, " UOM of Case
          zzjp_car_size(11) type c," Carton size
          zzjp_cas_size(11) type c, " Case size
          zzjp_rupqty(11) type c,  " Round up
          zzjp_init_ls LIKE marc-zzjp_init_ls, " Logistic Status
          zzjp_re1 LIKE marc-zzjp_re1, "Document type(Local)
          zzjp_re2 LIKE marc-zzjp_re2, "Report type
          zzjp_re3 LIKE marc-zzjp_re3, "Shipping report type
          zzjp_pro_id LIKE mvke-zzjp_pro_id," Product output sequence
          zzjp_bu_id LIKE mvke-zzjp_bu_id, " Business unit indicator
          zzjp_abv_name LIKE mvke-zzjp_abv_name," Product short name
          zzjp_abv_id1 LIKE mvke-zzjp_abv_id1," Product short name output
          zzjp_abv_id2 LIKE mvke-zzjp_abv_id2," Product short name internal
          zzjp_spl_id LIKE mvke-zzjp_spl_id,  " Sample internal order
          END OF t_mdata.
    Internal table for Mara Table
    DATA: BEGIN OF t_mara OCCURS 0,
          matnr LIKE mara-matnr,  " material Number
          vpsta LIKE mara-vpsta,  " Maintenance status of complete material
          pstat like mara-pstat,  " Maintenance status
          END OF t_mara.
    Internal table for Material Master View Selection Screens
    DATA: BEGIN OF t_bildtab OCCURS 0.
            INCLUDE STRUCTURE mbildtab.
    DATA: END OF t_bildtab.
    internal table for T_bildtab
    DATA: t_bildtab_dup LIKE t_bildtab OCCURS 0 WITH HEADER LINE.
    *Work area for T_bildtab internal table(Views Selection)
    DATA: BEGIN OF w_data,
          flag1 type c,
          anzd70 TYPE i,
          field1(20) type c,
          field2(20) type c,
          field3(20) type c,
          field4(20) type c,
          count(2) TYPE c,
          END OF w_data.
                Main Processing                           *
    START-OF-SELECTION.
    Store data from file into internal table
      PERFORM f_uplaod_data.
    Transfer the uploaded data into t_mdata internal Table
      PERFORM f_process_data.
    Selecting The views based on Material number
      PERFORM f_view_list.
    Open a BDC Session
      PERFORM f_bdc_open.
    *Selecting the fields from mara table
      SELECT matnr
             vpsta
             pstat
        FROM mara
      INTO TABLE t_mara
      FOR ALL ENTRIES IN t_mdata
      WHERE matnr = t_mdata-matnr.
      SORT t_mara BY matnr.
      SORT t_mdata BY matnr.
    Transfer the uploaded data into BDCDATA structure
      PERFORM f_process_bdc.
    Close The BDC Session
      PERFORM f_close_group.
    *&      Form  F_VIEW_LIST                                             *
             Routine to used for Calling the function module            *
              Selection_views_find                                      *
    FORM f_view_list.
      CALL FUNCTION 'SELECTION_VIEWS_FIND'
           EXPORTING
                bildsequenz     = c_seq_code
                pflegestatus    = c_viewlist
           TABLES
                bildtab         = t_bildtab
           EXCEPTIONS
                call_wrong      = 1
                empty_selection = 2
                OTHERS          = 3.
      IF sy-subrc <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " F_VIEW_LIST
    *&      Form  f612_view_sort                                          *
      Routine to used for Selecting The views based on Material Number  *
    FORM f612_view_sort.
      t_bildtab_dup[] = t_bildtab[].
    Reading the Internal table t_mara
      READ TABLE t_mara WITH KEY matnr = t_mdata-matnr.
      TRANSLATE t_mara-pstat USING ' $'.
      CLEAR: w_data-flag1, w_data-anzd70.
      LOOP AT t_bildtab_dup.
        IF t_bildtab_dup-pstat CA t_mara-pstat.
          w_data-anzd70 = w_data-anzd70 + 1.
          IF t_bildtab_dup-kzanz IS INITIAL.
            t_bildtab_dup-kzanz = 'X'.
            w_data-flag1 = 'X'.
            MODIFY t_bildtab_dup.
          ENDIF.
        ELSE.
          IF NOT t_bildtab_dup-kzanz IS INITIAL.
            CLEAR t_bildtab_dup-kzanz.
            w_data-flag1 = 'X'.
            MODIFY t_bildtab_dup.
          ENDIF.
        ENDIF.
      ENDLOOP.
      TRANSLATE t_mara-pstat USING '$ '.
      IF NOT w_data-flag1 IS INITIAL.
        SORT t_bildtab_dup BY kzanz DESCENDING idxbd ASCENDING.
      ENDIF.
    *Reading The internal table for T_bildtab_dup
      READ TABLE t_bildtab_dup WITH KEY dytxt = c_scm_view.
      IF t_bildtab_dup-kzanz = 'X'.
        WRITE sy-tabix TO w_data-count.
        w_data-count = w_data-count + 2.
        IF w_data-anzd70 > 18.
          w_data-count = w_data-count - 18.
        ENDIF.
        CONCATENATE 'MSICHTAUSW-DYTXT(' w_data-count ')' INTO w_data-field1.
        CONCATENATE 'MSICHTAUSW-KZSEL(' w_data-count ')' INTO w_data-field2.
      ENDIF.
      READ TABLE t_bildtab_dup WITH KEY dytxt = c_sd_view.
      IF t_bildtab_dup-kzanz = 'X'.
        WRITE sy-tabix TO w_data-count.
        IF w_data-anzd70 > 18.
              w_data-count = w_data-count + 2.
          w_data-count = w_data-count - 18.
        ENDIF.
        CONCATENATE 'MSICHTAUSW-DYTXT(' w_data-count ')' INTO w_data-field3.
        CONCATENATE 'MSICHTAUSW-KZSEL(' w_data-count ')' INTO w_data-field4.
      ENDIF.
    ENDFORM.                    " f612_view_sort
    *&      Form  f_uplaod_data                                           *
    Routine to used for Uploading the data from file to Internal table *
    FORM f_uplaod_data.
      CALL FUNCTION 'WS_UPLOAD'
           EXPORTING
                filename                = g_file
                filetype                = 'DAT'
           TABLES
                data_tab                = t_delim
           EXCEPTIONS
                conversion_error        = 1
                file_open_error         = 2
                file_read_error         = 3
                invalid_type            = 4
                no_batch                = 5
                unknown_error           = 6
                invalid_table_width     = 7
                gui_refuse_filetransfer = 8
                customer_error          = 9
                OTHERS                  = 10.
      IF sy-subrc <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF t_bpcs IS INITIAL.
        LOOP AT t_delim.
          SPLIT t_delim-text AT ',' INTO t_bpcs-matnr
                                         t_bpcs-dosage
                                         t_bpcs-appearance
                                         t_bpcs-idcode
                                         t_bpcs-prostformno
                                         t_bpcs-weitab
                                         t_bpcs-uom1
                                         t_bpcs-uom2
                                         t_bpcs-carsize
                                         t_bpcs-cassize
                                         t_bpcs-rupqty
                                         t_bpcs-abvname.
          APPEND t_bpcs.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " f_uplaod_data
    *&      Form  F_BDC_OPEN
          Routine  to create BDC Session to be processed
    FORM f_bdc_open.
      CALL FUNCTION 'BDC_OPEN_GROUP'
           EXPORTING
                client              = sy-mandt
                group               = c_group
                keep                = c_keep
                user                = sy-uname
           EXCEPTIONS
                client_invalid      = 1
                destination_invalid = 2
                group_invalid       = 3
                group_is_locked     = 4
                holddate_invalid    = 5
                internal_error      = 6
                queue_error         = 7
                running             = 8
                system_lock_error   = 9
                user_invalid        = 10
                OTHERS              = 11.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
      MESSAGE S000 WITH 'Batch input session is created successfully'(T02).
      ENDIF.
    ENDFORM.                    " F_BDC_OPEN
    *&      Form  F_PROCESS_BDC
          Processing of BDCDATA Structure
    FORM f_process_bdc.
      LOOP AT t_mdata.
        PERFORM f612_view_sort.
        PERFORM f_bdc_dynpro USING 'SAPLMGMM' '0060'.
        PERFORM f_bdc_field USING 'BDC_CURSOR'
                                      'RMMG1-MATNR'.
        PERFORM f_bdc_field USING 'BDC_OKCODE'
                                      '=AUSW'.
        PERFORM f_bdc_field USING 'RMMG1-MATNR'
                                      t_mdata-matnr.
        PERFORM f_bdc_dynpro USING 'SAPLMGMM' '0070'.
        PERFORM f_bdc_field USING 'BDC_CURSOR'
                                  'MSICHTAUSW-DYTXT(01)'.
        IF w_data-anzd70 > 18.
          PERFORM f_bdc_field       USING 'BDC_OKCODE'
                                      '=P+'.
          PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '0070'.
          PERFORM f_bdc_field  USING 'BDC_OKCODE' '/00'.
        ENDIF.
    reading the t_bildtab internal table
        READ TABLE t_bildtab_dup WITH KEY dytxt = c_scm_view.
        IF t_bildtab_dup-kzanz = 'X'.
          PERFORM f_bdc_field       USING 'BDC_CURSOR'
                                        w_data-field1.
          PERFORM f_bdc_field       USING w_data-field2 'X'.
          g_flag = 'X'.
        ENDIF.
    reading the t_bildtab internal table
        READ TABLE t_bildtab_dup WITH KEY dytxt = c_sd_view.
        IF sy-subrc EQ 0.
          g_flag = 'X'.
        ENDIF.
        IF t_bildtab_dup-kzanz = 'X'.
          PERFORM f_bdc_field       USING 'BDC_CURSOR'
                                        w_data-field3.
          PERFORM f_bdc_field       USING w_data-field4 'X'.
          g_flag1 = 'X'.
        ENDIF.
        IF g_flag = 'X' AND g_flag1 = 'X'.
          PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '0080'.
          PERFORM f_bdc_field       USING 'BDC_CURSOR'
                                        'RMMG1-VTWEG'.
          PERFORM f_bdc_field       USING 'BDC_OKCODE'
                                        '=ENTR'.
          PERFORM f_bdc_field       USING 'RMMG1-WERKS'
                                        c_werks.
          PERFORM f_bdc_field       USING 'RMMG1-VKORG'
                                        c_vkorg.
          PERFORM f_bdc_field       USING 'RMMG1-VTWEG'
                                        c_vtweg.
          CLEAR g_flag.
          CLEAR g_flag1.
        ELSE.
          IF g_flag = 'X'.
            PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '0080'.
            PERFORM f_bdc_field       USING 'RMMG1-WERKS'
                                        c_werks.
            PERFORM f_bdc_field      USING 'BDC_OKCODE' '/00'.
          ELSE.
            IF g_flag1 = 'X'.
              PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '0080'.
              PERFORM f_bdc_field       USING 'BDC_CURSOR'
                                            'RMMG1-VTWEG'.
              PERFORM f_bdc_field       USING 'RMMG1-WERKS'
                                          c_werks.
              PERFORM f_bdc_field       USING 'RMMG1-VKORG'
                                            c_vkorg.
              PERFORM f_bdc_field       USING 'RMMG1-VTWEG'
                                            c_vtweg.
              PERFORM f_bdc_field       USING 'BDC_OKCODE'
                                             '=ENTR'.
            ENDIF.
          ENDIF.
        ENDIF.
    *Processing of SCM View
        PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '4000'.
        PERFORM f_bdc_field       USING 'BDC_CURSOR' 'MARC-ZZJP_DOS_FRM'.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_DOS_FRM'
                                      t_mdata-zzjp_dos_frm.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_APRN'
                                      t_mdata-zzjp_aprn.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_CON_ID'
                                      t_mdata-zzjp_con_id.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_NYU_SOP'
                                      t_mdata-zzjp_nyu_sop.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_WEI_TAB'
                                      t_mdata-zzjp_wei_tab.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_CAR'
                                      t_mdata-zzjp_car.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_CAS'
                                      t_mdata-zzjp_cas.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_CAR_SIZE'
                                      t_mdata-ZZJP_CAR_SIZE.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_CAS_SIZE'
                                      t_mdata-ZZJP_CAS_SIZE.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_RUPQTY'
                                       t_mdata-ZZJP_RUPQTY.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_BIO'
                                      t_mdata-zzjp_bio.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_ITF'
                                      t_mdata-zzjp_itf.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_INIT_LS'
                                      t_mdata-zzjp_init_ls.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_RE1'
                                      t_mdata-zzjp_re1.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_RE2'
                                      t_mdata-zzjp_re2.
        PERFORM f_bdc_field       USING 'MARC-ZZJP_RE3'
                                      t_mdata-zzjp_re3.
        PERFORM f_bdc_field       USING 'BDC_OKCODE'
                                      '/00'.
    *Processing of SD View
        PERFORM f_bdc_dynpro      USING 'SAPLMGMM' '4000'.
        PERFORM f_bdc_field       USING 'BDC_CURSOR' 'MVKE-ZZJP_PRO_ID'.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_PRO_ID'
                                      t_mdata-zzjp_pro_id.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_BU_ID'
                                      t_mdata-zzjp_bu_id.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_ABV_NAME'
                                      t_mdata-zzjp_abv_name.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_ABV_ID1'
                                      t_mdata-zzjp_abv_id1.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_ABV_ID2'
                                      t_mdata-zzjp_abv_id2.
        PERFORM f_bdc_field       USING 'MVKE-ZZJP_SPL_ID'
                                      t_mdata-zzjp_spl_id.
        PERFORM f_bdc_field      USING 'BDC_OKCODE' '/00'.
        PERFORM f_bdc_dynpro      USING 'SAPLSPO1' '0300'.
        PERFORM f_bdc_field       USING 'BDC_OKCODE'
                                      '=YES'.
    perform f_bdc_insert.
    REFRESH T_BDCDATA.
      ENDLOOP.
    ENDFORM.                    " F_PROCESS_BDC
    *&      Form  f_bdc_dynpro
      p_prog is the program name to which data is passed                *
      p_dyno is the screen number to which the data is passed
        Routine for populating the BDCDATA structure with the
        Screen related information
    FORM f_bdc_dynpro USING    p_prog
                               p_dyno.
      t_bdcdata-program  = p_prog.
      t_bdcdata-dynpro   = p_dyno.
      t_bdcdata-dynbegin = 'X'.
      APPEND t_bdcdata.
      CLEAR t_bdcdata.
    ENDFORM.                    " F_bdc_dynpro
    *&      Form  F_BDC_FIELD
          p_fnam is the field name to which value is passed
          p_fval is the field value which is passed
       p_fnam is the field name to which value is passed
       p_fval is the field value which is passed
    FORM f_bdc_field USING    p_fnam
                              p_fval.
      t_bdcdata-fnam = p_fnam.
      t_bdcdata-fval = p_fval.
      APPEND t_bdcdata.
      CLEAR t_bdcdata.
    ENDFORM.                    " F_bdc_field
    *&      Form  F_PROCESS_DATA                                          *
         Routine to used for moving data from T_bpcs internal table to  *
         t_mdata Internal Table                                         *
    FORM f_process_data.
      LOOP AT t_bpcs.
        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
                  input  = t_bpcs-matnr
             IMPORTING
                  output = t_mdata-matnr.
        MOVE t_bpcs-dosage TO t_mdata-zzjp_dos_frm.
        MOVE t_bpcs-appearance TO t_mdata-zzjp_aprn.
        MOVE t_bpcs-idcode  TO t_mdata-zzjp_con_id.
        MOVE t_bpcs-prostformno TO t_mdata-zzjp_nyu_sop.
        MOVE t_bpcs-weitab TO t_mdata-zzjp_wei_tab.
        MOVE c_blank TO t_mdata-zzjp_bio.
        MOVE c_blank TO t_mdata-zzjp_itf.
        MOVE t_bpcs-uom1 TO t_mdata-zzjp_car.
        MOVE t_bpcs-uom2 TO t_mdata-zzjp_cas.
        MOVE t_bpcs-carsize TO t_mdata-zzjp_car_size.
        MOVE t_bpcs-cassize TO t_mdata-zzjp_cas_size.
        MOVE t_bpcs-rupqty TO t_mdata-zzjp_rupqty.
        MOVE c_intls TO t_mdata-zzjp_init_ls.
        MOVE c_blank TO t_mdata-zzjp_re1.
        MOVE c_blank TO t_mdata-zzjp_re2.
        MOVE c_blank TO t_mdata-zzjp_re3.
        MOVE c_blank TO t_mdata-zzjp_pro_id.
        MOVE c_blank TO t_mdata-zzjp_bu_id.
        MOVE t_bpcs-abvname TO t_mdata-zzjp_abv_name.
        MOVE c_blank TO t_mdata-zzjp_abv_id1.
        MOVE c_blank TO t_mdata-zzjp_abv_id2.
        MOVE c_blank TO t_mdata-zzjp_spl_id.
        APPEND t_mdata.
      ENDLOOP.
    ENDFORM.                    " F_PROCESS_DATA
    *&      Form  f_bdc_close
          Routine to close the BDC Session
    FORM f_close_group.
      CALL FUNCTION 'BDC_CLOSE_GROUP'
           EXCEPTIONS
                not_open    = 1
                queue_error = 2
                OTHERS      = 3.
      IF sy-subrc <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " f_close_group
    *&      Form  f_bdc_insert
         routine to input batch data into the Transaction MM02 from the
         session created
    FORM f_bdc_insert.
    CALL FUNCTION 'BDC_INSERT'
             EXPORTING
                  tcode            = c_tcode
             TABLES
                  dynprotab        = t_bdcdata
             EXCEPTIONS
                  internal_error   = 1
                  not_open         = 2
                  queue_error      = 3
                  tcode_invalid    = 4
                  printing_invalid = 5
                  posting_invalid  = 6
                  OTHERS           = 7.
        IF sy-subrc <> 0.
             MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    ENDFORM.                    " f_bdc_insert
    Reward Points if it is helpful
    Thanks
    Seshu

  • List of tables count and Views count in schema wise

    Hi All,
    I want to get all tables count and views count in Schema wise, What is the query for that?
    Thanks in Advance.

    SELECT COUNT(*) FROM sys.tables t join sys.schemas s
    on s.schema_id=t.schema_id
    SELECT COUNT(*) FROM sys.views t join sys.schemas s
    on s.schema_id=t.schema_id
    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

  • Select Count(*) from... returns zero, select * from... returns 4000 recs?

    Hi,
    I have an odd situation where "select count(*) from my_view where some_clause" returns 0, but the exact same query fetching the data (ie "select * from my_view where some_clause") works fine and fetches, correctly, 4000+ records.
    I have tried dropping and recreating the view, and collecting DB stats again, but the problem persists.
    I had a look at the explain plans and they are very different, but both the SQL statements work fine on a copy of the database taken with impdp.
    Does anyone have any suggestions on what might be going on here ?
    Any help would be appreciated, I've run out of ideas !
    Dave
    Edited by: user10281551 on 18-Sep-2008 00:43
    Edited by: user10281551 on 18-Sep-2008 00:44

    Maybe it's the bug that a function based index is present and gets incorrectly used in the select count(*) statement?
    If that's not the case, then please show us more details, like the statement and both execution plans.
    Regards,
    Rob.

  • Alternative for select count('x') or count(*)

    Hi Gurus,
    I need to use select count(*) multiple times in a SP before and after deletion of rows from multiple tables. As this is an expensive method, do we have some alternative for Count(*), like selecting something from a system table or view instead?

    Hi
    You can know the number of rows affected by the DELETE statement in PL/SQL (if you are using PL/SQL) using sql%rowcount. So you don't really need to count the rows again after the delete took place...
    If you are deleting the same rows as selected by the second count condition (older than a particular date), in fact you only need to count rows once for each table.
    Luis

  • "select count(*) from dba_jobs_running" takes 5 minutes to return

    Hi,
    I login as sys or system from sql*plus to run query "select count(*) from dba_jobs_running". This query takes about 5 minutes to run.
    Querying other DBA_* views returns instantly, only this dba_jobs_running view is troubling.
    I have 11 records in dba_jobs, and 18 records in v$lock as usual.
    No error or warning in logfile, no trace file.
    What's possibly wrong with the server?
    Thanks,
    Harry

    Hi,
    The following are the exact statements I used to create the trace file:
    alter session set timed_statistics=true;
    alter session set max_dump_file_size=unlimited;
    alter session set events '10046 trace name context forever, level 12';
    select count(*) from dba_jobs_running;
    exit;
    The content of the trace file is attached at the end.
    If it is CPU bound, I have no activity on the db host. I am solely using it to analyze this problem.
    load averages: 0.02, 0.02, 0.07 22:16:38
    48 processes: 47 sleeping, 1 on cpu
    CPU states: 98.4% idle, 1.6% user, 0.0% kernel, 0.0% iowait, 0.0% swap
    Memory: 1792M real, 983M free, 517M swap in use, 2937M swap free
    PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
    655 oracle 1 59 0 0K 0K sleep 1:14 0.32% oracle
    865 oracle 1 59 0 2072K 1184K cpu 0:00 0.14% top
    667 oracle 1 59 0 0K 0K sleep 0:13 0.08% oracle
    663 oracle 1 59 0 0K 0K sleep 0:27 0.07% oracle
    665 oracle 1 59 0 0K 0K sleep 0:15 0.02% oracle
    671 oracle 1 59 0 0K 0K sleep 0:00 0.02% oracle
    645 oracle 18 59 0 0K 0K sleep 0:23 0.01% oracle
    657 oracle 1 59 0 0K 0K sleep 0:14 0.00% oracle
    649 oracle 1 59 0 0K 0K sleep 0:02 0.00% oracle
    659 oracle 1 59 0 0K 0K sleep 0:01 0.00% oracle
    251 root 20 59 0 3256K 2512K sleep 0:00 0.00% nscd
    70 root 5 59 0 2864K 2096K sleep 0:00 0.00% picld
    224 root 3 59 0 3912K 2008K sleep 0:00 0.00% automountd
    271 root 1 59 0 4408K 1896K sleep 0:00 0.00% sendmail
    588 oracle 1 59 0 2600K 1864K sleep 0:00 0.00% bash
    Any help is greatly appreciated.
    <-- TRACE FILE CONTENT -->
    *** 2006-11-21 21:34:54.413
    *** SESSION ID:(21.832) 2006-11-21 21:34:54.412
    APPNAME mod='[email protected] (TNS V1-V3)' mh=0 act='' ah=0
    =====================
    PARSING IN CURSOR #1 len=69 dep=0 uid=0 oct=42 lid=0 tim=107123626140 hv=2004533713 ad='97219d80'
    alter session set events '10046 trace name context forever, level 12'
    END OF STMT
    EXEC #1:c=0,e=346,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=107123625473
    WAIT #1: nam='SQL*Net message to client' ela= 11 p1=1650815232 p2=1 p3=0
    WAIT #1: nam='SQL*Net message from client' ela= 6476024 p1=1650815232 p2=1 p3=0
    =====================
    PARSING IN CURSOR #1 len=37 dep=0 uid=0 oct=3 lid=0 tim=107130104260 hv=2246554324 ad='97c21958'
    select count(*) from dba_jobs_running
    END OF STMT
    PARSE #1:c=0,e=548,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=107130104237
    BINDS #1:
    EXEC #1:c=0,e=1412,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=107130106034
    WAIT #1: nam='SQL*Net message to client' ela= 12 p1=1650815232 p2=1 p3=0
    *** 2006-11-21 21:40:53.931
    FETCH #1:c=350760000,e=344612113,p=0,cr=2,cu=16652,mis=0,r=1,dep=0,og=4,tim=107474718456
    WAIT #1: nam='SQL*Net message from client' ela= 1936 p1=1650815232 p2=1 p3=0
    FETCH #1:c=0,e=6,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=107474721309
    WAIT #1: nam='SQL*Net message to client' ela= 8 p1=1650815232 p2=1 p3=0
    *** 2006-11-21 21:56:30.972
    WAIT #1: nam='SQL*Net message from client' ela= 915075702 p1=1650815232 p2=1 p3=0
    XCTEND rlbk=0, rd_only=1
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=2 r=0 w=0 time=100535896 us)'
    STAT #1 id=2 cnt=0 pid=1 pos=1 obj=0 op='NESTED LOOPS (cr=2 r=0 w=0 time=100535876 us)'
    STAT #1 id=3 cnt=5550 pid=2 pos=1 obj=0 op='MERGE JOIN CARTESIAN (cr=2 r=0 w=0 time=128639 us)'
    STAT #1 id=4 cnt=10 pid=3 pos=1 obj=0 op='NESTED LOOPS OUTER (cr=2 r=0 w=0 time=5839 us)'
    STAT #1 id=5 cnt=10 pid=4 pos=1 obj=69 op='FIXED TABLE FULL X$KSQRS (cr=0 r=0 w=0 time=4790 us)'
    STAT #1 id=6 cnt=10 pid=4 pos=2 obj=202 op='INDEX UNIQUE SCAN OBJ#(202) (cr=2 r=0 w=0 time=561 us)'
    STAT #1 id=7 cnt=5550 pid=3 pos=2 obj=0 op='BUFFER SORT (cr=0 r=0 w=0 time=90039 us)'
    STAT #1 id=8 cnt=555 pid=7 pos=1 obj=16 op='FIXED TABLE FULL X$KSUSE (cr=0 r=0 w=0 time=1277 us)'
    STAT #1 id=9 cnt=0 pid=2 pos=2 obj=0 op='VIEW (cr=0 r=0 w=0 time=344148954 us)'
    STAT #1 id=10 cnt=105477 pid=9 pos=1 obj=0 op='UNION-ALL (cr=0 r=0 w=0 time=343814331 us)'
    STAT #1 id=11 cnt=105476 pid=10 pos=1 obj=0 op='VIEW (cr=0 r=0 w=0 time=203487737 us)'
    STAT #1 id=12 cnt=105476 pid=11 pos=1 obj=0 op='UNION-ALL (cr=0 r=0 w=0 time=202961626 us)'
    STAT #1 id=13 cnt=0 pid=12 pos=1 obj=272 op='FIXED TABLE FULL X$KDNSSF (cr=0 r=0 w=0 time=13633786 us)'
    STAT #1 id=14 cnt=105476 pid=12 pos=2 obj=72 op='FIXED TABLE FULL X$KSQEQ (cr=0 r=0 w=0 time=188317145 us)'
    STAT #1 id=15 cnt=0 pid=10 pos=2 obj=253 op='FIXED TABLE FULL X$KTADM (cr=0 r=0 w=0 time=76301426 us)'
    STAT #1 id=16 cnt=1 pid=10 pos=3 obj=254 op='FIXED TABLE FULL X$KTCXB (cr=0 r=0 w=0 time=62693462 us)'
    STAT #1 id=16 cnt=1 pid=10 pos=3 obj=254 op='FIXED TABLE FULL X$KTCXB (cr=0 r=0 w=0 time=62693462 us)'
    <---- END of TRACE FILE -->

  • Select count(*) on sql statement returning zero when a matching row exists.

    Our account has an ANSI C application that checks for the existence a row on an Oracle table(s) by using the following SQL:
    int iCount = 0;
    EXEC SQL
    SELECT count(rownum) INTO :iCount
    FROM sys.all_tab_columns
    WHERE table_name IN
    (SELECT table_name FROM
    sys.all_synonyms
    WHERE upper(synonym_name) = upper(:szDestTable))
    AND upper(column_name) = upper(:szColumnName)
    AND owner = 'DBAUSER';
    The bind variables szDestTable and szColumnName are populated with values parsed from columns on another database table. This application is executed through out the day. Occasionally, the application will report a zero in the iCount when there should be a match. I have verified the szDestTable and szColumnName are populated with the correct values which would find a match and they are correct. To make matters even stranger, the application will parse the same input values and find a match (as it should). At some point during the day, and it can be at any time, the application will NOT find a match on the same file, same values. Every subsequent execution of this application will not find a match on the same values. Once the database is brought down and started up in the evening for its normal backups, the application will find a match again on the same values. This problem does not occur every day. I could be a week or a week and a half between incidents.
    I printed the contents of the sqlca.sqqlerrm.sqlerrmc field to a log file. The sqlca.sqlerrm.sqlerrmc field reported an ORA-1405 bind variable was null when the iCount was reporting a zero. When I compiled this application, I set the Proc*C flag to UNSAFE_NULLS=yes since there are other bind variable in the application that can be NULL and that is ok.
    The above SQL is compiled into the C application using the Proc*C compiler. It is compiled using the Oracle 11.2.0.2 libraries. The application is executed against an Oracle 11.2.0.2 database. The database and application are executed on an HP/Unix 11.31 platform.
    This problem did not start occurring until our account went from Oracle 10.2 to Oracle 11.2. Recently, I have changed the SQL to perform a “SELECT COUNT(rownum)” instead of the “SELECT COUNT(*)”. I compiled the application and executed the new application with the SELECT COUNT(rownum) against the same database where the same application with the SELECT COUNT(*) was failing to find a row that actually existed. The application with the SELECT COUNT(rownum) found the matching row as it should have. The new application has been executing in production for about 10 days now without any problems against ten various Oracle 11.2 databases.
    Why would SELECT COUNT(*) and SELECT COUNT(rownum) be any different?

    This forum is about C programming in general, and about using Studio C in particular.
    Your question is about Oracle database programming. You are more likely to find a helpful answer in a forum about database programming. Start here:
    https://forums.oracle.com/forums/category.jspa?categoryID=18

  • 'select count(*) from x' returns 5460 rows and 'Select * from x' returns 0 rows

    As you can see in the next lines something is wrong in my Oracle (8.0.6 on Win NT 4.0 sp 6a) :
    Oracle8 Enterprise Edition Release 8.0.6.0.0 - Production
    With the Partitioning option
    PL/SQL Release 8.0.6.0.0 - Production
    SQLWKS> SELECT * FROM V_TERRA_TE;
    PERIOD_DATE PERIOD_TIME TERRARCV TERRASND TERCV TESND
    0 rows selected.
    SQLWKS> SELECT COUNT(*) FROM V_TERRA_TE;
    COUNT(*)
    5460
    1 row selected.
    V_TERRA_TE is a complex join of 5 Tables :
    CREATE OR REPLACE VIEW "ACTUATE".V_TERRA_TE AS Select to_date(to_char(p1.period_date,'YYYYMMDD'),'YYYYMMDD') "PERIOD_DATE",
    to_date(to_char(p1.period_time,'HH24:MI'),'HH24:MI') "PERIOD_TIME",
    to_number(p1.caudalrcv + ((p3.caudalrcv + p4.caudalrcv)*(confterrate.conexadslterra/confterrate.conexadsltotal))) "TERRARCV",
    to_number(p1.caudalsnd + ((p3.caudalsnd + p4.caudalsnd)*(confterrate.conexadslterra/confterrate.conexadsltotal))) "TERRASND",
    to_number((p2.caudalrcv * confterrate.pctinfonegocio) + ((p3.caudalrcv + p4.caudalrcv)*(confterrate.conexadslte/confterrate.conexadsltotal)))"TERCV",
    to_number((p2.caudalsnd * confterrate.pctinfonegocio) + ((p3.caudalsnd + p4.caudalsnd)*(confterrate.conexadslte/confterrate.conexadsltotal)))"TESND"
    from p1,p2,p3,p4,confterrate
    where (p1.period_date=p2.period_date)and
    (p1.period_date=p3.period_date)and
    (p1.period_date=p4.period_date)and
    (p1.period_time=p3.period_time)and
    (p1.period_time=p4.period_time)and
    (p1.period_time=p2.period_time)and
    to_char(p1.period_date,'MMYYYY')=to_char(confterrate.period_datetime,'MMYYYY');
    I think that some not reported error happens in the select * with some temporary space or similar but only the message '0 rows selected' is displayed (instead the real error)
    Could somebody help me ?
    Thanks in advance
    Francisco

    Forcing the Join/sort to be made on Disk (not on memory) the problem not happens. This demostrate that ORACLE has a VERY IMPORTANT BUG : It returns 0 rows wich is false.
    To force it to work on disk i use this parameters :
    alter session set sort_area_size=0
    alter session set hash_join_enabled=false
    Note : probably is not the best combination or use of parameters, but using it the query works as espected.

  • Select Count(*) and actual row are differ: 136 rows vs 65k x 7 rows

    Dear All,
    Good morning. Need your advices. We had a view which is running and producing output to excel files. But recently after one of ours database migration, it were producing differ result: Select Count(*) and actual row are differ: 136 rows vs 65k x 7 rows. Error happen when we export out the row to csv file is produced 65000 rows x 7 worksheep. But when perform select count(*) from RTNEWWIP, result return: 136 rows.
    Is there any way to trace below sql to find where go wrong?
    The Veiw as below:
    CREATE OR REPLACE VIEW RTNEWWIP
    (FAB_ID, PO, PRD_NO, SHP_PRD_NO, LOT,
    WIP_QTY, ROUTEDESC, IN_TIME, STAY_DAY, BACK_DAY,
    WO_FCST_DATE, SHIP_FCST_DATE, SHIP_CONF_DATE, WS_DATE, ROUTERATIO,
    PROCESS, LOTSTATUS, LOTTYPE, RETICLEVERSION, PROCESSVERSION,
    ROUTESEQUENCE, PRIORITY, PROCESSGEN, PROCESSFAMILY)
    AS
    select
    --ord.order_no,
    'SILTERRA' FAB_ID,
    wip.PO_NUMBER PO,
    wip.FW_DEVICE PRD_NO,
    wip.USER_ITEM_DESCRIPTION SHP_PRD_NO,
    wip.LOT_ID LOT,
    wip.CURR_QTY WIP_QTY,
    wip.STEP_DESC ROUTEDESC,
    to_char(wip.RECORD_START_DATE,'DD-MON-YYYY HH24:MI:SS') IN_TIME,
    to_char((sysdate - wip.RECORD_START_DATE),'9999D99') STAY_DAY,
    to_char((wip.SCHEDULED_COMPLETE_DATE - sysdate),'9999D99') BACK_DAY,
    -- (sysdate - wip.RECORD_START_DATE) STAY_DAY,
    -- (wip.SCHEDULED_COMPLETE_DATE - sysdate) BACK_DAY,
    to_char(wip.SCHEDULED_COMPLETE_DATE,'DD-MON-YYYY') WO_FCST_DATE,
    to_char((wip.SCHEDULED_COMPLETE_DATE + 1),'DD-MON-YYYY') SHIP_FCST_DATE,
    --nvl(oel.attribute15, to_char(sysdate+3650,'DD-MON-YYYY')) SHIP_CONF_DATE,
    to_char(nvl(to_date(oel.attribute15,'DD-MON-YYYY'), sysdate+3650),'DD-MON-YYYY') SHIP_CONF_DATE,
    to_char(wip.LOT_START_DATE,'DD-MON-YYYY') WS_DATE,
    --wip.MASK_NO || '/' || wip.MASK_TOTAL ROUTERATIO,
    '''' ||wip.MASK_NO || '/' || wip.MASK_TOTAL ROUTERATIO,
    wip.PLAN_NAME_ACTIVE PROCESS,
    wip.LOT_STATUS LOTSTATUS,
    wip.LOT_TYPE LOTTYPE,
    0 RETICLEVERSION,
    wip.PLAN_VERSION_ACTIVE PROCESSVERSION,
    0 ROUTESEQUENCE,
    wip.PRIORITY PRIORITY,
    ' ' PROCESSGEN,
    ' ' PROCESSFAMILY
    from wip_report wip, lot_fact lf, order_fact orf, order_dim ord,
    apps.oe_order_headers_all@prod_myfabetl oeh,
    apps.oe_order_lines_all@prod_myfabetl oel
    where wip.CUSTNAME like 'Realtek%'
    --AND WIP.FW_DEVICE like '%R25C'
    and wip.ACTIVE_FACT_KEY = lf.RECORD_KEY
    and lf.ORDER_FACT_KEY = orf.RECORD_KEY
    and orf.ORDER_KEY = ord.RECORD_KEY
    and ord.ORDER_NO = to_char(oeh.order_number)
    and oeh.header_id = oel.header_id
    and orf.LINE_ITEM_NUMBER = to_char(oel.line_number)
    and orf.ITEM_SCHEDULE = to_char(oel.shipment_number)
    and wip.LOT_TYPE in ('ENX','PRA','PRD','PRT','CSK','MPW')
    union all
    select --od.order_no,'
    'SILTERRA' FAB_ID,
    od.CUST_PO PO,
    imd.FW_DEVICE_ID PRD_NO,
    nvl(orf.USER_ITEM_DESCRIPTION, nvl(imd.CUST_DEVICE_ID, imd.FW_DEVICE_ID)) SHP_PRD_NO,
    sfl.LOTID LOT,
    sfl.currentcompqty WIP_QTY,
    'CREATED' ROUTEDESC,
    to_char(to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss'), 'DD-MON-YYYY HH24:MI:SS') IN_TIME,
    --sysdate - to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss') STAY_DAY,
    --to_date(sfl.scheduledcompletedate,'yyyymmdd') - sysdate BACK_DAY,
    to_char(sysdate - to_date(substr(recordstartdate,1, 14), 'yyyymmddhh24miss'),'9999D99') STAY_DAY,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd') - sysdate,'9999D99')BACK_DAY,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd'),'DD-MON-YYYY') WO_FCST_DATE,
    to_char(to_date(sfl.scheduledcompletedate,'yyyymmdd') + 1, 'DD-MON-YYYY') SHIP_FCST_DATE,
    --nvl(oel.attribute15, to_char(sysdate+3650,'DD-MON-YYYY')) SHIP_CONF_DATE,
    to_char(nvl(to_date(oel.attribute15,'DD-MON-YYYY'), sysdate+3650),'DD-MON-YYYY') SHIP_CONF_DATE,
    to_char(to_date(sfl.startdate,'yyyymmdd'), 'DD-MON-YYYY') WS_DATE,
    ' ' ROUTERATIO,
    sfl.tempprocessplan PROCESS,
    sfl.currentstatus LOTSTATUS,
    sfl.currenttype LOTTYPE,
    0 RETICLEVERSION,
    0 PROCESSVERSION,
    0 ROUTESEQUENCE,
    ' ' PRIORITY,
    ' ' PROCESSGEN,
    ' ' PROCESSFAMILY
    from SIL_FW_LOTCREATED_VIEW sfl, order_dim od, order_fact orf, item_master_dim imd,
    apps.oe_order_headers_all@prod_myfabetl oeh,
    apps.oe_order_lines_all@prod_myfabetl oel
    where substr(sfl.salesorderno,1,instr(sfl.salesorderno,'-',1,1)-1)= to_char(od.ORDER_NO)
    and od.RECORD_KEY = orf.ORDER_KEY
    and od.RECORD_CURRENT_FLAG = 1
    and orf.RECORD_CURRENT_FLAG =1
    and to_char(orf.LINE_ITEM_NUMBER) = substr(sfl.salesorderno,instr(sfl.salesorderno, '-',1,1) +1, (instr(sfl.salesorderno, '.',1,1) -1) - instr(sfl.salesorderno, '-',1,1))
    and to_char(orf.ITEM_SCHEDULE) = substr(sfl.salesorderno,instr(sfl.salesorderno, '.',1,1) +1, length(salesorderno) - instr(sfl.salesorderno, '.',1,1))
    and orf.ITEM_MASTER_KEY = imd.RECORD_KEY
    and sfl.customername = 'Realtek'
    and od.ORDER_NO = to_char(oeh.order_number)
    and oeh.header_id = oel.header_id
    and orf.LINE_ITEM_NUMBER = to_char(oel.line_number)
    and orf.ITEM_SCHEDULE = to_char(oel.shipment_number);
    select count(*) from rtnewwip;
    COUNT(*)
    136
    1 row selected

    query might be referring to different environment/schema as you are using database link to access some tables.
    getting result/count from view means executing query which forms that view. try to run that query separately and see the output.
    it may help you to debug

  • Granting SELECT on dictionary views ... (?)

    Hi there,
    please try to find out, what I am doing wrong below:
    1. I connect as sys:
    connect sys as sysdba
    2. Create a role. Just to point out the problem, it will have just CREATE SESSION, CREATE PROCEDURE
    create role tr not identified;
    grant create session to tr;
    grant create procedure to tr;
    3. Now the problem: I want the role (users with that role) to have SELECT privilege, just on one dict-view, that is v$session:
    My first attempt is denied:
    grant select on v$session to tr;
    grant select on v$session to tr
    FEHLER in Zeile 1:
    ORA-02030: can only select from fixed tables/views
    Now this in itself is wierd. I read v$-objects are synonyms to v_$-objects. Is that right? What is the problem here? See, what happens next...
    4. grant select on v_$session to tr;
    That works!
    5. create user tu identified by tu;
    grant tr to tu;
    That works!
    6. Now connect as tu/tu
    sql*plus Test: select count(*) from v$session;
    COUNT(*)
    46
    works!
    7. Now: create a simple stored function to perform the same as my query:
    create or replace function testf
    return number
    is
    res number;
    begin
    select count(*) into res from v$session;
    return res;
    end;
    This is refused with ORA-00942: Table or view does not exist !!!
    Simple query on v$session works, but its usage inside a stored function is not allowed??? Please explain!!!
    Pointing out to the explanation in the documentation (just one link) would suffice. I just have not found an explanation for this behaviour!
    Many thanks in advance!
    Xenofon

    Ok, It seems this GRANT, even though it is an object privilege it is handled like of those privileges, which can be granted only directly to a user and not to a role;
    But on the other hand, the reaction is not the system:
    When you try to grant UNLIMITED tablespace to a role you get a definitive error message: ORA-01931.
    You don't get this error when granting SELECT on V_$SESSION to a role...
    It's getting more and more wierd...
    (Does anyone know a complete list of privs which can only be granted directly to a user? I thought it's only UNLIMITED TABLESPACE)

  • Select count(*) and blank element tags

    Is there a way other than column aliases to produce and return an element tag for the following xsql query.
    <xsql:query
    connection="{@cxn}"
    xmlns:xsql="urn:oracle-xsql">
    select count(*) from emp
    </xsql:query>
    Some databases such as SQL Server via a JDBC driver will return a blank column name, thus you'll have an invalid XML document, however SQL Server allows one to use column aliases, such as select count(*) as "count" from emp.
    However some databases such as Progress via a JDBC-ODBC bridge and ODBC driver does NOT allow column aliases. Thus I'll always get the following response:
    <ERROR>oracle.xml.sql.OracleXMLSQLException: String index out of range: </ERROR>
    Question. Can I substitute an element tag when I encounter a blank column name using an action handler? Any ideas? Sample code?
    Steve.

    Please have the data structure as below:
    <datastructure>
    <GROUP name="G_1" source="Q_TEMP">
    <element value="DEPTNO" name="DEPTNO" />
    <element value="DNAME" name="DNAME" />
    <element value="LOC" name="LOC" />
    <GROUP name="G_2" source="Q_TEMP1">
    <element value="ENAME" name="ENAME" />
    <element value="SAL" name="SAL" />
    *</GROUP>*
    *<element value="G_2.ENAME" name="TOTL_DETAILS" dataType="number" function="COUNT()" />*
    *<element value="G_2.SAL" name="TOTL_SAL" function="SUM()"/>*
    *</GROUP>*
    </datastructure>
    Aggregate functions to be placed at the level you require it. Here you need at G_1, so place it there.

  • How do I execute "Select count(*) from table " in OCI

    Hi,
    I am new to OCI and so this question may seem stupid. I would like to know how to execute the query "select count(*) from <table>" using OCI V8 functionality? Also after how do I get the result into a integer datatype? I have gone through most of the demo programs but is is of little help to me.
    Thanks in advance...
    Regards,
    Shubhayan.

    Hi,
    Here is sample code to give you some idea how to do it. If you want some more info let me know.
    Pankaj
    ub4 count;
    // Prepare the statement.
    char szQry = "SELECT count() FROM T1";
    if(OCI_ERROR == OCIStmtPrepare(pStmthp, pErrhp, (unsigned char*)szQry, strlen(szQry), OCI_NTV_SYNTAX , OCI_DEFAULT) )
         cout << "Error in OCIStmtPrepare" << endl;
         exit(1);
    // Bind the output parameter.
    OCIDefine *pDefnpp;
    if(OCI_ERROR == OCIDefineByPos ( pStmthp, &pDefnpp, pErrhp, 1,
    &count, sizeof(ub4), SQLT_INT,
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
                        OCI_DEFAULT) )
         cout << "Error in OCIDefineByPos" << endl;
         exit(1);
    if(OCI_ERROR == OCIStmtExecute(pSvchp, pStmthp, pErrhp, 1, 0, NULL, NULL, OCI_DEFAULT) )
         cout << "Error in OCIStmtExecute" << endl;
         exit(1);

Maybe you are looking for

  • Upgrading Crystal Reports XI Release 2 to CR 2008: Where is ReportDocument

    I am attempting to upgrade our .NET Crystal Reports code from Crystal Reports XI Release 2 on Visual Studio 2005 SP1 to Crystal Reports 2008 on the same compiler.  We use the ReportDocument interface and I can't seem to find it in the new Crystal Rep

  • Several issues on new AT300-101

    Hey guys. I bought an AT300-101 a week ago, and I have some problem with it. First: I cant make a mass storage mode. Did i miss something? Or i need a special cable to connect to pc and copy files to the tablet (the manufacturer cable does not work?)

  • Having problem with Snow Leopard

    I updated my mac today using Snow Leopard and now I'm having problem with amsn ans Cyberduck.. Is there anyway to have this fixed?

  • Import from Canon 5D does not load

    I imported directly from my Canon 5D via iPhoto. All the images were clearly visible as they imported, but when the import was done, all thumbnails were just blank white squares. Double-clicking on them resulted in a large, low-res "exclamation" icon

  • Merge "Develop Settings" instead of replace?

    Hi there, I know that I can copy develop settings from one photo to another. This overwrites the settings in the target photo. How can I merge the settings of 2 source photos into a third photo? I have certain adjustments in A, certain in B and want