How to use Bulk collect in dynamic SQL with the example below:

My Question is

Using of dynamic SQL with collection in bulkif we pass the name of the table as "to the parameter' function, I want to display those

An array of column names without vowels (replace the vowels by spaces or remove vowels and display).

Please explain for example.

Thank you!!

It's just a predefined type

SQL> desc sys.OdciVarchar2List
 sys.OdciVarchar2List VARRAY(32767) OF VARCHAR2(4000)

You can just as easily declare your own collection type (and you are probably better served declaring your own type of readability if nothing else)

SQL> ed
Wrote file afiedt.buf

  1  CREATE OR REPLACE
  2     PROCEDURE TBL_COLS_NO_VOWELS(
  3                                  p_owner VARCHAR2,
  4                                  p_tbl   VARCHAR2
  5                                 )
  6  IS
  7     TYPE vc2_tbl IS TABLE OF varchar2(4000);
  8     v_col_list vc2_tbl ;
  9  BEGIN
 10      EXECUTE IMMEDIATE 'SELECT COLUMN_NAME FROM DBA_TAB_COLUMNS WHERE OWNER = :1 AND TABLE_NAME = :2 ORDER BY COLUMN_ID'
 11         BULK COLLECT
 12         INTO v_col_list
 13        USING p_owner,
 14              p_tbl;
 15      FOR v_i IN 1..v_col_list.COUNT LOOP
 16        DBMS_OUTPUT.PUT_LINE(TRANSLATE(v_col_list(v_i),'1AEIOU','1'));
 17      END LOOP;
 18*  END;
SQL> /

Procedure created.

SQL> exec tbl_cols_no_vowels( 'SCOTT', 'EMP' );
MPN
NM
JB
MGR
HRDT
SL
CMM
DPTN

PL/SQL procedure successfully completed.

Justin

Tags: Database

Similar Questions

  • Procedure failed when using bulk collect clause and works with the cursor

    Hi all

    I use "BULK collect into" clause in my procedure and it is a failure after 21 minutes and gives the error "end of file communication channel.
    After that this error comes when I tried to connect the database it gives following error.

    ORA-01034 - Oracle is not available.
    ORA - 27101-shared memory realm does not exist.
    SVR4 error: 2: no such file or directory.

    When I use the cursor instead of the COLLECTION in BULK IN the clause, it runs successfully.

    Following the code works with the slider.
    procedure work_kiosk_full (an_jobid in number, ac_sqlcode out varchar2, ac_sqlerrm out varchar2) is

    ld_curr_time Date;

    cursor cur_work_kiosk is
    Select distinct jt.jt_id AS jt_id,
    NVL ((ROUND ((jt_date_completed-jt_date_requested) * 24, 2)))
    ),
    0
    ) AS actual_hrs_to_complete,
    NVL ((ROUND ((jt_date_responded-jt_date_requested) * 24, 2)))
    ),
    0
    ) AS actual_hrs_to_respond,
    peo1.peo_name AS agent_name,
    peo1.peo_user_name AS asagent_soe_id,
    Le.lglent_desc AS ap_system,
    "" AS assign_work_request_comment,
    DECODE (jt.jt_bill_id,
    138802, 'BILLABLE CLIENT. "
    138803, "CONTRACTED"
    "138804, ' BILLABLE IN-HOUSE."
    NULL, ' '
    ) Billable.
    BL.bldg_name_cc BUILDING, bl.bldg_id_ls AS building_id,
    DECODE (bl.bldg_active_cc,
    'Y', 'ACTIVE',
    'INACTIVE '.
    ) AS building_status,
    DECODE (jt.jt_wrk_cause_id,
    141521, "STANDARD WEAR."
    141522, "NEGLIGENCE."
    141523, "ACCIDENTAL."
    141524, "MECHANICAL FAILURE."
    141525, "CONTROL."
    141526, "VANDAL."
    141527, 'STANDARD ',.
    141528, "WORK PROJECT",.
    6058229, "TEST."
    NULL, ' '
    ) AS cause_type,
    ' ' AS comments, peo3.peo_name AS completed_by,
    JT.jt_requestor_email AS contact_email,
    JT.jt_requestor_name_first
    || ' '
    || JT.jt_requestor_name_last AS contact_name,
    JT.jt_requestor_phone AS contact_phone,
    CC.cstctrcd_apcode AS corp_code,
    CC.cstctrcd_code AS cost_center,
    JT.jt_date_closed AS date_closed,
    JT.jt_date_completed AS date_completed,
    JT.jt_date_requested AS date_requested,
    JT.jt_date_responded AS date_responded,
    JT.jt_date_response_ecd AS date_response_ecd,
    JT.jt_date_scheduled AS date_scheduled,
    DECODE (jt.jt_def_id,
    139949, "WTG VENDOR RESPONSE."
    139950, "WAITING ON PARTS."
    139951, "AVAILABILITY OF THE HAND ŒUVRE."
    139952, "WORK DEFERRED-HI PRI."
    139953, "APPROVAL OF WIND TURBINES."
    139954, "FUNDING."
    139955, "ACCESS DENIED."
    139956, "WTG MATERIAL."
    NULL, ' '
    ) AS deferral_reason,
    JT.jt_description as description,
    JT.jt_date_resched_ecd IN the development of the young child,
    FMG.facility_manager AS facility_manager,
    FL.floors_text AS FLOOR, gl.genled_desc AS general_ledger,
    '' AS kiosk_date_requested,' ' AS kiosk_dispatch_confirmed.
    "" AS kiosk_dispatched,
    EQP.equip_customer_code AS linked_equipment_alias,
    EQP.equip_id AS linked_equipment_id,
    EQP.equip_text AS linked_equipment_name,
    DECODE (jt_originator_type_id,
    1000, "PROJECT MOVE REQUEST."
    138834, "CUSTOMER OPEN CORRECTION."
    138835, "OPEN REQUEST CUSTOMER."
    138836, "CORRECTIVE MAINTENANCE",.
    138837, "BOOKING CONFERENCE ROOM."
    138838, "PROJECT INITIATED REQUEST."
    138839, "PLANNED PREVENTATIVE MAINTENANCE."
    138840, "COULD START FREE APPLICATION."
    NULL, ' '
    ) AS originator_type,
    "" AS payment_terms, priority_text AS priority_code,
    swoty.sworktype_text AS problem_type,
    Prop.property_name_cc as a property,
    JT.jt_cost_quote_total AS quote_total,
    par.levels_name IN the region,
    DECODE (jt.jt_repdef_id,
    141534, 'ADJUSTED SETTING. "
    141535, "THE TRAINING OF THE END,"
    141536, "NEW REQUEST"
    141537, "NO INVESTIGATION OF REPAIR."
    141538 "REPLACED PARTS."
    141539, 'REPLACE EQUIPMEN.
    1000699, "NEW REQUEST"
    NULL, ' '
    ) AS repair_definitions,
    JT.jt_repairdesc AS MARKED_COR,
    JT.jt_requestor AS applicant, ' ' AS requestor_cost_center.
    JT.jt_requestor_email AS requestor_email,
    JT.jt_requestor_name_first AS requestor_name,
    JT.jt_requestor_phone AS requestor_phone,
    "" LIKE response_time, rm.room_name_cc ROOM,
    P1.peo_provider_code1 AS service_provider,
    P1.peo_address_1 AS service_provider_address,
    peocity.city_text service_provider_city,
    P1.peo_provider_code1 AS service_provider_code,
    peocity.city_country_name AS service_provider_country,
    peocur.currency_text AS service_provider_currency,
    P1.peo_name AS service_provider_description,
    P1.peo_dispatch_method AS serv_prov_dispatc_hmethod,
    P1.peo_rate_double AS serv_prov_double_time_rate,
    P1.peo_email AS service_provider_email,
    P1.peo_emergency_phone AS serv_prov_emergency_phone,
    P1.peo_fax AS service_provider_fax_number,
    P1.peo_home_phone AS service_provider_home_phone,
    P1.peo_rate_hourly AS service_provider_hourly_rate,
    P1.peo_title AS service_provider_job_title,
    P1.peo_method_id AS service_provider_method,
    P1.peo_cell_phone AS service_provider_mobile_phone,
    P1.peo_pager AS service_provider_pager,
    P1.peo_rate_differential AS service_provider_rates,
    P1.peo_rate_differential AS ser_prov_shift_differential,
    peocity.city_state_prov_text AS serv_prov_state_province,
    DECODE (p1.peo_active,
    'Y', 'ACTIVE',
    'INACTIVE '.
    ) AS service_provider_status,
    P1.peo_url AS serv_prov_web_site_address,
    P1.peo_phone AS service_provider_work_phone,
    P1.peo_postal_code AS serv_prov_zip_postal_code, ' ' shift, as.
    ' ' AS skill,.
    DECODE (jt.jt_bigstatus_id,
    138813, «NEWS»,
    138814 "PENDING."
    138815, 'OPEN ',.
    138816, "END."
    138817, 'CLOSED ',.
    138818, "CANCELLED."
    NULL, ' '
    ) The STATUS,
    Lev.levels_name IN the subregion, ' ' IN the trade.
    P1.peo_ls_interface_code1 AS vendor_id,
    P1.peo_fax AS vendor_purchasing_fax,
    P1.peo_vendor_site_code AS vendor_sitecode,
    JT.jt_id AS vendor_ticket, p1.peo_name AS vendor_companyname,
    JT.jt_requestor_vip AS vip, wo.wo_id AS work_order_no,
    JT.jt_id AS work_request,
    JT.jt_class_id AS work_request_class,
    woty.worktype_text AS work_type, ' ' AS wr_cost.
    JT.jt_description AS wr_description,
    "" AS wr_dispatch_method,
    DECODE (jt.jt_bigstatus_id,
    138813, «NEWS»,
    138814 "PENDING."
    138815, 'OPEN ',.
    138816, "END."
    138817, 'CLOSED ',.
    138818, "CANCELLED."
    NULL, ' '
    ) AS wr_status,
    ctrY.country_name as a country
    OF citi.jobticket jt,.
    Citi.Property prop,
    Citi.Bldg bl,
    Citi.bldg_levels bldglvl,
    civil LEVEL lev,
    civil by LEVELS.
    (SELECT crstools.stragg (peo_name) facility_manager,
    bldgcon_bldg_id
    OF citi.bldg_contacts, citi.people
    WHERE bldgcon_peo_id = peo_id
    AND IN bldgcon_contype_id (40181, 10142)
    FMG GROUP BY bldgcon_bldg_id),
    Citi.floors, fl,
    Citi.Room rm,
    Citi.general_ledger gl,
    the Citi.legal_entity
    Citi.cost_center_codes cc,
    Citi.Equipment eqp,
    Citi.workType woty,
    Citi.subworktype swoty,
    Citi.work_order wo,
    Jtwo Citi.jt_workers,
    Citi.Priority,
    Ctry Citi.Country,
    Citi.People p1,
    Citi.People peo3,
    Citi.People peo1,
    Citi.City peocity,
    Citi.Currency peocur
    WHERE jt.jt_bldg_id = bl.bldg_id
    AND bl.bldg_id = bldglvl.bldg_levels_bldg_id
    AND bldglvl.bldg_levels_levels_id = lev.levels_id
    AND lev.levels_parent = par.levels_id (+)
    AND prop.property_id = bl.bldg_property_id
    AND bl.bldg_active_ls <>' n
    AND jt.jt_floors_id = fl.floors_id (+)
    AND jt.jt_room_id = rm.room_id (+)
    AND jt.jt_bldg_id = fmg.bldgcon_bldg_id (+)
    AND jt.jt_genled_id = gl.genled_id (+)
    AND gl.genled_lglent_id = le.lglent_id (+)
    AND jt.jt_cstctrcd_id = cc.cstctrcd_id (+)
    AND jt.jt_equip_id = eqp.equip_id (+)
    AND jt.jt_id = jtwo.jtw_jt_id (+)
    AND jt.jt_worktype_id = woty.worktype_id (+)
    AND jt.jt_sworktype_id = swoty.sworktype_id (+)
    AND jt.jt_wo_id = wo.wo_id
    AND jt.jt_priority_id = priority_id (+)
    - AND jt.jt_date_requested > = ADD_MONTHS (SYSDATE,-12)
    AND jt.jt_last_update > = ADD_MONTHS (ld_curr_time-12)
    AND bl.bldg_country_id = ctry.country_id
    AND jtwo.jtw_peo_id = p1.peo_id (+)
    AND p1.peo_city_id = peocity.city_id (+)
    AND jt.jt_completed_by_peo_id = peo3.peo_id (+)
    AND p1.peo_rate_currency_id = peocur.currency_id (+)
    AND jt.jt_agent_peo_id = peo1.peo_id (+);


    BEGIN
    run immediately 'truncate table crstools.drt_bom_work_kiosk;
    Select sysdate in double ld_curr_time;
    FOR cur_rec in cur_work_kiosk LOOP
    IF MOD (cur_work_kiosk % rowcount, 10000) = 0 then
    COMMIT;
    END IF;

    INSERT INTO crstools.drt_bom_work_kiosk
    (JT_ID
    ACTUAL_HRS_TO_COMPLETE
    ACTUAL_HRS_TO_RESPOND
    AGENT_NAME
    ASAGENT_SOE_ID
    AP_SYSTEM
    ASSIGN_WORK_REQUEST_COMMENT
    BILLABLE
    BUILDING
    BUILDING_ID
    BUILDING_STATUS
    CAUSE_TYPE
    COMMENTS
    COMPLETED_BY
    CONTACT_EMAIL
    CONTACT_NAME
    CONTACT_PHONE
    CORP_CODE
    COST_CENTER
    DATE_CLOSED
    DATE_COMPLETED
    DATE_REQUESTED
    DATE_RESPONDED
    DATE_RESPONSE_ECD
    DATE_SCHEDULED
    DEFERRAL_REASON
    DESCRIPTION
    DPE
    FACILITY_MANAGER
    FLOOR
    GENERAL_LEDGER
    KIOSK_DATE_REQUESTED
    KIOSK_DISPATCH_CONFIRMED
    KIOSK_DISPATCHED
    LINKED_EQUIPMENT_ALIAS
    LINKED_EQUIPMENT_ID
    LINKED_EQUIPMENT_NAME
    ORIGINATOR_TYPE
    PAYMENT_TERMS
    PRIORITY_CODE
    PROBLEM_TYPE
    PROPERTY
    QUOTE_TOTAL
    REGION
    REPAIR_DEFINITIONS
    MARKED_COR
    APPLICANT
    REQUESTOR_COST_CENTER
    REQUESTOR_EMAIL
    REQUESTOR_NAME
    REQUESTOR_PHONE
    RESPONSE_TIME
    ROOM
    SERVICE_PROVIDER
    SERVICE_PROVIDER_ADDRESS
    SERVICE_PROVIDER_CITY
    SERVICE_PROVIDER_CODE
    SERVICE_PROVIDER_COUNTRY
    SERVICE_PROVIDER_CURRENCY
    SERVICE_PROVIDER_DESCRIPTION
    SERV_PROV_DISPATC_HMETHOD
    SERV_PROV_DOUBLE_TIME_RATE
    SERVICE_PROVIDER_EMAIL
    SERV_PROV_EMERGENCY_PHONE
    SERVICE_PROVIDER_FAX_NUMBER
    SERVICE_PROVIDER_HOME_PHONE
    SERVICE_PROVIDER_HOURLY_RATE
    SERVICE_PROVIDER_JOB_TITLE
    SERVICE_PROVIDER_METHOD
    SERVICE_PROVIDER_MOBILE_PHONE
    SERVICE_PROVIDER_PAGER
    SERVICE_PROVIDER_RATES
    SER_PROV_SHIFT_DIFFERENTIAL
    SERV_PROV_STATE_PROVINCE
    SERVICE_PROVIDER_STATUS
    SERV_PROV_WEB_SITE_ADDRESS
    SERVICE_PROVIDER_WORK_PHONE
    SERV_PROV_ZIP_POSTAL_CODE
    MAJ
    SKILLS
    STATUS
    SUBREGION
    TRADE
    VENDOR_ID
    VENDOR_PURCHASING_FAX
    VENDOR_SITECODE
    VENDOR_TICKET
    VENDOR_COMPANYNAME
    VIP
    WORK_ORDER_NO
    WORK_REQUEST
    WORK_REQUEST_CLASS
    WORK_TYPE
    WR_COST
    WR_DESCRIPTION
    WR_DISPATCH_METHOD
    WR_STATUS
    COUNTRY
    CREATE_DATE
    )
    VALUES
    (cur_rec.jt_id
    cur_rec, ACTUAL_HRS_TO_COMPLETE
    cur_rec, ACTUAL_HRS_TO_RESPOND
    cur_rec, AGENT_NAME
    cur_rec, ASAGENT_SOE_ID
    cur_rec, AP_SYSTEM
    cur_rec, ASSIGN_WORK_REQUEST_COMMENT
    BILLABLE cur_rec.
    cur_rec, BUILDING
    cur_rec, BUILDING_ID
    cur_rec, BUILDING_STATUS
    cur_rec, CAUSE_TYPE
    cur_rec.COMMENTS
    cur_rec.COMPLETED_BY
    cur_rec, CONTACT_EMAIL
    cur_rec, CONTACT_NAME
    cur_rec, CONTACT_PHONE
    cur_rec, CORP_CODE
    cur_rec, COST_CENTER
    cur_rec, DATE_CLOSED
    cur_rec, DATE_COMPLETED
    cur_rec, DATE_REQUESTED
    cur_rec, DATE_RESPONDED
    cur_rec, DATE_RESPONSE_ECD
    cur_rec, DATE_SCHEDULED
    cur_rec, DEFERRAL_REASON
    cur_rec, DESCRIPTION
    cur_rec, DEVELOPMENT OF THE YOUNG CHILD
    cur_rec, FACILITY_MANAGER
    cur_rec, FLOOR
    cur_rec, GENERAL_LEDGER
    cur_rec, KIOSK_DATE_REQUESTED
    cur_rec, KIOSK_DISPATCH_CONFIRMED
    cur_rec, KIOSK_DISPATCHED
    cur_rec, LINKED_EQUIPMENT_ALIAS
    cur_rec, LINKED_EQUIPMENT_ID
    cur_rec, LINKED_EQUIPMENT_NAME
    cur_rec, ORIGINATOR_TYPE
    cur_rec, PAYMENT_TERMS
    cur_rec, PRIORITY_CODE
    cur_rec, PROBLEM_TYPE
    cur_rec, PROPERTY
    cur_rec, QUOTE_TOTAL
    cur_rec, REGION
    cur_rec, REPAIR_DEFINITIONS
    cur_rec, MARKED_COR
    cur_rec, APPLICANT
    cur_rec, REQUESTOR_COST_CENTER
    cur_rec, REQUESTOR_EMAIL
    cur_rec, REQUESTOR_NAME
    cur_rec, REQUESTOR_PHONE
    cur_rec, RESPONSE_TIME
    cur_rec, ROOM
    cur_rec, SERVICE_PROVIDER
    cur_rec, SERVICE_PROVIDER_ADDRESS
    cur_rec, SERVICE_PROVIDER_CITY
    cur_rec, SERVICE_PROVIDER_CODE
    cur_rec, SERVICE_PROVIDER_COUNTRY
    cur_rec, SERVICE_PROVIDER_CURRENCY
    cur_rec, SERVICE_PROVIDER_DESCRIPTION
    cur_rec, SERV_PROV_DISPATC_HMETHOD
    cur_rec, SERV_PROV_DOUBLE_TIME_RATE
    cur_rec, SERVICE_PROVIDER_EMAIL
    cur_rec, SERV_PROV_EMERGENCY_PHONE
    cur_rec, SERVICE_PROVIDER_FAX_NUMBER
    cur_rec, SERVICE_PROVIDER_HOME_PHONE
    cur_rec, SERVICE_PROVIDER_HOURLY_RATE
    cur_rec, SERVICE_PROVIDER_JOB_TITLE
    cur_rec, SERVICE_PROVIDER_METHOD
    cur_rec, SERVICE_PROVIDER_MOBILE_PHONE
    cur_rec, SERVICE_PROVIDER_PAGER
    cur_rec, SERVICE_PROVIDER_RATES
    cur_rec, SER_PROV_SHIFT_DIFFERENTIAL
    cur_rec, SERV_PROV_STATE_PROVINCE
    cur_rec, SERVICE_PROVIDER_STATUS
    cur_rec, SERV_PROV_WEB_SITE_ADDRESS
    cur_rec, SERVICE_PROVIDER_WORK_PHONE
    cur_rec, SERV_PROV_ZIP_POSTAL_CODE
    cur_rec, UPDATE
    cur_rec SKILL.
    cur_rec, STATUS
    cur_rec subregion.
    cur_rec, TRADE
    cur_rec, VENDOR_ID
    cur_rec, VENDOR_PURCHASING_FAX
    cur_rec, VENDOR_SITECODE
    cur_rec, VENDOR_TICKET
    cur_rec, VENDOR_COMPANYNAME
    cur_rec, VIP
    cur_rec, WORK_ORDER_NO
    cur_rec, WORK_REQUEST
    cur_rec, WORK_REQUEST_CLASS
    cur_rec, WORK_TYPE
    cur_rec, WR_COST
    cur_rec, WR_DESCRIPTION
    cur_rec, WR_DISPATCH_METHOD
    cur_rec, WR_STATUS
    cur_rec, COUNTRY
    ld_curr_time
    );
    END LOOP;

    COMMIT;

    exception
    while others then
    Rollback;
    dbms_output.put_line('SQLCODE:'||) SQLCODE. "Error :'|| SQLERRM);

    end work_kiosk_full;

    Note: total record inserted 849000.

    The same code does not work with big collect in would adopt.

    Please help me why this is happening.


    Thanks and greetings
    Shyam ~.

    Shyam,

    I agree with Billy.

    Why are you not using an INSERT..SELECT ?
    
    Also, what are you trying to achieve by
    - incremental commits?
    - copying data from one table to another (using expensive I/O)?
    - using dynamic DML?
    
    Most of these approaches are typically wrong - and not recommended for scalable and performant Oracle applications.
    

    I could see you using a CURSOR for LOOP if you change the data inserted so that you could not encapsulate the changes in a query, but you do an insert in right in the table of your cursor. A much more effective way would be to use the following changes I made to your code sample:

    PROCEDURE WORK_KIOSK_FULL(AN_JOBID   IN NUMBER,
                              AC_SQLCODE OUT VARCHAR2,
                              AC_SQLERRM OUT VARCHAR2) IS
    BEGIN
       EXECUTE IMMEDIATE 'truncate table crstools.drt_bom_work_kiosk';
    
       /* Note:  The APPEND hint forces a Direct Path INSERT (see Link below code sample) and is combined with the NOLOGGING Hint */
       /*        To dramtically increase performance.  The Direct Path INSERT inserts records above the High-Water Mark on the table. */
    
       INSERT /*+ APPEND NOLOGGING */ INTO CRSTOOLS.DRT_BOM_WORK_KIOSK
          (JT_ID
          ,ACTUAL_HRS_TO_COMPLETE
          ,ACTUAL_HRS_TO_RESPOND
          ,AGENT_NAME
          ,ASAGENT_SOE_ID
          ,AP_SYSTEM
    --      ,ASSIGN_WORK_REQUEST_COMMENT     /* I commented out this COLUMN because it doesn't make sense to me to insert */
          ,BILLABLE                          /* a couple of space characters into a table.   If the intent is to leave the column NULL */
          ,BUILDING                          /* don't include it in your INSERT statement and it will be NULL.  If there is a valid reason */
          ,BUILDING_ID                       /* for inserting the spaces, then remove the "line comments" from the insert and select statments */
          ,BUILDING_STATUS
          ,CAUSE_TYPE
    --      ,COMMENTS
          ,COMPLETED_BY
          ,CONTACT_EMAIL
          ,CONTACT_NAME
          ,CONTACT_PHONE
          ,CORP_CODE
          ,COST_CENTER
          ,DATE_CLOSED
          ,DATE_COMPLETED
          ,DATE_REQUESTED
          ,DATE_RESPONDED
          ,DATE_RESPONSE_ECD
          ,DATE_SCHEDULED
          ,DEFERRAL_REASON
          ,DESCRIPTION
          ,ECD
          ,FACILITY_MANAGER
          ,FLOOR
          ,GENERAL_LEDGER
    --      ,KIOSK_DATE_REQUESTED
    --      ,KIOSK_DISPATCH_CONFIRMED
    --      ,KIOSK_DISPATCHED
          ,LINKED_EQUIPMENT_ALIAS
          ,LINKED_EQUIPMENT_ID
          ,LINKED_EQUIPMENT_NAME
          ,ORIGINATOR_TYPE
    --      ,PAYMENT_TERMS
          ,PRIORITY_CODE
          ,PROBLEM_TYPE
          ,PROPERTY
          ,QUOTE_TOTAL
          ,REGION
          ,REPAIR_DEFINITIONS
          ,REPAIR_DESCRIPTION
          ,REQUESTOR
    --      ,REQUESTOR_COST_CENTER
          ,REQUESTOR_EMAIL
          ,REQUESTOR_NAME
          ,REQUESTOR_PHONE
    --      ,RESPONSE_TIME
          ,ROOM
          ,SERVICE_PROVIDER
          ,SERVICE_PROVIDER_ADDRESS
          ,SERVICE_PROVIDER_CITY
          ,SERVICE_PROVIDER_CODE
          ,SERVICE_PROVIDER_COUNTRY
          ,SERVICE_PROVIDER_CURRENCY
          ,SERVICE_PROVIDER_DESCRIPTION
          ,SERV_PROV_DISPATC_HMETHOD
          ,SERV_PROV_DOUBLE_TIME_RATE
          ,SERVICE_PROVIDER_EMAIL
          ,SERV_PROV_EMERGENCY_PHONE
          ,SERVICE_PROVIDER_FAX_NUMBER
          ,SERVICE_PROVIDER_HOME_PHONE
          ,SERVICE_PROVIDER_HOURLY_RATE
          ,SERVICE_PROVIDER_JOB_TITLE
          ,SERVICE_PROVIDER_METHOD
          ,SERVICE_PROVIDER_MOBILE_PHONE
          ,SERVICE_PROVIDER_PAGER
          ,SERVICE_PROVIDER_RATES
          ,SER_PROV_SHIFT_DIFFERENTIAL
          ,SERV_PROV_STATE_PROVINCE
          ,SERVICE_PROVIDER_STATUS
          ,SERV_PROV_WEB_SITE_ADDRESS
          ,SERVICE_PROVIDER_WORK_PHONE
          ,SERV_PROV_ZIP_POSTAL_CODE
    --      ,SHIFT
    --      ,SKILL
          ,STATUS
          ,SUBREGION
    --      ,TRADE
          ,VENDOR_ID
          ,VENDOR_PURCHASING_FAX
          ,VENDOR_SITECODE
          ,VENDOR_TICKET
          ,VENDOR_COMPANYNAME
          ,VIP
          ,WORK_ORDER_NO
          ,WORK_REQUEST
          ,WORK_REQUEST_CLASS
          ,WORK_TYPE
    --      ,WR_COST
          ,WR_DESCRIPTION
    --      ,WR_DISPATCH_METHOD
          ,WR_STATUS
          ,COUNTRY
          ,CREATE_DATE
          )
       VALUES
          (SELECT DISTINCT
              JT.JT_ID AS JT_ID
             ,NVL((ROUND((JT_DATE_COMPLETED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_COMPLETE
             ,NVL((ROUND((JT_DATE_RESPONDED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_RESPOND
             ,PEO1.PEO_NAME AS AGENT_NAME
             ,PEO1.PEO_USER_NAME AS ASAGENT_SOE_ID
             ,LE.LGLENT_DESC AS AP_SYSTEM
    --         ,' ' AS ASSIGN_WORK_REQUEST_COMMENT
             ,DECODE(JT.JT_BILL_ID,138802,'CLIENT BILLABLE'
                                  ,138803,'CONTRACTED'
                                  ,138804,'INTERNAL BILLABLE',NULL,' ') AS BILLABLE
             ,BL.BLDG_NAME_CC AS BUILDING
             ,BL.BLDG_ID_LS AS BUILDING_ID
             ,DECODE(BL.BLDG_ACTIVE_CC, 'Y', 'ACTIVE', 'INACTIVE') AS BUILDING_STATUS
             ,DECODE(JT.JT_WRK_CAUSE_ID,141521,'STANDARD WEAR AND TEAR'
                                       ,141522,'NEGLIGENCE'
                                       ,141523,'ACCIDENTAL'
                                       ,141524,'MECHANICAL MALFUNCTION'
                                       ,141525,'OVERSIGHT'
                                       ,141526,'VANDAL'
                                       ,141527,'STANDARD'
                                       ,141528,'PROJECT WORK'
                                       ,6058229,'TEST',NULL,' ') AS CAUSE_TYPE
    --         ,' ' AS COMMENTS
             ,PEO3.PEO_NAME AS COMPLETED_BY
             ,JT.JT_REQUESTOR_EMAIL AS CONTACT_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST || ' ' ||JT.JT_REQUESTOR_NAME_LAST AS CONTACT_NAME
             ,JT.JT_REQUESTOR_PHONE AS CONTACT_PHONE
             ,CC.CSTCTRCD_APCODE AS CORP_CODE
             ,CC.CSTCTRCD_CODE AS COST_CENTER
             ,JT.JT_DATE_CLOSED AS DATE_CLOSED
             ,JT.JT_DATE_COMPLETED AS DATE_COMPLETED
             ,JT.JT_DATE_REQUESTED AS DATE_REQUESTED
             ,JT.JT_DATE_RESPONDED AS DATE_RESPONDED
             ,JT.JT_DATE_RESPONSE_ECD AS DATE_RESPONSE_ECD
             ,JT.JT_DATE_SCHEDULED AS DATE_SCHEDULED
             ,DECODE(JT.JT_DEF_ID,139949,'WTG VENDOR RESPONSE'
                                 ,139950,'WAITING ON PARTS'
                                 ,139951,'LABOR AVAILABILITY'
                                 ,139952,'DEFERRED- HI PRI WORK'
                                 ,139953,'WTG APPROVAL'
                                 ,139954,'FUNDING REQUIRED'
                                 ,139955,'ACCESS DENIED'
                                 ,139956,'WTG MATERIAL',NULL,' ') AS DEFERRAL_REASON
             ,JT.JT_DESCRIPTION AS DESCRIPTION
             ,JT.JT_DATE_RESCHED_ECD AS ECD
             ,FMG.FACILITY_MANAGER AS FACILITY_MANAGER
             ,FL.FLOORS_TEXT AS FLOOR
             ,GL.GENLED_DESC AS GENERAL_LEDGER
    --         ,' ' AS KIOSK_DATE_REQUESTED
    --         ,' ' AS KIOSK_DISPATCH_CONFIRMED
    --         ,' ' AS KIOSK_DISPATCHED
             ,EQP.EQUIP_CUSTOMER_CODE AS LINKED_EQUIPMENT_ALIAS
             ,EQP.EQUIP_ID AS LINKED_EQUIPMENT_ID
             ,EQP.EQUIP_TEXT AS LINKED_EQUIPMENT_NAME
             ,DECODE(JT_ORIGINATOR_TYPE_ID,1000,'PROJECT MOVE REQUEST'
                                          ,138834,'CUSTOMER INITIATED CORRECTION'
                                          ,138835,'CUSTOMER INITIATED REQUEST'
                                          ,138836,'CORRECTIVE MAINTENANCE'
                                          ,138837,'CONFERENCE ROOM BOOKING'
                                          ,138838,'PROJECT INITIATED REQUEST'
                                          ,138839,'PLANNED PREVENTIVE MAINTENANCE'
                                          ,138840,'SELF INITATED REQUEST',NULL,' ') AS ORIGINATOR_TYPE
    --         ,' ' AS PAYMENT_TERMS
             ,PRIORITY_TEXT AS PRIORITY_CODE
             ,SWOTY.SWORKTYPE_TEXT AS PROBLEM_TYPE
             ,PROP.PROPERTY_NAME_CC AS PROPERTY
             ,JT.JT_COST_QUOTE_TOTAL AS QUOTE_TOTAL
             ,PAR.LEVELS_NAME AS REGION
             ,DECODE(JT.JT_REPDEF_ID,141534,'ADJUSTED SETTING'
                                    ,141535,'TRAINING FOR END'
                                    ,141536,'NEW REQUEST'
                                    ,141537,'NO REPAIR REQUIR'
                                    ,141538,'REPLACED PARTS'
                                    ,141539,'REPLACE EQUIPMEN'
                                    ,1000699,'NEW REQUEST',NULL,' ') AS REPAIR_DEFINITIONS
             ,JT.JT_REPAIRDESC AS REPAIR_DESCRIPTION
             ,JT.JT_REQUESTOR AS REQUESTOR
    --         ,' ' AS REQUESTOR_COST_CENTER
             ,JT.JT_REQUESTOR_EMAIL AS REQUESTOR_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST AS REQUESTOR_NAME
             ,JT.JT_REQUESTOR_PHONE AS REQUESTOR_PHONE
    --         ,' ' AS RESPONSE_TIME
             ,RM.ROOM_NAME_CC AS ROOM
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER
             ,P1.PEO_ADDRESS_1 AS SERVICE_PROVIDER_ADDRESS
             ,PEOCITY.CITY_TEXT SERVICE_PROVIDER_CITY
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER_CODE
             ,PEOCITY.CITY_COUNTRY_NAME AS SERVICE_PROVIDER_COUNTRY
             ,PEOCUR.CURRENCY_TEXT AS SERVICE_PROVIDER_CURRENCY
             ,P1.PEO_NAME AS SERVICE_PROVIDER_DESCRIPTION
             ,P1.PEO_DISPATCH_METHOD AS SERV_PROV_DISPATC_HMETHOD
             ,P1.PEO_RATE_DOUBLE AS SERV_PROV_DOUBLE_TIME_RATE
             ,P1.PEO_EMAIL AS SERVICE_PROVIDER_EMAIL
             ,P1.PEO_EMERGENCY_PHONE AS SERV_PROV_EMERGENCY_PHONE
             ,P1.PEO_FAX AS SERVICE_PROVIDER_FAX_NUMBER
             ,P1.PEO_HOME_PHONE AS SERVICE_PROVIDER_HOME_PHONE
             ,P1.PEO_RATE_HOURLY AS SERVICE_PROVIDER_HOURLY_RATE
             ,P1.PEO_TITLE AS SERVICE_PROVIDER_JOB_TITLE
             ,P1.PEO_METHOD_ID AS SERVICE_PROVIDER_METHOD
             ,P1.PEO_CELL_PHONE AS SERVICE_PROVIDER_MOBILE_PHONE
             ,P1.PEO_PAGER AS SERVICE_PROVIDER_PAGER
             ,P1.PEO_RATE_DIFFERENTIAL AS SERVICE_PROVIDER_RATES
             ,P1.PEO_RATE_DIFFERENTIAL AS SER_PROV_SHIFT_DIFFERENTIAL
             ,PEOCITY.CITY_STATE_PROV_TEXT AS SERV_PROV_STATE_PROVINCE
             ,DECODE(P1.PEO_ACTIVE, 'Y', 'ACTIVE', 'INACTIVE') AS SERVICE_PROVIDER_STATUS
             ,P1.PEO_URL AS SERV_PROV_WEB_SITE_ADDRESS
             ,P1.PEO_PHONE AS SERVICE_PROVIDER_WORK_PHONE
             ,P1.PEO_POSTAL_CODE AS SERV_PROV_ZIP_POSTAL_CODE
    --         ,' ' AS SHIFT
    --         ,' ' AS SKILL
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS STATUS
             ,LEV.LEVELS_NAME AS SUBREGION
    --         ,' ' AS TRADE
             ,P1.PEO_LS_INTERFACE_CODE1 AS VENDOR_ID
             ,P1.PEO_FAX AS VENDOR_PURCHASING_FAX
             ,P1.PEO_VENDOR_SITE_CODE AS VENDOR_SITECODE
             ,JT.JT_ID AS VENDOR_TICKET
             ,P1.PEO_NAME AS VENDOR_COMPANYNAME
             ,JT.JT_REQUESTOR_VIP AS VIP
             ,WO.WO_ID AS WORK_ORDER_NO
             ,JT.JT_ID AS WORK_REQUEST
             ,JT.JT_CLASS_ID AS WORK_REQUEST_CLASS
             ,WOTY.WORKTYPE_TEXT AS WORK_TYPE
    --         ,' ' AS WR_COST
             ,JT.JT_DESCRIPTION AS WR_DESCRIPTION
    --         ,' ' AS WR_DISPATCH_METHOD
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS WR_STATUS
             ,CTRY.COUNTRY_NAME AS COUNTRY
             ,SYSDATE --LD_CURR_TIME
         FROM CITI.JOBTICKET JT,
              CITI.PROPERTY PROP,
              CITI.BLDG BL,
              CITI.BLDG_LEVELS BLDGLVL,
              CITI.LEVELS LEV,
              CITI.LEVELS PAR,
              (SELECT CRSTOOLS.STRAGG(PEO_NAME) FACILITY_MANAGER,
                      BLDGCON_BLDG_ID
                 FROM CITI.BLDG_CONTACTS, CITI.PEOPLE
                WHERE BLDGCON_PEO_ID = PEO_ID
                  AND BLDGCON_CONTYPE_ID IN (40181, 10142)
                GROUP BY BLDGCON_BLDG_ID) FMG,
              CITI.FLOORS FL,
              CITI.ROOM RM,
              CITI.GENERAL_LEDGER GL,
              CITI.LEGAL_ENTITY LE,
              CITI.COST_CENTER_CODES CC,
              CITI.EQUIPMENT EQP,
              CITI.WORKTYPE WOTY,
              CITI.SUBWORKTYPE SWOTY,
              CITI.WORK_ORDER WO,
              CITI.JT_WORKERS JTWO,
              CITI.PRIORITY,
              CITI.COUNTRY CTRY,
              CITI.PEOPLE P1,
              CITI.PEOPLE PEO3,
              CITI.PEOPLE PEO1,
              CITI.CITY PEOCITY,
              CITI.CURRENCY PEOCUR
        WHERE JT.JT_BLDG_ID = BL.BLDG_ID
          AND BL.BLDG_ID = BLDGLVL.BLDG_LEVELS_BLDG_ID
          AND BLDGLVL.BLDG_LEVELS_LEVELS_ID = LEV.LEVELS_ID
          AND LEV.LEVELS_PARENT = PAR.LEVELS_ID(+)
          AND PROP.PROPERTY_ID = BL.BLDG_PROPERTY_ID
          AND BL.BLDG_ACTIVE_LS = 'N'
          AND JT.JT_FLOORS_ID = FL.FLOORS_ID(+)
          AND JT.JT_ROOM_ID = RM.ROOM_ID(+)
          AND JT.JT_BLDG_ID = FMG.BLDGCON_BLDG_ID(+)
          AND JT.JT_GENLED_ID = GL.GENLED_ID(+)
          AND GL.GENLED_LGLENT_ID = LE.LGLENT_ID(+)
          AND JT.JT_CSTCTRCD_ID = CC.CSTCTRCD_ID(+)
          AND JT.JT_EQUIP_ID = EQP.EQUIP_ID(+)
          AND JT.JT_ID = JTWO.JTW_JT_ID(+)
          AND JT.JT_WORKTYPE_ID = WOTY.WORKTYPE_ID(+)
          AND JT.JT_SWORKTYPE_ID = SWOTY.SWORKTYPE_ID(+)
          AND JT.JT_WO_ID = WO.WO_ID
          AND JT.JT_PRIORITY_ID = PRIORITY_ID(+)
             --AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
          AND JT.JT_LAST_UPDATE >= ADD_MONTHS(LD_CURR_TIME, -12)
          AND BL.BLDG_COUNTRY_ID = CTRY.COUNTRY_ID
          AND JTWO.JTW_PEO_ID = P1.PEO_ID(+)
          AND P1.PEO_CITY_ID = PEOCITY.CITY_ID(+)
          AND JT.JT_COMPLETED_BY_PEO_ID = PEO3.PEO_ID(+)
          AND P1.PEO_RATE_CURRENCY_ID = PEOCUR.CURRENCY_ID(+)
          AND JT.JT_AGENT_PEO_ID = PEO1.PEO_ID(+)
          );
    
       COMMIT;
    
    EXCEPTION
       WHEN OTHERS THEN
          ROLLBACK;
          DBMS_OUTPUT.PUT_LINE('SQLCODE :' || SQLCODE || ' Error :' || SQLERRM);
    
    END WORK_KIOSK_FULL;
    

    Here is the link for infor the [Oracle Direct - Path INSERT | http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c21dlins.htm#10778].

    Also, if you are really wanting to use a CURSOR for LOOP COLLECTION in BULK, I suggest you read the article by Steven Feuerstein [PL/SQL practices: GEM VRAC | http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html].

    I hope this helps.
    Craig...

    If my response or response from another person was helpful, please mark accordingly

  • Oracle dynamic SQL with the UNION operator

    Hello

    I have sql string contains two queries separated by the UNION operator. When I run by using DBMS_SQL, it becomes only the first SQL before the UNION operator.

    Can anyone correct how can I Sue UNION in DBMS_SQL?

    Thank you

    Sorry,

    I tested my code

                        BEGIN
                          FOR I IN (SELECT 1 A FROM DUAL UNION
                                  SELECT 2 A  FROM DUAL UNION
                                  SELECT 3 A  FROM DUAL) LOOP
                          DBMS_OUTPUT.PUT_LINE(I.A);
                         END LOOP;
                        END;
                        
    

    and copy this code and PASE to DBMS_SQL. PARSE (all other cases, "... and insert the INSERT STATEMENT but does not erase DBMS_OUTPUT.")

    Edited by: Quluzade Mr. Mahir on February 28, 2011 12:18

  • How to use ODIOUTFILE to generate a file with the specified permission.

    The syntax will be if I want to use ODIOUTFILE to genreate a file under Linux with permissio to owner and group writing reading?


    Thank you

    Good to know who works!

    Be sure to check the answer himself as correct or useful if it helps you...

    Cezar Santos
    http://odiexperts.com

  • change a pl/sql block using "bulk collect.

    Hello

    I have a pl/sql block, short it slows...

    DECLARE

    CURSOR CURUPDATE1 IS

    SELECT MF_TJ. UID_LO

    OF MF_TJ

    WHERE MF_TJ. DTYP (SELECT CD

    OF MF_DOC_TYPE

    WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')

    AND MF_TJ. LINE_TYP IS SET TO NULL;

    BEGIN

    FOR T IN CURUPDATE1

    LOOP

    UPDATE MF_TJ

    THE MF_TJ VALUE. LINE_TYP = "NR."

    WHERE MF_TJ. UID_LO = T.UID_LO;

    UPDATE MF_AJ

    THE MF_AJ VALUE. LINE_TYP = "NR."

    WHERE MF_AJ. TJ_UID_LO = T.UID_LO;

    END LOOP;

    END;

    /

    now I change to use bulk collect, but I split it into two pl/sql blocks (each for an update)

    DECLARE
    CURSOR CURUPDATE1 IS
    SELECT MF_TJ. UID_LO
    OF MF_TJ
    WHERE MF_TJ. DTYP (SELECT CD
    OF MF_DOC_TYPE
    WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')
    AND MF_TJ. LINE_TYP IS SET TO NULL;
    TYPE of recs_type IS the TABLE OF CURUPDATE1% ROWTYPE directory INDEX;
    REB recs_type;
    BEGIN
    CURUPDATE1 OPEN;
    Go SEARCH the CURUPDATE1 COLLECT in BULK IN REB 8000 limit;
    CLOSE CURUPDATE1;
    FORALL i IN 1.recs. COUNTY
    UPDATE MF_TJ
    THE MF_TJ VALUE. LINE_TYP = "NR."
    WHERE MF_TJ. UID_LO = (i) recs. UID_LO;-

    END;
    /


    DECLARE
    CURSOR CURUPDATE1 IS
    SELECT MF_TJ. UID_LO
    OF MF_TJ
    WHERE MF_TJ. DTYP (SELECT CD
    OF MF_DOC_TYPE
    WHERE MF_DOC_TYPE. DTYP_CAT = 'xx')
    AND MF_TJ. LINE_TYP IS SET TO NULL;
    TYPE of recs_type IS the TABLE OF CURUPDATE1% ROWTYPE directory INDEX;
    REB recs_type;
    BEGIN
    CURUPDATE1 OPEN;
    Go SEARCH the CURUPDATE1 COLLECT in BULK IN REB 8000 limit;
    CLOSE CURUPDATE1;
    FORALL i IN 1.recs. COUNTY
    UPDATE MF_AJ
    THE MF_AJ VALUE. LINE_TYP = "NR."
    WHERE MF_AJ. TJ_UID_LO = (i) recs. UID_LO;-
    END;
    /

    Is there a way I can just use pl/sql block using bulk collect?

    Thank you very much

    Hi 5181139

    As Paulzip and Jarkko Turpeinen have pointed out, you could do it using only SQL...

    This is a course using COLLECT in BULK:

    DECLARE
       blimit CONSTANT PLS_INTEGER := 500;
       CURSOR curupdate1 IS
          SELECT MF_TJ.UID_LO
          FROM   MF_TJ
          WHERE  MF_TJ.DTYP IN (SELECT CD
                                FROM MF_DOC_TYPE
                                WHERE MF_DOC_TYPE.DTYP_CAT = 'xx')
          AND MF_TJ.LINE_TYP IS NULL;
       TYPE c_arr IS TABLE OF curupdate1%ROWTYPE;
       c_rows c_arr;
    BEGIN
       OPEN curupdate1;
       LOOP
          FETCH curupdate1 BULK COLLECT INTO c_rows LIMIT blimit;
          FORALL i IN c_rows.FIRST..c_rows.LAST
             UPDATE MF_TJ
             SET    MF_TJ.LINE_TYP = 'NR'
             WHERE  MF_TJ.UID_LO = c_rows(i).uid_lo;
    
          FORALL i IN c_rows.FIRST..c_rows.LAST
             UPDATE MF_AJ
             SET    MF_AJ.LINE_TYP = 'NR'
             WHERE MF_AJ.TJ_UID_LO = c_rows(i).uid_lo;
          EXIT WHEN c_rows.COUNT < blimit;
       END LOOP;
       CLOSE curupdate1;
    END;
    

    See you soon,.

    Gas

  • Using bulk collect into with assistance from the limit to avoid the TEMP tablespace error run out?

    Hi all

    I want to know if using bulk collect into limit will help to avoid the TEMP tablespace error run out.

    We use Oracle 11 g R1.

    I am assigned to a task of creating journal facilitated for all tables in a query of the APEX.

    I create procedures to execute some sql statements to create a DEC (Create table select), and then fires on these tables.

    We have about three tables with more than 26 million records.

    It seems very well running until we reached a table with more than 15 million record, we got an error says that Miss tablespace TEMP.

    I googled on this topic and retrieve the tips:

    Use NO LOG

    Parallel use

    BULK COLLECT INTO limited

    However, the questions for those above usually short-term memory rather than running out of TEMPORARY tablespace.

    I'm just a junior developer and does not have dealed with table more than 10 million documents at a time like this before.

    The database support is outsourced. If we try to keep it as minimal contact with the DBA as possible. My Manager asked me to find a solution without asking the administrator to extend the TEMP tablespace.

    I wrote a few BULK COLLECT INTO to insert about 300,000 like once on the development environment. It seems.

    But the code works only against a 000 4000 table of records. I am trying to add more data into the Test table, but yet again, we lack the tablespace on DEV (this time, it's a step a TEMP data)

    I'll give it a go against the table of 26 million records on the Production of this weekend. I just want to know if it is worth trying.

    Thanks for reading this.

    Ann

    I really need check that you did not have the sizes of huge line (like several K by rank), they are not too bad at all, which is good!

    A good rule of thumb to maximize the amount of limit clause, is to see how much memory you can afford to consume in the PGA (to avoid the number of calls to the extraction and forall section and therefore the context switches) and adjust the limit to be as close to that amount as possible.

    Use the routines below to check at what threshold value would be better suited for your system because it depends on your memory allocation and CPU consumption.  Flexibility, based on your limits of PGA, as lines of length vary, but this method will get a good order of magnitude.

    CREATE OR REPLACE PROCEDURE show_pga_memory (context_in IN VARCHAR2 DEFAULT NULL)

    IS

    l_memory NUMBER;

    BEGIN

    SELECT st. VALUE

    IN l_memory

    SYS.v_$ session se, SYS.v_$ sesstat st, SYS.v_$ statname nm

    WHERE se.audsid = USERENV ('SESSIONID')

    AND st.statistic # nm.statistic = #.

    AND themselves. SID = st. SID

    AND nm.NAME = 'pga session in memory. "

    Dbms_output.put_line (CASE

    WHEN context_in IS NULL

    THEN NULL

    ELSE context_in | ' - '

    END

    || 'Used in the session PGA memory ='

    || To_char (l_memory)

    );

    END show_pga_memory;

    DECLARE

    PROCEDURE fetch_all_rows (limit_in IN PLS_INTEGER)

    IS

    CURSOR source_cur

    IS

    SELECT *.

    FROM YOUR_TABLE;

    TYPE source_aat IS TABLE OF source_cur % ROWTYPE

    INDEX BY PLS_INTEGER;

    l_source source_aat;

    l_start PLS_INTEGER;

    l_end PLS_INTEGER;

    BEGIN

    DBMS_SESSION.free_unused_user_memory;

    show_pga_memory (limit_in |) "- BEFORE"); "."

    l_start: = DBMS_UTILITY.get_cpu_time;

    OPEN source_cur.

    LOOP

    EXTRACTION source_cur

    LOOSE COLLECTION l_source LIMITED limit_in;

    WHEN l_source EXIT. COUNT = 0;

    END LOOP;

    CLOSE Source_cur;

    l_end: = DBMS_UTILITY.get_cpu_time;

    Dbms_output.put_line (' elapsed time CPU for limit of ')

    || limit_in

    || ' = '

    || To_char (l_end - l_start)

    );

    show_pga_memory (limit_in |) "- AFTER");

    END fetch_all_rows;

    BEGIN

    fetch_all_rows (20000);

    fetch_all_rows (40000);

    fetch_all_rows (60000);

    fetch_all_rows (80000);

    fetch_all_rows (100000);

    fetch_all_rows (150000);

    fetch_all_rows (250000);

    -etc.

    END;

  • How to divide a collection of PL/SQL in two?

    Hello

    I try to divide a pl/sql table into two, but ended up with some "nasty" loops

    I was wondering if there was an easier way?
    Session altered.
    SQL> create or replace package my_package
    as
       function my_func(required_number_of_elements in number) 
         return sys.odcinumberlist;
    end my_package;
    Package created.
    SQL> create or replace package body my_package
    as
          
       function my_func(required_number_of_elements in number) 
         return sys.odcinumberlist
       is
          return_list sys.odcinumberlist;
          log_list    sys.odcinumberlist := sys.odcinumberlist();
          
          procedure split_it
          is
    -- Should split list, so 
    --   log_list holds return_list(required_number_of_elements + 1) .. return_list(return_list.count) 
    --   return_list holds return_list(1) .. return_list(required_number_of_elements)           
          begin
             IF required_number_of_elements < return_list.count
             THEN
                log_list.extend(return_list.count - required_number_of_elements);
    
                FOR i IN  required_number_of_elements + 1 .. return_list.count
                LOOP
                  log_list(i - required_number_of_elements) := return_list(i); 
                END LOOP;
                
                return_list.trim(return_list.count - required_number_of_elements);
                
             END IF;
          end split_it;
       begin
    
          select object_id
          bulk collect into return_list
          from all_objects
          where rownum <= 5; -- Disregard, just to simplify example
          
          split_it; -- How to write this?
    
          dbms_output.put_line('return_list.count: ' || return_list.count);
          dbms_output.put_line('log_list.count: ' || log_list.count);            
          return return_list;
       end my_func;
    end my_package;
    Package body created.
    SQL> declare 
      dummy sys.odcinumberlist;
    begin 
      dummy := my_package.my_func(3);
      dummy := my_package.my_func(10);
    end;
    return_list.count: 3
    log_list.count: 2
    return_list.count: 5
    log_list.count: 0
    PL/SQL procedure successfully completed.
    BANNER                                                          
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selected.
    Concerning
    Peter

    Published by: Peter on May 13, 2009 02:01
    Banner added

    How to divide a collection of PL/SQL in two?

    Just copy and DELETE the part of the original Collection:

    SQL> declare
       c1 sys.dbms_debug_vc2coll;
       c2 sys.dbms_debug_vc2coll;
    begin
       select to_char (level)
       bulk collect
       into c1
       from dual
       connect by level <= 10;
    
       c2 := c1;
       c1.delete (1, 5);
       c2.delete (6, 10);
    
       for i in c1.first .. c1.last
       loop
          dbms_output.put_line ('C1: ' || c1 (i));
       end loop;
    
       for i in c2.first .. c2.last
       loop
          dbms_output.put_line ('C2: ' || c2 (i));
       end loop;
    end;
    /
    C1: 6
    C1: 7
    C1: 8
    C1: 9
    C1: 10
    C2: 1
    C2: 2
    C2: 3
    C2: 4
    C2: 5
    PL/SQL procedure successfully completed.
    
  • Tables created in a stored procedure cannot be used with dynamic SQL? The impact?

    There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?

    If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).

    In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?

    Thank you and best regards,
    Amedeo.

    Published by: AGF on March 17, 2009 10:51

    AGF says:
    Hi, Frank.

    Thank you for your response. I understand that the dynamic SQL is required in this context.

    Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.

    In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.

    I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.

    The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).

    If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.

    With the TWG, you have none of these issues.

    Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)

    When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.

    Another risk of dynamic query is SQL injection which may result in a security risk on the database.

    Good programming will have little need for the tables of dynamically created dynamically or SQL.

  • Dynamic SQL with dynamic identifiers

    Oracle 10gXE

    I have a table that is used to track student attendance. If the student is present on a given day, a record is inserted with the student ID and the date they frequented.

    presence of DESC
    Name of Type Null
    --------------- -------- ------
    ID NOT NULL NUMBER
    NUMBER OF STUDENT_ID
    SITE_ID NUMBER
    DATE OF ATTENDANCE_DATE

    I want to view a report (in TOP) which shows all students for a given site, the days when school was in session for this month (not Saturday, Sunday) and a X for the student who participated in that day or a null value if they do not have.

    ID # FNAME LNAME 3 4 5 6 7 10
    38754636 POE JANE X X X
    81248754 DOE KAYLA X X X X X
    43127409 RAO JOHN X X X X X

    In this example, days 3 and 7 of the month are from Monday to Friday and 8-9 have been excluded because they are on Saturday and Sunday.

    I am trying to find a way to dynamically generate a query for any month/year and returning to a report. The obstacle is that given that I don't know in advance which days in a month will be excluded, the identifiers in my select statement are not fixed.

    I found a query that returns a list of day numbers and dates for a given month. It looks like this:

    SELECT LEVEL lv, TO_DATE (TO_CHAR (LEVEL, '09')
    || TO_CHAR (EXTRACT (TO_DATE('01-SEP-11') MONTHS), '09')
    || To_char (EXTRACT (TO_DATE('01-SEP-11') YEAR), ' 9999'), 'dd.mm.yyyy') mon_day
    OF double WHERE ROWNUM < = EXTRACT (DAY OF LAST_DAY (TO_DATE('01-SEP-11')))
    CONNECT BY LEVEL = ROWNUM

    I combined this request with another brings my student attendance data and results that pivots in what I need. Then, I created a function that accepts the month and year as parameters and creates the combined request.

    SELECT c.ID student_id, c.last_name, c.first_name,.
    MAX (decode (mon_day, ' 01 - SEPT.-11', 'X', NULL)) '1', MAX (decode (mon_day, ' 02 - SEVEN.-11', 'X', NULL)) '2 ',.
    MAX (decode (mon_day, ' 05 - SEPT.-11', 'X', NULL)) '5', MAX (decode (mon_day, ' 06 - SEPT.-11', 'X', NULL)) "6."
    MAX (decode (mon_day, ' 07-SEP-11', 'X', NULL)) '7', MAX (decode (mon_day, ' 08 - SEPT.-11', 'X', NULL)) "8."
    MAX (decode (mon_day, ' 09 - SEPT.-11', 'X', NULL)) '9', MAX (decode (mon_day, 12-SEP-11', 'X', NULL)) "12."
    MAX (decode (mon_day, 13-SEP-11', 'X', NULL)) '13', MAX (decode (mon_day, 14-SEPT-11', 'X', NULL)) "14."
    MAX (decode (mon_day, 15-SEP-11', 'X', NULL)) '15', MAX (decode (mon_day, 16-SEP-11', 'X', NULL)) "16."
    MAX (decode (mon_day, 19-SEP-11', 'X', NULL)) '19', MAX (decode (mon_day, 20-7.-11', 'X', NULL)) "20."
    MAX (decode (mon_day, 21-SEP-11', 'X', NULL)) "21", MAX (decode (mon_day, 22-SEP-11', 'X', NULL)) '22 ',.
    MAX (decode (mon_day, 23-SEP-11', 'X', NULL)) '23', MAX (decode (mon_day, 26-SEP-11', 'X', NULL)) "26."
    MAX (decode (mon_day, 27-SEP-11', 'X', NULL)) '27', MAX (decode (mon_day, 28-SEP-11', 'X', NULL)) "28."
    MAX (decode (mon_day, 29-SEP-11', 'X', NULL)) '29', MAX (decode (mon_day, 30-SEP-11', 'X', NULL)) '30 '.
    (SELECT level lv, TO_DATE (TO_CHAR (LEVEL, '09')
    || TO_CHAR (EXTRACT (TO_DATE('01-SEP-11') MONTHS), '09')
    || To_char (EXTRACT (TO_DATE('01-SEP-11') YEAR), ' 9999'), 'dd.mm.yyyy') mon_day
    OF double WHERE ROWNUM < = EXTRACT (DAY OF LAST_DAY (TO_DATE('01-SEP-11')))
    CONNECTION LEVEL = ROWNUM) a, b of attendance, student c
    WHERE to_char(MON_DAY,'D') NOT IN (1.7)
    AND A.mon_day = b.attendance_date
    AND b.student_id = c.ID
    Group of c.ID, student_id, c.last_name, c.first_name

    Now I'm stuck on what I can pass this request in to get my result. What I've read, dynamic SQL method 4 would work if I incorporate Pro/C. I hope this isn't my only option. I have considered to try to do this in a function table in pipeline, but since the columns returned are not known in advance, I can't create a corresponding data type.

    I'm starting to wonder if I forgot a simpler method to achieve this.

    Published by: David Sumner on April 12, 2012 18:52

    Ignoring the actual query and looking at the dynamic SQL part of the question.

    There are 3 ways to run a dynamic select SQL in PL/SQL code.

    immediate execution requires a fixed number of bind variables, linking him in position and translates a single implicit output cursor extraction - requiring the projection of cursor to be known at the time of coding.

    REF CURSOR are essentially the same - the only exception being that it requires an extraction explicit coding process output cursor.

    DBMS_SQL differs in all of these respects. The connection is by name and not position. The connection is dynamic. Projection of the cursor must not be known at the time of coding. It is dynamically determined at runtime and fetch offers of release of the cursor with the projection of unknown SQL - coding time.

    Apex uses DBMS_SQL internally (in fact he uses DBMS_SYS_SQL properly run dynamic and specific patterns of Oracle SQL, as if a session connected as a scheme runs the SQL code). This allows the Apex to take a dynamic SQL that you enter a region (which can contain a variable number of bind variable), run it and make the projection of the cursor as an HTML report.

    Apex supports in turn also dynamic SQL - what you (Apex developer) to provide a dynamic SQL code for a region, instead of you having to provide SQL fixed (with bind variable) for the region in question.

    As Apex creates DBMS_SQL sliders, it doesn't have your SQL as a ref cursor or cursor DBMS_SQL. All they need is the source of the SQL statement. And that's what you create dynamically.

    So in the Apex, dynamic SQL means using a function from PL/SQL to return the source for Apex SQL analyze like a slider DBMS_SQL - instead of coding the source SQL statement in a fixed statement.

    So, using the option of function for an area considered in the Apex, allows you to provide the following in the code that must run to get the SQL statement for the report Apex (Apex running this as a dynamic function that returns a string):

    --// return the dynamic SQL for the report region
    return(
      case
        when :P1_OPTION = 1 then
          'select * from emp'
    
        when :P1_OPTION = 2 then
          'select * from dept where dept_id = :P1_DEPT_ID'
      end
    );
    

    You can also write a PL/SQL function that is stored in the database and call this function so that it can determine what is the dynamic SQL source code statement. For example

    --// calling database function to return the dynamic SQL for the report region
    return(
      GetDynamicReportSQL( page => 1, option => :P1_OPTION )
    );
    

    Dynamic SQL is fully supported by Apex - but does not require that you, the developer, to create the dynamic cursor and treat the dynamic linking and dynamic recovery of this slider.

    All you have to do is to provide the source code of this dynamic SQL (including the bind variable) to the Apex and it will do the whole thing from cursor for you.

  • How to use system recovery after OS change to the g4 pavilion 1305 to the

    Hello

    My name is SUNIL GUPTA

    I have laptop model g4 1305-UA Pavilion, preinstalled OS Win7 Home Basic 64 Bit.

    I was changed for Win 7 Ultimate 64 Bit with clean install.

    And now I want to reinstall Windows 7 64 Basic Home Edition.

    Am that I reinstall with my recovery disks or not?

    and if so please tell me...

    Hello

    You can use the following method to create your own family Windows 7 Edition installation disk basic 64-bit.

    Before you try the following, make sure that you can always read the character product activation key 25 on your label Windows COA (5 blocks of 5 alphanumeric games).

    An example of a COA label can be seen here.

    You can create a Windows 7 installation disc yourself using another PC. However, it not there no download directly available for Windows 7 Home Basic Edition, so you'll need to download another version (one will do, but the link below is for Windows 7 Home Premium 64-bit - the source is Digital River).

    Windows 7 Home Premium SP1 64-bit

    For the key on your label of COA to work, you must now use the method described in the following link to convert this ISO to an all-version Installer.

    http://www.SevenForums.com/tutorials/85813-Windows-7-universal-installation-disc-create.html

    Once that is done, use an application like ImgBurn to burn the ISO correctly on a blank DVD - a guide on the use of ImgBurn to write an ISO on a disc is here.

    Use the disk to perform the installation, enter the activation key of Windows on the label of the COA at the request and once the installation is complete, use ' 'phone Method' described in detail in the link below to activate the operating system -this made method supported by Microsoft and is popular with people who want to just have a new installation of Windows 7 without additional software load normally comes with OEM installations.

    http://www.kodyaz.com/articles/how-to-activate-Windows-7-by-phone.aspx

    You could possibly need for your laptop can be found, additional drivers and software here.

    Best regards

    DP - K

  • How to use several adf 12 shape and insert the form data in to table during the click on "submit" button

    How to use several adf 12 shape and insert the form data in to table during the click on "submit" button. Can we use several form from adf or not?

    Make sure that you dragged the VO based EO.

    Also make sure that the VO attributes based EO Updatable property.

    The query according to VO is used only to add LOV to the column of the original VO ModelId.

    See you soon

    AJ

  • How can I use a vector image to stretch with the background in Muse master pages?

    How can I use a vector image to stretch with the background in Muse master pages?

    Click on the 'Fill' text not the drop-down arrow.

  • Dynamic SQL with a Ref Cursor

    Hello

    I have a package that returns a Ref Cursor, in this procedure, I have a dynamic sql code that is built according to certain values, and the query is a select query, is it possible that I can put that dynamic sql in the ref cursor and return of the procedure.

    Or y at - it no alternative better workaround.

    Thanks in advance.

    Naveen

    Yes you can.

    Try this...

    create or replace package test_pack is
    type ref_cur is ref cursor;
    procedure just_print(ref_var ref_cur);
    end;
    /
    
    create or replace package body test_pack is
    procedure just_print(ref_var ref_cur) is
    l_var emp%rowtype;
    begin
    loop
    fetch ref_var into l_var;
    exit when ref_var%notfound;
    dbms_output.put_line(l_var.ename);
    end loop;
    end;
    end;
    /
    
    declare
    cur_var test_pack.ref_cur;
    dsql varchar2(100);
    begin
    dsql := 'select * from emp where deptno=10';
    open cur_var for dsql;
    test_pack.just_print(cur_var);
    end;
    /
    CLARK
    KING
    MILLER
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.00
    

    Kind regards
    Prazy

  • How to use &lt; C:when test... inside the column in the table of the ADF

    I use ADF table with two columns
    in the first column, I check the Type of document is doc type so I have to use commondlink to download this file, otherwise I need to display only text.

    to this I added
    * < c:when test = "{boolean ($favoriteType eq 'doc')}" > *.
    that does not work.

    Please let me know how to use < C:when test... inside the column in the table of the ADF

    < tr:column sortProperty = "favoriteName" sortable = "true".
    headerText = "#{res ['favorite.favoritename ']}" "
    width = "500" noWrap = "false" >
    < c: choose >
    * < c:when test = "{boolean ($favoriteType eq 'doc')}" > *.
    < tr:commandLink actionListener = "#{bindings.downloadFile.execute} '"
    Text = "#{row.favoriteName} '"
    Disabled = "#{!}" Bindings.downloadFile.Enabled}"/ >
    < / c:when >
    < c: otherwise >
    < af:outputText value = "#{row.favoriteName}" / >
    < / c: otherwise >
    < / c: choose >
    < / tr:column >
    < tr:column sortProperty = "favoriteType" sortable = "true".
    headerText = "#{res ['favorite.favoriteType ']} ' rendering ="true">"
    < af:outputText value = "#{row.favoriteType}" id = "favoriteType" / > "
    < / tr:column >

    Hello

    I do not see, you use a Table of the ADF, but I see that you use Apache Trinidad. JSTL is executed analysis of time then that JSF is to render time, that's why it does not work what you see. Trinidad is a part of tr:switcher, and you can try this. Note that it doesn't ' r allow to change components by rank.

    Frank

  • How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and

    I have a table whose columns with values such as

    MINNEAŸPOLIS and ¿VV ¿A

    Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.

    Please help to write a SQL SELECT with Regexp_like query or any other option.

    Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.

    SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;

Maybe you are looking for