Refining SQL Replacement for Oracle's WM_CONCAT Function (Pivoting Rows to column)

Greetings,
I am moving a query from Oracle SQL to Microsoft SQL and am having some difficulty with the transition. Part of my code (listed here) used to pivot the data and display RESULT_VALUE 
by the CPI_SEQ . In Oracle this was easy to do by using the function: WM_CONCAT.
I have been ‘Googling’ for the non-Oracle way to achieve this and stumbled on to the “STUFF((SELECT…)”
 method. This almost works for me except that it places everything into one cell, whereas
 I need to concatenate  RESULT_VALUE by CPI_SEQ (the CPI_SEQ is the unique ID). The current code gives me this:
RESULTS
Anxiety, Depression, Diabetes, 
COPD, ARDS
Whereas I want  my code to present it this way instead
CPI_SEQ                              
RESULTS
22                                          
Anxiety, Depression
44                                          
Diabetes
46                                          
COPD, ARDS
SELECT (STUFF((SELECT ',' + RESULT_VALUE
FROM
SELECT DISTINCT
C1.CPI_Seq AS CPI_SEQ,C1.Result_Value AS RESULT_VALUE
,count(FCurrent.Field_Name) "Current"
,count(FPast.Field_Name) "Past"
,Count(*) Count
,CASE
When count(FCurrent.Field_Name) > 0 and count(FPast.Field_Name) >0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT(C1.Result_Value,'(C/P)')
When count(FCurrent.Field_Name) > 0 and count(FPast.Field_Name) =0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT (C1.Result_Value,'(C)')
When count(FCurrent.Field_Name) = 0 and count(FPast.Field_Name) >0 and count(Fcurrent.Field_Name)+ count(FPast.Field_Name) = Count(C1.PF_RESULT_SEQ) Then CONCAT(C1.Result_Value,'(P)')
End Result
From
[AnalyticsDW].[dbo].[rr_stag_PF_Results] A1
join [AnalyticsDW].[dbo].[rr_stag_PF_Results] C1 on A1.PF_Result_Seq = C1.PF_Result_Seq
join [AnalyticsDW].[dbo].[rr_PF_Fields_Dept] FCurrent on A1.PF_Result_Seq = FCurrent.RES_SEQ
AND FCurrent.Field_Name = 'Current'
AND A1.Label_Seq in('187582', '187576','187612','187600','187618','187612')
left join [AnalyticsDW].[dbo].rr_PF_Fields_Dept FPast on A1.PF_Result_Seq = FPast.Res_Seq
AND FPast.Field_Name = 'Past'
AND A1.Label_Seq in('187583', '187577','187613','187601','187619','187613')
WHERE
A1.Result_Value ='Yes'
AND (C1.Result_Value in ('Dyspnea', 'Confusion','Pressure Ulcer', 'Stasis Ulcer','Depression','Anxiety'))
GROUP BY
C1.CPI_Seq,
C1.Result_Value
) L1
FOR XML PATH('')),1,2,'')) RESULTS

;With CTE
AS
SELECT
C1.CPI_Seq AS CPI_SEQ,
C1.Result_Value AS RESULT_VALUE
From
[AnalyticsDW].[dbo].[rr_stag_PF_Results] A1
join [AnalyticsDW].[dbo].[rr_stag_PF_Results] C1 on A1.PF_Result_Seq = C1.PF_Result_Seq
join [AnalyticsDW].[dbo].[rr_PF_Fields_Dept] FCurrent on A1.PF_Result_Seq = FCurrent.RES_SEQ
AND FCurrent.Field_Name = 'Current'
AND A1.Label_Seq in('187582', '187576','187612','187600','187618','187612')
left join [AnalyticsDW].[dbo].rr_PF_Fields_Dept FPast on A1.PF_Result_Seq = FPast.Res_Seq
AND FPast.Field_Name = 'Past'
AND A1.Label_Seq in('187583', '187577','187613','187601','187619','187613')
WHERE
A1.Result_Value ='Yes'
AND (C1.Result_Value in ('Dyspnea', 'Confusion','Pressure Ulcer', 'Stasis Ulcer','Depression','Anxiety'))
GROUP BY
C1.CPI_Seq,
C1.Result_Value
SELECT CPI_Seq,
STUFF((SELECT ',' + Result_Value
FROM CTE
WHERE CPI_Seq = c.CPI_Seq
FOR XML PATH(''),TYPE).value('.','varchar(max)'),1,1,'') AS Results
FROM (SELECT DISTINCT CPI_Seq FROM CTE)c
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Help out:SQL Assistant for oracle

    Any time i use the logminer utility from the SQLaps SQL Assistant for oracle to query either my redo or archive logs i get this error, but the dictionary.txt file exist in the location specified;
    Please help out with details on how to solve this error:
    ORA-01284: file C\oracle\product\10.2.0\db_1\dictionary.txt cannot be opened
    ORA-06512: at "SYS.DBMS_LOGMNR", line 58
    ORA-06512: at line 1
    kindly help out on the reason for this error and detailed steps to solve this issue

    NAIJA-EXBOY wrote:
    That is how the error appears when you use the GUI utility for the logminer to query the alert logs,
    Does anybody have ideas on how logminer utility works using this software "SQL Assistant for oracle""SQL Assistant for Oracle" doesn't seem to be a tool provided by Oracle, but a third-party tool. Therefore I suggest you contact their technical support for your inquiry.
    As a workaround, as already suggested, you might want to use the DBMS_LOGMNR package to use the LogMiner. It's not that complicated at all and just needs a couple of calls to the DBMS_LOGMNR and optionally DBMS_LOGMNR_D packages. You can check the documentation on how to use it.
    If you have Oracle Enterprise Manager you could access the LogMiner interface using the Java Console version prior to 11g.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Ocacle 12c with SQL navigator for Oracle

    Hi, Could anyone help me out. I have recently installed the Oracle 12c on my personal laptop. Trying to connect the oracle database from SQL Navigator for oracle but couldn't succeed

    874cb721-f132-4cea-b60b-c221071f680c wrote:
    Hi, Could anyone help me out. I have recently installed the Oracle 12c on my personal laptop. Trying to connect the oracle database from SQL Navigator for oracle but couldn't succeed
    I tried to make my car go but couldn't succeed.
    Tell me how to make my car go.
    How do I ask a question on the forums?
    https://forums.oracle.com/message/9362002#9362002

  • Pivoting rows into columns in Oracle 10g

    Hi,
    I want to pivot rows into column in some optimal way.
    I don't want to go with the DECODE option as the number of columns can be more than 200.
    i have also tried the transpose logic which is making the pl/sql block too huge.
    can i directly query the database for the desired output instead of storing the data into some arrays and displaying rows as columns?

    Hi,
    Here's a dynamic way to do this is Oracle 10, using theSQL*Plus @ command to handle the dynamic parts.
    First, let's see how we would do this using a static query:
    WITH     col_cntr    AS
         SELECT     column_name
         FROM     all_tab_columns
         WHERE     owner          = 'FKULASH'
         AND     table_name     = 'TEST_EMP'
         AND     column_name     NOT IN ('EMP_ID', 'TYPE_VAL')
    ,     unpivoted_data     AS
         SELECT     e.type_val
         ,     c.column_name
         ,     CASE c.column_name
                  WHEN  'X_AMT'  THEN  x_amt     -- *****  Dynamic section 1  *****
                  WHEN  'Y_AMT'  THEN  y_amt     -- *****  Dynamic section 1  *****
                  WHEN  'Z_AMT'  THEN  z_amt     -- *****  Dynamic section 1  *****
              END     AS v
         FROM          test_emp  e
         CROSS JOIN     col_cntr  c
    SELECT       column_name     AS type_val
    ,       SUM (CASE WHEN type_val = 'Q1' THEN v ELSE 0 END)     AS q1     -- ***** Dynamic section 2  *****
    ,       SUM (CASE WHEN type_val = 'Q2' THEN v ELSE 0 END)     AS q2     -- ***** Dynamic section 2  *****
    ,       SUM (CASE WHEN type_val = 'Q3' THEN v ELSE 0 END)     AS q3     -- ***** Dynamic section 2  *****
    ,       SUM (CASE WHEN type_val = 'Q4' THEN v ELSE 0 END)     AS q4     -- ***** Dynamic section 2  *****
    FROM       unpivoted_data
    GROUP BY  column_name
    ORDER BY  column_name
    ;Column names are hard-coded in two places:
    (1) in the sub-query unpivoted_data, we had to know that there were 3 columns to be unpivoted, and that they were called x_amt, y_amt and z_amt. You want to derive all of that from all_tab_columns.
    (2) in the main query, we had to know that there would be 4 pivoted columns in the rsult set, and that they would be called q1, q2, q3 and q4. You want to derive all that from the data actually in test_emp.
    Instead of hard-coding those 2 dynamic sections, have Preliminary Queries write them for you, a split second before you run the main query, by running this script:
    --  Before writing sub-scripts, turn off features designed for human readers
    SET     FEEDBACK    OFF
    SET     PAGESIZE    0
    PROMPT *****  Preliminary Query 1  *****
    SPOOL     c:\temp\sub_script_1.sql
    SELECT    '              WHEN  '''
    ||       column_name
    ||       '''  THEN  '
    ||       LOWER (column_name)     AS txt
    FROM       all_tab_columns
    WHERE       owner          = 'FKULASH'
    AND       table_name     = 'TEST_EMP'
    AND       column_name     NOT IN ('EMP_ID', 'TYPE_VAL')
    ORDER BY  column_name
    SPOOL     OFF
    PROMPT     *****  Preliminary Query 2  *****
    SPOOL     c:\temp\sub_script_2.sql
    SELECT DISTINCT  ',       SUM (CASE WHEN type_val = '''
    ||                type_val
    ||           ''' THEN v ELSE 0 END)     AS '
    ||           LOWER (type_val)          AS txt
    FROM           test_emp
    ORDER BY      txt
    SPOOL     OFF
    --  After writing sub-scripts, turn on features designed for human readers
    SET     FEEDBACK    5
    SET     PAGESIZE    50
    -- Main Query:
    WITH     col_cntr    AS
         SELECT     column_name
         FROM     all_tab_columns
         WHERE     owner          = 'FKULASH'
         AND     table_name     = 'TEST_EMP'
         AND     column_name     NOT IN ('EMP_ID', 'TYPE_VAL')
    ,     unpivoted_data     AS
         SELECT     e.type_val
         ,     c.column_name
         ,     CASE c.column_name
                  @c:\temp\sub_script_1
              END     AS v
         FROM          test_emp  e
         CROSS JOIN     col_cntr  c
    SELECT       column_name     AS type_val
    @c:\temp\sub_script_2
    FROM       unpivoted_data
    GROUP BY  column_name
    ORDER BY  column_name
    ;As you can see, the main query looks exactly like the static query, except that the two dynamic sections have been replaced by sub-scripts. These 2 sub-scripts are written by 2 prelimiary queries, right before the main query.
    As others have said, the fact that you're asking this question hints at a poor table design. Perhaps the table should be permanently stored in a form pretty much like unpivoted_data, above. When you need to display it with columns x_amt, y_amt, ..., then pivot it, using GROUP BY type_col. When you need to display it with columns q1, q2, ..., then pivot it using GROUP BY column_name.

  • Item Conversion Template Issue for Oracle Migration - Copy functionality

    Hi,
    I am working on Migration project which is from Radius ERP to Oracle 11.5.10.2.
    Currently working on Item Conversion. This Item conversion having the fileds like (ORGANIZATION_ID,SEGMENT1,DESCRIPTION,ITEM_TYPE,COST_OF_SALES_ACCOUNT,SALES_ACCOUNT,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15,GLOBAL_ATTRIBUTE10,REF_INVENTORY_ITEM_ID,REF_ORGANIZATION_ID).
    I have validated those fields and loaded into interfacing to Oracle Successfully in the master Org and Validated through Frontend.
    when I close the form, I will be receiving the below warning message and telling that Template id needs to be assign to the item before assigning item to the Org. The message is showing like
    "*You have not applied a template to this item, please apply a template before assigning this item to an ORG.*"
    Please find the below package which I wrote for this conversion requirement.
    The customer is saying like need to achieve the copy functionality based on the "REF_INVENTORY_ITEM_ID and REF_ORGANIZATION_ID".
    The Issue is am not able to handle the copy functionality and getting above message. kindly refer the package and suggest me where i am doing the mistake. Its high priority issue for me.
    Thanks in advance.
    CREATE OR REPLACE PACKAGE APPS.xxxx_inv_items_conv_pkg
    AS
    PROCEDURE xxx_item_conversion_proc (
    errbuf OUT VARCHAR2,
    retcode OUT VARCHAR2,
    p_org_id IN NUMBER,
    -- p_commit_point IN NUMBER,
    p_load_code IN VARCHAR2
    IS
    <<Local Variables Declaration>> <<For space limit deleted these variables>>
    CURSOR cur_item_master (pc_org_code VARCHAR2)
    IS
    SELECT itemstg.*
    FROM xxx_inv_system_items_stg itemstg
    WHERE itemstg.organization_id = pc_org_code
    AND itemstg.status_flag IS NULL;
    CURSOR cur_item_master_dup (pc_org_code VARCHAR2)
    IS
    SELECT itemstg.segment1, itemstg.organization_id
    FROM xxx_inv_system_items_stg itemstg
    WHERE itemstg.ROWID <
    (SELECT MAX (b.ROWID)
    FROM xxx_inv_system_items_stg b
    WHERE b.segment1 = itemstg.segment1
    AND b.organization_id = itemstg.organization_id
    AND b.organization_id = pc_org_code
    AND itemstg.status_flag IS NULL
    AND b.status_flag IS NULL);
    BEGIN
    IF p_load_code = 'Insert'
    THEN
    l_transaction_type := 'CREATE'; -- Default Value in I/F Table
    ELSIF p_load_code = 'Update'
    THEN
    l_transaction_type := 'UPDATE'; -- Default Value in I/F Table
    END IF;
    DBMS_OUTPUT.put_line ( 'Validation Starts At :'
    || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS')
    --Checking for Duplicate Records items
    BEGIN
    UPDATE xxx_inv_system_items_stg a
    SET a.status_flag = 'E',
    a.error_message = 'Duplicate Record'
    WHERE a.ROWID >
    ANY (SELECT b.ROWID
    FROM xxx_inv_system_items_stg b
    WHERE a.segment1 = b.segment1
    AND a.organization_id = b.organization_id)
    AND a.organization_id = p_org_id
    AND a.status_flag IS NULL;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Exception in updating duplicates'
    || SQLERRM
    END;
    DBMS_OUTPUT.put_line ('CheckPoint: Duplicate Record');
    BEGIN
    SELECT organization_id
    INTO l_organization_id
    FROM org_organization_definitions
    WHERE organization_id = p_org_id;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    DBMS_OUTPUT.PUT_LINE(p_org_id||' Org Does Not Exist');
    -- p_retcode := '2';
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.PUT_LINE('Exception in Getting Org Id'||'Cannot Proceed');
    -- p_retcode := '2';
    END ;
    DBMS_OUTPUT.put_line ('CheckPoint: Orgcode' || l_organization_id);
    /* IF p_retcode = '2'
    THEN
    RETURN;
    END IF;*/
    --Block             : Setting Master and Validation Orgs Flags
    BEGIN
    SELECT DECODE (master_organization_id, l_organization_id, 'Y', 'N'),
    master_organization_id
    INTO l_master_org,
    l_master_org_id
    FROM mtl_parameters
    WHERE organization_id = l_organization_id;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_master_org := 'N';
    l_master_org_id := NULL;
    DBMS_OUTPUT.PUT_LINE(p_org_id||' Org Does Not Exist');
    END ;
    DBMS_OUTPUT.put_line ('master_organization_id');
    SELECT fnd_profile.VALUE ('USER_ID')
    INTO l_user_id
    FROM DUAL;
    -- Block : Set the SET_PROCESS_ID
    l_set_process_id := l_organization_id;
    l_insert_count := 0;
    LOOP
    BEGIN
    SELECT COUNT (segment1)
    INTO l_insert_count
    FROM mtl_system_items_interface
    WHERE set_process_id = l_set_process_id
    AND transaction_type = l_transaction_type
    AND process_flag = 1;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_insert_count := 0;
    END;
    EXIT WHEN l_insert_count = 0;
    l_set_process_id := l_set_process_id + 10;
    END LOOP;
    DBMS_OUTPUT.put_line ('SET PROCESS ID -l_insert_count ' || l_insert_count);
    IF p_load_code = 'Insert'
    THEN
    BEGIN
    FOR recitem_data IN cur_item_master_dup (p_org_id)
    LOOP
    UPDATE xxx_inv_system_items_stg
    SET status_flag = l_processed_flag,
    error_message = l_error_message
    WHERE segment1 = recitem_data.segment1
    AND organization_id = recitem_data.organization_id
    AND status_flag IS NULL;
    COMMIT;
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ( 'Update of Duplicates Failed : '
    || SQLCODE
    || '--'
    || SQLERRM
    END ;
    END IF;
    FOR recitem_data IN cur_item_master (p_org_id)
    LOOP
    <<Local Variables Declaration>> <<For space limit deleted these variables>>
    IF p_load_code = 'Update'
    THEN
    l_error_message := 'Update Mode' || l_error_delimiter;
    END IF;
    --l_count := -1;
    BEGIN
    DBMS_OUTPUT.put_line ('CheckPoint: ItemValidationStart');
    SELECT DISTINCT inventory_item_id,
    restrict_subinventories_code,
    restrict_locators_code
    INTO l_inventory_item_id,
    l_restrict_subinventories_code,
    l_restrict_locators_code
    FROM apps.mtl_system_items_b msi
    WHERE msi.organization_id = l_organization_id
    AND msi.segment1 = UPPER (recitem_data.segment1);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    l_count := 0;
    -- l_processed_flag := 'F';
    DBMS_OUTPUT.put_line ('inventory_item_id - AFTER MAIN LOOP' || l_inventory_item_id||'-'||l_processed_flag);
    DBMS_OUTPUT.put_line ('inventory_item_id - AFTER MAIN LOOP' || l_inventory_item_id||'-'||recitem_data.ref_inventory_item_id);
    WHEN OTHERS
    THEN
    l_count := -1;
    -- l_processed_flag := 'F';
    DBMS_OUTPUT.put_line ('inventory_item_id - AFTER MAIN LOOP' || l_inventory_item_id||'-'||l_processed_flag);
    END ;
    DBMS_OUTPUT.put_line ('inventory_item_id - AFTER MAIN LOOP'||recitem_data.ref_inventory_item_id);
    IF l_count = -1
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Exception - Checking Item already Present'
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ('Exception - Checking Item already Present'||l_processed_flag);
    ELSIF (l_count > 0 AND p_load_code = 'Insert')
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Item Already Exists In '
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ('Exception - Checking Item already Present1'||l_processed_flag);
    ELSIF (l_count = 0 AND p_load_code = 'Update')
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Item Not Present In '
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ('Exception - Checking Item already Present2'||l_processed_flag);
    END IF;
    BEGIN
    SELECT count(*)
    INTO l_seg_count
    FROM apps.mtl_system_items_b msi
    WHERE msi.organization_id = l_organization_id
    AND msi.segment1 = UPPER (recitem_data.segment1);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    l_seg_count := 0;
    l_processed_flag:='F';
    l_error_message :=
    l_error_message
    || 'Item Not Present In Oracle'
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ('inventory_item_id - l_seg_count ' ||l_seg_count||'-'||l_processed_flag );
    WHEN OTHERS
    THEN
    l_seg_count := -1;
    l_processed_flag:='F';
    l_error_message :=
    l_error_message
    || 'Item Not Present In Oracle'
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    END ;
    IF p_load_code = 'Insert'
    THEN
    IF l_organization_id != l_master_org_id
    THEN
    BEGIN
    SELECT COUNT (1)
    INTO l_org_item_count
    FROM apps.mtl_system_items_b msi
    WHERE msi.organization_id = l_master_org_id
    AND msi.segment1 = UPPER (recitem_data.segment1);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    l_org_item_count := 0;
    DBMS_OUTPUT.put_line ('l_org_item_count ' ||l_org_item_count||'-'||l_processed_flag );
    WHEN OTHERS
    THEN
    l_org_item_count := -1;
    END ;
    IF l_org_item_count = -1
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Exception - Checking Item in Master '
    || l_error_delimiter;
    ELSIF l_org_item_count = 0
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Item Does Not Exist in Master '
    || l_error_delimiter;
    END IF;
    END IF;
    END IF;
    DBMS_OUTPUT.put_line ( 'CheckPoint: Iteminmasterorg'
    || l_org_item_count
    IF (recitem_data.description IS NULL AND p_load_code = 'Insert')
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message || 'Description is NULL' || l_error_delimiter;
    END IF;
    IF (recitem_data.sales_account IS NOT NULL)
    THEN
    BEGIN
    SELECT code_combination_id
    INTO l_sales_account
    FROM gl_code_combinations_kfv
    WHERE code_combination_id= recitem_data.sales_account;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    -- l_processed_flag := 'F'; --QUESTION
    l_error_message :=
    l_error_message
    || 'Sales Account Not Setup '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ( 'CheckPoint: Salesacct_Validation'
    || l_sales_account||'-'||l_processed_flag
    WHEN OTHERS
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Sales Account Exception '
    || SQLERRM
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ( 'CheckPoint: Salesacct_Validation'
    || l_sales_account||'-'||l_processed_flag
    END ;
    END IF;
    IF (recitem_data.cost_of_sales_account IS NOT NULL)
    THEN
    BEGIN
    SELECT code_combination_id
    INTO l_cost_of_sales_account
    FROM gl_code_combinations_kfv
    WHERE code_combination_id =
    recitem_data.cost_of_sales_account;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'COGS Account Not Setup '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ( 'l_cost_of_sales_account'
    || l_cost_of_sales_account||'-'||l_processed_flag
    WHEN OTHERS
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'COGS Account Exception '
    || SQLERRM
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ( 'l_cost_of_sales_account'
    || l_cost_of_sales_account||'-'||l_processed_flag
    END check_cogs_account;
    END IF;
    BEGIN
    select distinct organization_code
    into l_ref_org_code
    from org_organization_definitions
    where organization_id = recitem_data.ref_organization_id ;
    EXCEPTION
    WHEN OTHERS THEN
    l_ref_org_code:= NULL;
    l_processed_flag:='F';
    l_error_message :=
    l_error_message
    || 'Reference Org Not Present'
    || p_org_id
    || ' Organization '
    || l_error_delimiter ;
    DBMS_OUTPUT.put_line ('l_ref_org_code'|| l_ref_org_code||'-'||l_processed_flag);
    END;
    BEGIN
    select concatenated_segments
    into l_ref_inventory_item_code
    from mtl_system_items_kfv
    where inventory_item_id = recitem_data.ref_inventory_item_id
    and organization_id = recitem_data.ref_organization_id ;
    EXCEPTION
    WHEN OTHERS THEN
    l_ref_inventory_item_code :=NULL;
    l_processed_flag:='F';
    l_error_message :=
    l_error_message
    || 'Reference Item Not Present'
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    DBMS_OUTPUT.put_line ('l_ref_inventory_item_code'|| l_ref_inventory_item_code||'-'||l_processed_flag);
    END;
    IF (l_master_org = 'N' AND p_load_code = 'Insert')
    THEN
    BEGIN
    SELECT count(*)
    INTO l_description_count
    FROM mtl_system_items_tl
    WHERE organization_id = l_master_org_id
    AND inventory_item_id =
    (SELECT inventory_item_id
    FROM mtl_system_items_b
    WHERE organization_id = l_master_org_id
    AND segment1 = recitem_data.segment1);
    END ;
    IF l_description_count > 0 THEN
    l_processed_flag:='F';
    l_error_message :=
    l_error_message
    || 'Item Description Not Present'
    || p_org_id
    || ' Organization '
    || l_error_delimiter;
    END IF;
    END IF;
    IF l_processed_flag = 'S'
    THEN
    BEGIN
    INSERT INTO mtl_system_items_interface
    (organization_id,
    segment1,
    description,
    ITEM_TYPE,
    COST_OF_SALES_ACCOUNT,
    SALES_ACCOUNT,
    attribute_category,
    set_process_id,
    transaction_type,
    process_flag,
    copy_organization_code,
    copy_item_number,
    creation_date,
    created_by,
    last_updated_by,
    last_update_date
    --attribute_category
    , attribute1
    , attribute2
    ,attribute3
    ,attribute4
    ,attribute5
    ,attribute6
    ,attribute7
    ,attribute8
    ,attribute9
    ,attribute10
    ,attribute11
    ,attribute12
    ,attribute13
    ,attribute14
    ,attribute15
    ,global_attribute10
    VALUES (l_organization_id,
    recitem_data.segment1,
    recitem_data.description,
    recitem_data.ITEM_TYPE,
    recitem_data.COST_OF_SALES_ACCOUNT,
    recitem_data.SALES_ACCOUNT,
    recitem_data.ATTRIBUTE_CATEGORY,
    l_set_process_id,
    l_transaction_type, --,l_transaction_type
    l_process_flag,
    l_ref_org_code,
    l_ref_inventory_item_code,
    SYSDATE, l_user_id,
    l_user_id, SYSDATE
    -- l_attribute_category
    ,recitem_data.attribute1
    ,recitem_data.attribute2
    ,recitem_data.attribute3
    ,recitem_data.attribute4
    ,recitem_data.attribute5
    ,recitem_data.attribute6
    ,recitem_data.attribute7
    , recitem_data.attribute8
    ,recitem_data.attribute9
    , recitem_data.attribute10
    ,recitem_data.attribute11
    ,recitem_data.attribute12
    ,recitem_data.attribute13
    ,recitem_data.attribute14
    ,recitem_data.attribute15
    , substr(recitem_data.global_attribute10,1,length(recitem_data.global_attribute10)-1) --recitem_data.global_attribute10
    l_insert_count := l_insert_count + 1;
    /* IF (l_insert_count = NVL (p_commit_point, 10000))
    THEN
    -- l_set_process_id := l_set_process_id + 10; -- REVERT BACK CHANGE
    l_insert_count := 0;
    END IF;
    EXCEPTION
    WHEN OTHERS
    THEN
    l_processed_flag := 'F';
    l_error_message :=
    l_error_message
    || 'Error in Inserting Item '
    || SQLERRM
    || l_error_delimiter;
    END ;
    COMMIT;
    DBMS_OUTPUT.put_line ('CheckPoint: Insertion Completed in Intfacetable');
    END IF;
    BEGIN
    UPDATE xxx_inv_system_items_stg
    SET status_flag = l_processed_flag,
    error_message = l_error_message
    WHERE segment1 = recitem_data.segment1
    AND organization_id = recitem_data.organization_id
    AND status_flag IS NULL;
    COMMIT;
    DBMS_OUTPUT.put_line ('Error Message'||l_error_message);
    EXCEPTION
    WHEN OTHERS
    THEN
    fnd_file.put_line (fnd_file.LOG,
    'Error:Updating Item:'
    || SQLCODE
    || '-'
    || SQLERRM
    END;
    END LOOP; --FOR recitem_data IN cur_item_master
    DBMS_OUTPUT.put_line ( 'Validation Ends At :'
    || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS')
    DBMS_OUTPUT.put_line ('Number of records inserted into Table Successfully -->'|| l_insert_count);
    END;
    END xxxx_inv_items_conv_pkg;
    Edited by: 896170 on Apr 12, 2013 11:58 PM

    Issue got solved... changed the PO line amount as:
    <?xdoxslt:set_variable($_XDOCTX,'line_amt',xdoxslt:to_number(LINE_AMOUNT))?>
    Reference :Syntax for 'to_number'
    Regards
    Manikanta Panigrahi

  • Replacement for fuction CONVERSION_EXIT_ALPHA_INPUT SAP Function module

    hi folks..
    do we have any replacement in terms of codes for the fuction CONVERSION_EXIT_ALPHA_INPUT SAP Function module.. i know the use of this fuction module as it converts data in numeric format to character format which is only accpetable in SAP.. cant we do it manualy using the abap codes.. or else it is the only option to do so????

    Hi Ram,
    I guess Isaac got a little confused, anyways try the below code, forgot to add...just curious to know the reason behind your post...any specific reason why you want to avoid the FMs.
    DATA: l_vbeln TYPE vbeln VALUE '12345',
          l_overlay TYPE vbeln VALUE '0000000000'.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = l_vbeln
    IMPORTING
       OUTPUT        = l_vbeln.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        input         = l_vbeln
    IMPORTING
       OUTPUT        = l_vbeln.
    * Code to replace Conversion exit alpha input
    SHIFT l_vbeln RIGHT DELETING TRAILING space.
    OVERLAY l_vbeln WITH l_overlay.
    * Code to replace Conversion exit alpha output
    SHIFT l_vbeln LEFT DELETING LEADING '0'.
    IF sy-subrc EQ 0.
    ENDIF.
    Regards,
    Chen
    Edited by: Chen K V on Jun 2, 2011 2:17 PM
    Edited by: Chen K V on Jun 2, 2011 2:18 PM

  • SQL Interface for Oracle in Windows 64 bit

    Hi there,
    Is there anyone ever trying to upload data from oracle (relational sql) to the essbase on Windows 64 bit platform ? I've read the documentation about setting SQL Interface by using the ODBC Connection ( using DataDirect Library ), but it seems that I can not see the DataDirect lib in the ODBC Control Panel (64bit), but it is installed in the 32 bit ODBC (odbcad32.exe).
    However when I try to add new connection using MERANT OEM 5.2 64-BIT Oracle ODBC driver (DataDirect lib), it raise error : "the setup routines for the MERANT OEM 5.2 64-BIT Oracle ODBC driver could not be loaded due to system error code 193"..
    please advice any one.... thanks

    I got it to work!!!
    The reg setting that is provided is for the wrong version of the dll. Notice the 5.1 and then you only have 5.2 directories.
    The files in the reg are also wrong they are for the example below. arora21.dll (stated) vs arora22.dll (one's provided)
    Some easy tweaks.
    I modified the reg with the following and presto. It worked!! To make it better you can change the OEM 5.1 to OEM 5.2.. Good luck
    echo off
    IF DEFINED HYPERION_HOME (
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol"
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v APILevel /t REG_SZ /d 1
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v ConnectFunctions /t REG_SZ /d YYY
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v CPTimeout /t REG_SZ /d 60
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v Driver /t REG_SZ /d %HYPERION_HOME%\Common\ODBC-AMD64\Merant\5.2\Drivers\arora22.dll
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v DriverODBCVer /t REG_SZ /d 3.52
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v FileUsage /t REG_SZ /d 0
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v HelpRootDirectory /t REG_SZ /d %HYPERION_HOME%\Common\ODBC-AMD64\Merant\5.2\help
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v Setup /t REG_SZ /d %HYPERION_HOME%\Common\ODBC-AMD64\Merant\5.2\Drivers\arora22.dll
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v SQLLevel /t REG_SZ /d 1
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /v UsageCount /t REG_SZ /d 1
    REG ADD "HKLM\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" /v "MERANT OEM 5.1 64-BIT Oracle Wire Protocol" /t REG_SZ /d Installed
    ) ELSE (
    echo "Environment variable HYPERION_HOME must be first defined to run script."
    Edited by: user652102 on Aug 23, 2008 11:37 AM

  • Can I change the SQL Datatype for Oracle Date?

    xMII 11.5 maps Oracle's Date type to its SQL type code 91 (Date).  When used in a display template, this xMII type displays only the date component (for example, "5/5/2007"), but in Oracle it holds the date and time.  In Java, the java.sql.Date type also holds the time component.  To get xMII to display a date/time (for example, "5/5/2007 11:23:59") you must have a SQL type code of 93 (Timestamp).
    Is there any way to get my xMII widgets to show the date and time components of an Oracle Date?  Is there a mapping of some kind that tells xMII which database SQL types map to which xMII SQL type codes?
    -tim

    In Aqua Data Studio:
    SELECT CREATED_DATE_TIME, MESSAGE FROM COLLABORATION_LOG
    where CREATED_DATE_TIME > to_date('01/01/07','mm/dd/yy') and site='DEM1'
    order by CREATED_DATE_TIME DESC
    GO
    results:
    CREATED_DATE_TIME   MESSAGE                                                                        
    5/3/2007 8:30:25 PM   (403)Access Forbidden                                                          
    5/3/2007 8:30:25 PM   (403)Access Forbidden                                                          
    5/3/2007 8:30:25 PM   (403)Access Forbidden   
    If I put the exact same SQL (without the "GO" at the end which is an Aqua Data Studio keyword) into a Fixed SQL Query in xMII and click "Test" and choose html format I get:
    CREATED_DATE_TIME MESSAGE
    05/03/2007 00:00:00 (403)Access Forbidden
    05/03/2007 00:00:00 (403)Access Forbidden
    05/03/2007 00:00:00 (403)Access Forbidden
    The time component is reported as "00:00:00" in xMII which is not the desired result.  I want xMII to see that column as a Timestamp which should read and sore both the date and time components in xMII.
    -tim

  • Replacement for the following obsolete function modules..

    ADDRESS_GET_NUMBER
    ADDRESS_INSERT
    ARCHIVOBJECT_PREFETCH

    Hello Thilak
    The entire package SZA which contains the function group SAD2 with the function modules you mentioned is marked as obsolete.
    Most likely these obsolete objects have been replaced by:
    - Package: ZSA -> <b>ZSAD</b>
    - Function Group SAD2 -> <b>SZA0</b>
    - Fm ADDRESS_GET_NUMBER -> <b>ADDR_NUMBER_GET</b>
    - Fm ADDRESS_INSERT -> <b>ADDR_INSERT</b>
    - Fm ARCHIVOBJECT_PREFETCH -> <i>???</i>
    Regards
      Uwe

  • Guaranteed restore point Vs catdwgrd.sql downgrade for oracle 12c

    I understand that we have two ways to downgrade (assuming compatible parameter is not modified) when we upgrade a 11.2.0.3 database to oracle 12c.
    I am curious to know advantages of catdwgrd.sql when compared to guaranteed restore point downgrade. I think guaranteed restore point looks very simple
    compared to catdwgrd.sql. Also I think oracle doesn't exactly bring the database back to the same state when we use catdwgrd.sql whereas
    guranteed restore point brings us back to the same state.
    Thank You
    Sarayu

    Which method you choose will depend on your circumstances. This blog post may help
    https://blogs.oracle.com/UPGRADE/entry/is_there_a_fallback_strategy
    A third possible option is to simply restore the database from backups
    HTH
    Srini

  • Is SOA Suite replacement for Oracle Service Bus 10gR3 (10.3.1.0) ?

    I am confused if i have SOA Suite do I need Oracle Service Bus 10gR3 (10.3.1.0) for my ESB ?

    Right now there are eclipse plug-ins for OSB. In a default OSB installation you should have workshop installed with the OSB plug-ins.
    For the next release, OSB 11g, JDeveloper will incorporate these features.

  • Executing Native SQL query for oracle

    Hi,
    I want to run following native sql query but it is giving me error ora:933,
    DATA: BEGIN OF WA,
          TSP_NAME(255) TYPE C,
          PER_USAGE(10) TYPE C,
          END OF WA.
    EXEC SQL PERFORMING loop_output.
    select t.tablespace_name,'(' || TO_CHAR(ROUND(100*(NVL(b.bytes,0)/NVL(a
    .bytes,0)))) || '%)' "TSUsed%" from dba_tablespaces t,
    ( select tablespace_name, sum(bytes)/1024/1024 bytes
    from dba_data_files group by tablespace_name) a,
    ( select e.tablespace_name, sum(e.bytes)/1024/1024 bytes
    from dba_extents e group by e.tablespace_name ) b,
    ( select f.tablespace_name, sum(f.bytes)/1024/1024 bytes
    from dba_free_space f group by f.tablespace_name ) c
    where t.tablespace_name = a.tablespace_name(+) and
    t.tablespace_name = b.tablespace_name(+) and
    t.tablespace_name = c.tablespace_name(+) into :wa.
    ENDEXEC.
    Please provide me the soln
    Regards,
    Bharat Mistry

    ORA-00933: SQL command not properly ended.
    Try:
    EXEC SQL PERFORMING loop_output.
    select
    into :wa
    ENDEXEC.
    (No "." at the end). If that doesn't work, try ending it with a ";"
    Rob

  • Replacement for Oracle Graphics in Forms 9i.

    I read some time ago that Oracle Forms 9i was going to use a
    special Java tool to create charts but in the 9i documents
    available I can't see any reference to it anymore. What is the
    official direction?

    I suggest that you'll have a look at Oracle's BI beans which integrate with Oracle9i JDeveloper and enable you to create graphs that can be incorporated into Forms also.

  • I need OrderEntry schema SQL file for Oracle 10g Express

    It seems Oracle 10g Express does not come with oe schema.
    I do not want to download another Oracle.

    I think its doable:
    1) http://www.oracle.com/technology/obe/obe1013jdev/common/OBEConnection.htm
    Download the sample_schema_scripts9i10g.zip
    Since you have Oracle Express you should unzip it to :
    C:\oraclexe\app\oracle\product\10.2.0\demo
    Thereafter copy
    C:\oraclexe\app\oracle\product\10.2.0\demo\schema\order_entry
    to
    C:\oraclexe\app\oracle\product\10.2.0\server\demo\schema
    then :
    C:\oraclexe\app\oracle\product\10.2.0\demo\schema>path=c:\oraclexe\app\oracle\pr
    oduct\10.2.0\server\BIN
    C:\oraclexe\app\oracle\product\10.2.0\demo\schema>sqlplus system/manager
    then
    @mksample as described in http://www.oracle.com/technology/obe/obe1013jdev/common/OBEConnection.htm
    I agree with you that this was not straight forward since these scripts are pretty complex, but I did this now and I have at least the customer - orders relation up and running so I hope it helps.
    kind regards
    Terje

  • Replacement for oracle Jdriver type 2?

    Hi,
    Since WLS8.1 Sp1, the WebLogic Jdriver is deprecated...
    I was using the Oracle JDriver Type 2 (native).
    Does it exist a new type 2 driver? Or should I use the oci driver from oracle?
    Thank you
    Yann.

    You should use the type 2 driver from oracle.

Maybe you are looking for