Substring, comparasion operatins usng PL/SQL

i just need to know how to operate substring functions using PL/SQL. For instance, assume that i have strings such as 1000YTL, 200YTL, 3000YTL. What i need to cut the letters(YTL) ang get the numeric values and select mix and max of the numeric values. Here is my procedure
create or replace procedure Ihale_GettheMaxOrMin(v_ihlkodu in ihale_katilimcilar.ihlkodu%TYPE, outminval out number)
is
cursor cur is
select statement;
begin
OPEN cur;
LOOP
FETCH cur INTO maybe_an_array;
EXIT WHEN cur%NOTFOUND;
//substring and comparasion operations to get the mix or max and assign it to the out parameter...
END LOOP;
CLOSE cur;
end Ihale_GettheMaxOrMin;

like this ?
SQL> select replace('1000YTL', 'YTL') from dual;
REPL
1000
Hi there,
That will only work if you know that there are always going to be 3 chars and you know what the characters are. You would be safer to use the TRANSLATE function to remove all possible characters you do not need e.g.
SQL> SELECT '>>'||TRANSLATE( UPPER ('1000YTL'), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',' ')||'<<'
2 from dual
3 ;
'>>'||TR
1000<<SQL>
I've added the >> and << to show that you get just the number and nothing else.
This will remove all the letters of the alphabet so you don't care what those letters are. If there may be other characters in the string then simply add them to the list of those to translate to ''
Mark

Similar Messages

  • SUBSTR function working only in SQL developper?

    Hello,
    I type the following query based on what I am learning in terms of Single-row Functions and it seems to work in SQL developer but for some reason not in SQL Plus ? Can anyone tell me where i am going wrong?
    Select Job_title,
    SUBSTR(Job_title, 1, 10)
    SUBSTR(Job_Title, 11)
    from jobs;
    This is just to test the function's abilities and to see what it does but I was wondering as to why it doesn't work on the SQL plus prompt. Any help would be greatly appreciated.
    Thank you

    Vlakarmis wrote:
    Hello,
    I type the following query based on what I am learning in terms of Single-row Functions and it seems to work in SQL developer but for some reason not in SQL Plus ? Can anyone tell me where i am going wrong?
    Select Job_title,
    SUBSTR(Job_title, 1, 10)
    SUBSTR(Job_Title, 11)
    from jobs;
    This is just to test the function's abilities and to see what it does but I was wondering as to why it doesn't work on the SQL plus prompt. Any help would be greatly appreciated.
    Thank you"Doesn't work" is not an actionable error message.
    Please use copy and paste - copy your entire sqlplus session - full sqlstatement and full response, and post back here. If it returns many rows, we don't need to see all of them, just a representative sample.

  • Substr function not working in coldfusion sql

    Hi all,
    I am using coldfusion 7.0.2 with oracle 10g. I've the
    following simple query
    select substr(colname,1,3) from tablename
    this query works fine if i run it using TOAD or SQLPLUS but
    when i run this query in coldfusion script i get the following
    error
    [Table (rows 9 columns SUBSTR(colname,1,3)):
    [SUBSTR(colname,1,3): coldfusion.sql.QueryColumn@fc7be7] ] is not
    indexable by SUBSTR(colname
    can anybody tell me why it doesn't work in coldfusion but
    works fine in sqlplus?
    thank you

    There's no such thing as "coldfusion sql" (sic). Everything
    between the
    <cfquery> tags is simply resolved (ie: CF runtime
    statements between
    pound-signs) and passed straight to the DB drivers, and
    thence to the DB
    itself. CF does no SQL processing at all.
    Your error kind of suggests a syntac error AFTER the query
    has been
    executed though.
    Could you post some code, and point out which precise line is
    erroring?
    Adam

  • No Data Found: Exception in SQL inside PL/SQL block

    Hi Friends
    I am trying to execute an SQL SELECT stmt inside a PL/SQL block. But when i execute the procedure, it gives me No Data Found Exception.
    I know it is because no row is fetched in the query, but the condition of the SELECT query i have specified is being satisfied, i have checked it by running it on the SQL prompt.
    But somehow, it is not running from inside the PL/SQL procedure.Can anybody help me out on this as to why is this happening?? I am giving my code for reference and have Highlighted the Query inside it:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
         v_salesorg varchar2(10);
         v_sales_district varchar2(10);
         v_salesoff varchar2(10);
         v_custgrp varchar2(10);
         v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    dbms_output.put_line(v_cust_cur.customer_code );
                        SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    dbms_output.put_line(v_partner_code||i.customer_code);
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
              WHERE customer_code = i.customer_code and salesorg = i.salesorg;
                   dbms_output.put_line(v_salesorg||i.salesorg);
                        SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G'; dbms_output.put_line(v_parent_cust);
                        SELECT credit_block INTO v_credit_blk from load_cust_company_cod
              WHERE customer_code = i.customer_code;
    dbms_output.put_line(v_credit_blk);
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
                                  where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
                                                      LOOP
    -- exit when j%NOTFOUND;
         dbms_output.put_line(j.account_group);
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
              v_nature := '06';
         --     EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    dbms_output.put_line(v_type||' '||v_nature);
    END LOOP;
    INSERT INTO sfdc_account
              (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    Kindly Help.....
    Thanks and Regards

    Create the procedure again and execute it in SQL*Plus environment and paste the output:
    CREATE OR REPLACE procedure insert_sfdc_account
    as
    --DECLARE
    CURSOR C1 IS
    SELECT customer_code, name1, name2, name3, name4, phone_number, fax, web_address, industry_sector, customer_profile, customer_type,
    address, city, postal_code, country_key, zzcust_type, vat_code
    FROM load_cust_general
    WHERE account_group = 'ZSIT';
    v_cust_cur c1%ROWTYPE;
    -- type sales_tab is table of load_cust_sales_area%rowtype;
    v_sales_area load_cust_sales_area%ROWTYPE;
    -- v_sales_area sales_tab;
    v_salesorg varchar2(10);
    v_sales_district varchar2(10);
    v_salesoff varchar2(10);
    v_custgrp varchar2(10);
    v_salesgrp varchar2(10);
    v_type varchar2(20);
    v_nature varchar2(10);
    v_partner_code varchar2(10);
    v_parent_cust varchar2(20);
    v_credit_blk varchar2(20);
    BEGIN
    open c1;
    loop
    fetch c1 into v_cust_cur;
    exit when c1%NOTFOUND;
    for i in (SELECT customer_code, salesorg from load_cust_partner
    where customer_code = v_cust_cur.customer_code ) LOOP
    SELECT partner_code into v_partner_code from load_cust_partner
    where customer_code = i.customer_code and salesorg = i.salesorg and partner_function = 'Z1';
    SELECT salesorg, sales_district, salesoff, salesgrp, custgrp INTO v_salesorg, v_sales_district, v_salesoff, v_salesgrp, v_custgrp FROM load_cust_sales_area
    WHERE customer_code = i.customer_code and salesorg = i.salesorg;
    dbms_output.put_line('Customer_Code : '|| i.customer_code);
    dbms_output.put_line('SalesOrg : '|| i.salesorg);
    SELECT parent_customer INTO v_parent_cust from load_cust_hierarchy
    WHERE customer_code = i.customer_code and salesorg = i.salesorg and hierarchy_type = 'G';
    dbms_output.put_line('Successfully Executed SQL st. Error is somewhere else');
    SELECT credit_block INTO v_credit_blk from load_cust_company_cod
    WHERE customer_code = i.customer_code;
    for j in (SELECT account_group, customer_type from load_cust_general
    where customer_code IN (select customer_code from load_cust_partner
    where partner_code = i.customer_code and salesorg = i.salesorg and partner_function = 'ZS'))
    LOOP
    -- exit when j%NOTFOUND;
    if (j.account_group = 'ZDIS') THEN
    v_type := 'DISAC';
    v_nature := '06';
    -- EXIT ;
    else
    v_type := 'SPACC';
    v_nature := '01';
    END IF;
    END LOOP;
    INSERT INTO sfdc_account
    (SAP_ACCOUNT_ID__C, NAME, TYPE, RECORDTYPEID, PARENTID, PHONE, FAX, WEBSITE, OWNERID, MARKETING_DOMAIN__C,
    INDUSTRIAL_SECTOR__C, ABC_CLASSIFICATION__C, NAME_1__C, NAME_2__C, NAME_3__C, NAME_4__C, PAYMENT_STATUS__C,
    CUSTOMER_GROUP__C, ADDRESS_STREET__C, CITY__C, POSTAL_CODE__C, COUNTRY__C, SALES_OFFICE__C, SALESORG__C,
    SALESDISTRICT__C, SALESGROUP__C, NATURE__C, VATCODE__C)
    VALUES((i.customer_code||i.salesorg), (v_cust_cur.Name1||' '||v_cust_cur.name2), ' ', v_type, v_parent_cust,
    v_cust_cur.phone_number, v_cust_cur.fax, v_cust_cur.web_address, v_partner_code, SUBSTR(v_cust_cur.industry_sector,1,2),
    v_cust_cur.industry_sector, v_cust_cur.customer_profile, v_cust_cur.name1, v_cust_cur.name2, v_cust_cur.name3,
    v_cust_cur.name4, v_credit_blk, v_custgrp, v_cust_cur.address, v_cust_cur.city, v_cust_cur.postal_code,
    v_cust_cur.country_key, v_salesoff, v_salesorg, v_sales_district,
    v_salesgrp, v_nature, v_cust_cur.vat_code);
    end loop;
    end loop;
    CLOSE c1;
    -- Delete data from Load Table
    -- EXECUTE IMMEDIATE 'TRUNCATE TABLE load_cust_general';
    /* truncate table load_cust_partner;
    truncate table load_cust_hierarhy;
    truncate table load_cust_sales_area;
    truncate table load_cust_company_cod;
    commit;
    exception
    when others then
    raise_application_error( -20001, substr( sqlerrm, 1, 150 ) );
    END;
    SQL> set serveroutput on
    SQL> exec insert_sfdc_account;

  • SQL Loader - Field in data file exceeds maximum length

    Dear All,
    I have a file which has more than 4000 characters in a field and I wish to load the data in a table with field length = 4000. but I receive error as
    Field in data file exceeds maximum lengthThe below given are the scripts and ctl file
    Table creation script:
    CREATE TABLE "TEST_TAB"
        "STR"  VARCHAR2(4000 BYTE),
        "STR2" VARCHAR2(4000 BYTE),
        "STR3" VARCHAR2(4000 BYTE)
      );Control file:
    LOAD DATA
    INFILE 'C:\table_export.txt'
    APPEND INTO TABLE TEST_TAB
    FIELDS TERMINATED BY '|'
    TRAILING NULLCOLS
    ( STR CHAR(4000) "SUBSTR(:STR,1,4000)" ,
    STR2 CHAR(4000) "SUBSTR(:STR2,1,4000)" ,
    STR3 CHAR(4000) "SUBSTR(:STR3,1,4000)"
    )Log:
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon Jul 26 16:06:25 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Control File:   C:\TEST_TAB.CTL
    Data File:      C:\table_export.txt
      Bad File:     C:\TEST_TAB.BAD
      Discard File:  none specified
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 0
    Bind array:     64 rows, maximum of 256000 bytes
    Continuation:    none specified
    Path used:      Conventional
    Table TEST_TAB, loaded from every logical record.
    Insert option in effect for this table: APPEND
    TRAILING NULLCOLS option in effect
       Column Name                  Position   Len  Term Encl Datatype
    STR                                 FIRST  4000   |       CHARACTER           
        SQL string for column : "SUBSTR(:STR,1,4000)"
    STR2                                 NEXT  4000   |       CHARACTER           
        SQL string for column : "SUBSTR(:STR2,1,4000)"
    STR3                                 NEXT  4000   |       CHARACTER           
        SQL string for column : "SUBSTR(:STR3,1,4000)"
    value used for ROWS parameter changed from 64 to 21
    Record 1: Rejected - Error on table TEST_TAB, column STR.
    Field in data file exceeds maximum length
    MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
    Table TEST_TAB:
      0 Rows successfully loaded.
      1 Row not loaded due to data errors.
      0 Rows not loaded because all WHEN clauses were failed.
      0 Rows not loaded because all fields were null.
    Space allocated for bind array:                 252126 bytes(21 rows)
    Read   buffer bytes: 1048576
    Total logical records skipped:          0
    Total logical records read:             1
    Total logical records rejected:         1
    Total logical records discarded:        0
    Run began on Mon Jul 26 16:06:25 2010
    Run ended on Mon Jul 26 16:06:25 2010
    Elapsed time was:     00:00:00.22
    CPU time was:         00:00:00.15Please suggest a way to get it done.
    Thanks for reading the post!
    *009*

    Hi Toni,
    Thanks for the reply.
    Do you mean this?
    CREATE TABLE "TEST"."TEST_TAB"
        "STR"  VARCHAR2(4001),
        "STR2" VARCHAR2(4001),
        "STR3" VARCHAR2(4001)
      );However this does not work as the error would be:
    Error at Command Line:8 Column:20
    Error report:
    SQL Error: ORA-00910: specified length too long for its datatype
    00910. 00000 -  "specified length too long for its datatype"
    *Cause:    for datatypes CHAR and RAW, the length specified was > 2000;
               otherwise, the length specified was > 4000.
    *Action:   use a shorter length or switch to a datatype permitting a
               longer length such as a VARCHAR2, LONG CHAR, or LONG RAW*009*
    Edited by: 009 on Jul 28, 2010 6:15 AM

  • REG:- SQL QUERY

    HI FRENDS
    MY PROBLEM IS IN BELOW QUERY
    select SUBSTR('Sales - Alternate Channels (Sub Department).Area Manager.1',1,7) from dual
    HERE I WANT TO TAKE ONLY 'SALES' FROM THE STRING.
    BUT SOME TIME INSTEAD OF SALES IT WILL COME 'Branch Operations' LIKE THAT THEN I WANT TAKE THESE STRING ONLY....
    IN SHORT I WAN TO TAKE ONLY THAT STRING WHICH IS BEFORE '-'......NOT THAT VALUE WHICH AFTER '-'...
    PL HELP.

    If u want srting before '-' than use instr to search '-'
    e.g.
    select substr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1',1
    ,instr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
    from dual
    SQL> select substr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1',1
    2 ,instr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
    3 from dual
    4 /
    SUBSTR('BRANCHOPERATIONS-ALTER
    Branch Operations
    SQL> select substr('Sales - Alternate Channels (Sub Department).Area Manager.1',1
    2 ,instr('Sales - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
    3 from dual
    4 /
    SUBSTR('SALES-ALTERNATECHANNEL
    Sales

  • How to write xml doc to file in PL/SQL

    I have a function defined that uses xmlgen.getxml to generate an xml confirmation document. I am calling this function from a trigger and would like to have the returned xml document (a clob) written to an OS file. Can anyone help me with this issue?
    Thanks,
    John

    declare
    TYPE weak_cursor_type is REF CURSOR;
    curOUT weak_cursor_type;
    vOUT clob;
    begin
    open curOUT FOR SELECT xmlgen.getXML('select * from all_users',1) XML_TXT FROM DUAL;
    fetch curOUT into vOUT;
    sp_gen_util.output_clob(vOUT,80,'file');
    sp_gen_util.output_str(vOUT, 250, 'screen');
    end;
    ----part of package sp_gen_util----
    ------------- package variables --------------
    SUBTYPE max_str_type is varchar2(32767);
    wk_CR char:=chr(10);
    MAX_STR_LEN constant number:= 32767;
    --- driver routine. calls "open_file_function"
    --- and "LOBPrint"
    --- assumptions: that UTL_DIR has been set in INIT.ORA
    --- to support any directories passed
    --- inputs: CLOB for output
    --- line_length (only affects screen output just now)
    --- destination (currently allows "screen" and "file")
    --- file_status ("a" append, "w" open for write)
    --- dirname (directory path for file)
    --- filename (file name for write or append)
    PROCEDURE output_clob (
    p_str clob,
    p_line_length number DEFAULT 80,
    p_destination varchar2 DEFAULT 'screen',
    p_status varchar2 DEFAULT 'a',
    p_dirname varchar2 DEFAULT '/tmp',
    p_filename varchar2 DEFAULT 'write_host_file.log' ) IS
    v_outfile utl_file.file_type;
    begin
    wk_substr_len:=p_line_length;
    if p_destination='file' then
    v_outfile := open_file_fun(p_status, p_dirname, p_filename);
    end if;
    LOBPrint(p_str,p_destination,v_outfile);
    if p_destination='file' then
    utl_file.fclose(v_outfile);
    end if;
    end output_clob;
    --- loops through blocks of text by delimiter (carriage return)
    --- and writes to either the screen or file
    --- (output to screen needs work for clob...currently using
    --- "output_str" instead for <32k strings instead)
    --- inputs: CLOB for output
    --- destination (currently allows "screen" and "file")
    --- filehandle (open filehandle from openfile routine)
    PROCEDURE LOBPrint(
    p_str clob,
    p_destination varchar2,
    v_outfile utl_file.file_type default null ) is
    ---------------local working variables
    wk_str max_str_type; --MAX=32767
    wk_offset INTEGER := 1;
    wk_clob clob;
    wk_clob_len number;
    wk_clob_len2 number;
    wk_max_loops number:=70000;
    begin
    wk_clob_len:= dbms_lob.getlength(p_str);
    if wk_clob_len <= MAX_STR_LEN
    and p_destination='file' then
    --- NOTE: dbms_lob.substr parameters are OPPOSITE of sql substr
    utl_file.put_line(v_outfile, dbms_lob.substr( p_str, wk_clob_len, 1));
    elsif wk_clob_len > MAX_STR_LEN then
    dbms_lob.createtemporary(wk_clob, TRUE, dbms_lob.call);
    --- wk_clob: LOB locator of the copy target.
    --- p_str: LOB locator of source for the copy.
    --- wk_clob_len: Number of bytes (for BLOBs) or characters (for CLOBs)
    --- to copy.
    --- 1: Offset in bytes or characters in the destination LOB
    --- (origin: 1) for the start of the copy.
    --- 1: Offset in bytes or characters in the source LOB
    --- (origin: 1) for the start of the copy.
    dbms_lob.copy(wk_clob, p_str, wk_clob_len, 1, 1);
    LOOP
    wk_str:=word_parse_trim_lob_FUN(wk_clob,wk_CR);
    if p_destination='file' then
    utl_file.put_line(v_outfile, wk_str);
    elsif p_destination='screen' then
    dbms_output.put_line(wk_str);
    end if;
    wk_clob_len2:= dbms_lob.getlength(wk_clob);
    EXIT WHEN wk_clob is null ;
    END LOOP;
    end if;
    END LOBPrint;
    --- "function with side-effect"
    --- input is CLOB, with is "returned" without leading field
    --- additional parameter is field (or token) delimiter
    --- value returned is leading field from input string
    FUNCTION word_parse_trim_lob_FUN(o_str IN OUT NOCOPY clob,
    p_delimiter IN varchar2) RETURN varchar2
    IS
    o_token max_str_type;
    clob_len number;
    next_pos number;
    wk_clob clob;
    BEGIN
    clob_len:= dbms_lob.getlength(o_str);
    next_pos:= dbms_lob.instr(o_str, p_delimiter, 1, 1);
    if next_pos != 0 then
    -- NOTE: dbms_lob.substr parameters are OPPOSITE of sql substr
    dbms_lob.createtemporary(wk_clob, TRUE, dbms_lob.call);
    o_token:= dbms_lob.substr( o_str, next_pos-1, 1);
    -- o_str:= dbms_lob.substr(o_str,clob_len-next_pos,next_pos+1);
    if next_pos = clob_len then
    wk_clob := null;
    else
    --- wk_clob: LOB locator of the copy target.
    --- o_str: LOB locator of source for the copy.
    --- clob_len: Number of bytes (for BLOBs) or characters (for CLOBs)
    --- to copy.
    --- 1: Offset in bytes or characters in the destination LOB
    --- (origin: 1) for the start of the copy.
    --- next_pos+1: Offset in bytes or characters in the source LOB
    --- (origin: 1) for the start of the copy.
    dbms_lob.copy(wk_clob, o_str, clob_len, 1, next_pos+1);
    end if;
    else
    o_token:= dbms_lob.substr( o_str, MAX_STR_LEN, 1);
    end if;
    o_str := wk_clob;
    RETURN(o_token);
    EXCEPTION
    when others then
    null;
    -- dbms_output.put_line('Error:'||SQLCODE||',text:'||SQLERRM);
    END word_parse_trim_lob_FUN;

  • UDM for long running sql

    Hi
    I am planning to use enterprise manager grid control to create a UDM for the following sql that would alert me for the sql that is running for more then a hour for all databases any ideas on how to do this
    SELECT
            substr(swn.sql_text,40),
            ||'SQL is Running on Instance ' ||s.inst_id || 'Since '|| ROUND(sl.elapsed_seconds/60) elapsed_mins,      
    FROM   gv$session_longops sl,
    gv$session s ,
    gv$sql swn
    WHERE  s.sid     = sl.sid
    AND    s.inst_id = sl.inst_id
    AND    s.serial# = sl.serial#
    AND    s.inst_id = swn.inst_id
    AND    s.sql_address = swn.address
    AND    s.sql_hash_value = swn.hash_value
    AND    sl.sofar  <> sl.totalwork
    AND    sl.totalwork <> 0
    AND    round((sl.elapsed_seconds)/60,0) > 60
    order by 7Edited by: user9243284 on Jun 7, 2010 3:48 AM

    I think you should specify:
    SQL query output: two columns
    Metric Type: String
    and the following query:
    SELECT 'NA',0
    from dual
    union
    SELECT distinct '( ' ||i.instance_name ||','|| sl.sid ||','|| sl.serial# ||', ) ' || substr(s.sql_text,1,1000) sql, ROUND(sl.elapsed_seconds/60) mins
    FROM gv$session_longops sl,
    gv$sql s,
    gv$instance i
    WHERE sl.sofar = sl.totalwork
    AND sl.totalwork = 0
    AND sl.inst_id = s.inst_id (+)
    AND sl.sql_address = s.address (+)
    AND sl.sql_hash_value = s.hash_value (+)
    AND sl.inst_id = i.inst_id
    use the select from dual, to make sure your query allways returns at least one row.
    BTW, you will find some examples of UDM creation on my blog.
    Regards
    Rob
    http://oemgc.wordpress.com

  • SUBSTR & Max Char Fetched trebled

    We've been encountering virtual memory problems with Viewer (disco 4.1.48 , I know prob solved in 10g - no in a position to go there yet!!) where the result of a PL/SQL function sets the Max Char Fetched to 2000/4000 , hence we hit the issue with the MaxVirtualHeapMem being breached.
    To negate this issue we have SUBSTR'd all function calls e.g. SUBSTR(function_call,1,150) - the report works but I am seeing some strange behaviour in Admin. For the 150 character example the Max char fetched property shows 450, all other SUBSTRs in both views and sql folders are precisely three times the amount in the Max char fetched property.
    As volumes increase I suspect that we will continue to hit memory problems because of this.
    Has anyone come across this strange behaviour before? Workarounds suggestions welcomed.
    Matt

    Russ,
    Thanks for having a look, I think we've got a bit confused. 'Max char fetched' is the item property, you can see in Admin - Disco reserves this space for the column whilst running the query .
    Yes, unfortunately we are having to substr all function calls in DB views as Disco defaults to 2000/4000 chars for these items - have a look at some of the standard BIS BAs or see Metalink Note:270273.1 for info. This we can live with and its fixed in 10g...(uuughhh I hate 4i after having done a few 10g implementations). Then we'll remove them after upgrade to help the CPU cause, but it could be many months away.
    The current problem that I'm finding strange, is the tripling issue. If a DB view has and item say SUBSTR(emps.employee_longname,1,150) - no function calls involved, this then appears in the folder with the item property 'Max char fetched' as 450 - I would have thought that this should be 150.
    In all the years of working with Disco, I never noticed this behaviour before - though I have never looked at it before. I thought I'd give the forum a try b4 raising a SR to see if somebody has encountered this.
    thanks,
    matt

  • SQL UDM

    Hi,
    I am working upon few UDM's similar to as mentioned here. I am creating a UDM so that alert get generated if user account status is locked or expired. I use the SQL STMT for this is "select count(account_status) from dba_users where account_status<>'OPEN';" , is there any way i can also get output as users for whom alert got triggered with account status. I have given the threshold as !=0 if any of the users will get status expired or locked alert will be triggered.
    Let me know if there is any possibility.
    Thanks.

    I think you should specify:
    SQL query output: two columns
    Metric Type: String
    and the following query:
    SELECT 'NA',0
    from dual
    union
    SELECT distinct '( ' ||i.instance_name ||','|| sl.sid ||','|| sl.serial# ||', ) ' || substr(s.sql_text,1,1000) sql, ROUND(sl.elapsed_seconds/60) mins
    FROM gv$session_longops sl,
    gv$sql s,
    gv$instance i
    WHERE sl.sofar = sl.totalwork
    AND sl.totalwork = 0
    AND sl.inst_id = s.inst_id (+)
    AND sl.sql_address = s.address (+)
    AND sl.sql_hash_value = s.hash_value (+)
    AND sl.inst_id = i.inst_id
    use the select from dual, to make sure your query allways returns at least one row.
    BTW, you will find some examples of UDM creation on my blog.
    Regards
    Rob
    http://oemgc.wordpress.com

  • Logical error in the query

    create table my_employee
    (id number(4)primary key,
    last_name varchar2(25),
    first_name varchar2(25),
    userid varchar2(8),
    salary number(9,2)
    I want to write an INSERT statement to MY_EMPLOYEE table . Concatenate the first letter of the first name and first seven characters of the last name to produce user ID using a single sql statement
    I wrote the query like this and i am getting logical error
    insert into my_employee
    values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SQL> insert into my_employee
    2 values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&sal
    ary);
    Enter value for id: 20
    Enter value for last_name: popopopp
    Enter value for last_name: qwertyyuu
    Enter value for salary: 300000
    old 2: values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),
    new 2: values(20,'popopopp','o',substr('o',1,1)||substr('qwertyyuu',1,7),300000)
    1 row created.
    it is asking the last_name two times

    you can do it with a .sql script
    c:\my_emp.sql
    PROMPT
    PROMPT instering my_employees
    PROMPT
    ACCEPT ID NUMBER PROMPT 'ID ? : '
    ACCEPT FIRST_NAME CHAR PROMPT 'FIRST_NAME ?: '
    ACCEPT LAST_NAME CHAR PROMPT 'LAST_NAME ?: '
    ACCEPT SALARY NUMBER PROMPT 'SALARY ? : '
    insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SELECT * FROM my_employee where id=&&id;
    and then from sqlplus @c:\my_emp.sql
    scott@ORCL> @C:\MY_EMP
    instering my_employees
    ID ? : 20
    FIRST_NAME ?: john
    LAST_NAME ?: papas
    SALARY ? : 1000
    old 1: insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary)
    new 1: insert into my_employee values( 20,'papas','john',substr('john',1,1)||substr('papas',1,7), 1000)
    1 row created.
    old 1: SELECT * FROM my_employee where id=&&id
    new 1: SELECT * FROM my_employee where id= 20
    ID LAST_NAME FIRST_NAME USERID SALARY
    20 papas john jpapas 1000
    scott@ORCL>

  • String to Row: Delimiter as part of the value

    My DB Version - 10.2.0.4.0
    I have a string like this
    with t
    as
    select q'['My column',LPAD(TRIM(my_column),4,'0'),10,10000]' str
      from dual
    select * from tI am looking for a SQL solution that will convert this string into row like this
    'My column'
    LPAD(TRIM(my_column),4,'0')
    10
    10000Normal way to convert delimited string to row would be like this
    with t
    as
    select q'['My column',LPAD(TRIM(my_column),4,'0'),10,10000]' str
      from dual
    select regexp_substr(str,'[^,]+',1,level) val
      from t
    connect by level <= length(str)-length(replace(str,','))+1But this would result in
    'My column'
    LPAD(TRIM(my_column)
    4
    '0')
    10
    10000 But this is incorrect. So any idea how to solve it?

    Karthick_Arp wrote:
    I totally understand. But we should also accept the fact that at times we get such crazy stuff to work with.
    Just hoping that some one comes up with a super cool sql to do this ;)Something like this perhaps?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select q'['My column',LPAD(TRIM(my_column),4,'0'),10,10000]' str from dual)
      2      ,x as (select regexp_substr(str, '[^(]+', 1, rownum) str, rownum as lvl
      3             from t
      4             connect by rownum <= length(regexp_replace(str, '[^(]'))+1
      5            )
      6      ,y as (select x.str as orig_str, lvl
      7                   ,replace(regexp_replace(x.str, '[^\)]+$'),',','~')||regexp_substr(x.str, '[^\)]+$') as str2
      8             from x
      9            )
    10      ,z as (select ltrim(sys_connect_by_path(str2, '('),'(') as str
    11             from y
    12             where connect_by_isleaf = 1
    13             connect by lvl = prior lvl + 1
    14             start with lvl = 1
    15            )
    16  --
    17  select rownum rn, replace(regexp_substr(str, '[^,]+', 1, rownum),'~',',') str
    18  from z
    19* connect by rownum <= length(regexp_replace(str, '[^,]'))+1
    SQL> /
            RN STR
             1 'My column'
             2 LPAD(TRIM(my_column),4,'0')
             3 10
             4 10000
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select q'['My column',LPAD(TRIM(SUBSTR(my_column,4)),4,'0'),10,SUBSTR('FRED',4),10000]' str from dual)
      2      ,x as (select regexp_substr(str, '[^(]+', 1, rownum) str, rownum as lvl
      3             from t
      4             connect by rownum <= length(regexp_replace(str, '[^(]'))+1
      5            )
      6      ,y as (select x.str as orig_str, lvl
      7                   ,replace(regexp_replace(x.str, '[^\)]+$'),',','~')||regexp_substr(x.str, '[^\)]+$') as str2
      8             from x
      9            )
    10      ,z as (select ltrim(sys_connect_by_path(str2, '('),'(') as str
    11             from y
    12             where connect_by_isleaf = 1
    13             connect by lvl = prior lvl + 1
    14             start with lvl = 1
    15            )
    16  --
    17  select rownum rn, replace(regexp_substr(str, '[^,]+', 1, rownum),'~',',') str
    18  from z
    19* connect by rownum <= length(regexp_replace(str, '[^,]'))+1
    SQL> /
            RN STR
             1 'My column'
             2 LPAD(TRIM(SUBSTR(my_column,4)),4,'0')
             3 10
             4 SUBSTR('FRED',4)
             5 10000
    SQL>Seems to work, but don't hold me to that. :D

  • Compression

    When i am trying to do compression, iam getting following error message..
    Job started
    Step 001 started (program RSCOMP1, variant &0000000000017, user ID BIADMIN)
    Performing check and potential update for status control table
    FB RSM1_CHECK_DM_GOT_REQUEST called from PRG RSSM_PROCESS_COMPRESS; row 000200
    Request '653'; DTA 'Z0SD_C03'; action 'C'; with dialog 'X'
    Leave RSM1_CHECK_DM_GOT_REQUEST in row 70; Req_State ''
    SQL: 12.01.2009 16:37:54 BIADMIN
    DROP TRIGGER "/BI0/0500000068"
    SQL-END: 12.01.2009 16:37:54 00:00:00
    SQL: 12.01.2009 16:37:54 BIADMIN
    DROP TABLE "/BI0/0400000069I"
    SQL-END: 12.01.2009 16:37:54 00:00:00
    SQL-ERROR: 942 ORA-00942: table or view does not exist
    SQL: 12.01.2009 16:37:54 BIADMIN
    DROP TABLE "/BI0/0400000069R"
    SQL-END: 12.01.2009 16:37:54 00:00:00
    SQL-ERROR: 942 ORA-00942: table or view does not exist
    SQL: 12.01.2009 16:37:54 BIADMIN
    DROP TABLE "/BI0/0400000069F"
    SQL-END: 12.01.2009 16:37:54 00:00:00
    SQL-ERROR: 942 ORA-00942: table or view does not exist
    SQL: 12.01.2009 16:37:55 BIADMIN
    CREATE OR REPLACE PROCEDURE "/BI0/0400000069"
    (P_PDIMID            IN  NUMBER, P_PDIMID_NORMAL
       IN  NUMBER, P_PDIMID_REF_POINT  IN  NUMBER,
    P_UPDATE_REF_POINT  IN  CHAR, P_NO_UPDATE_PHASE
    IN  CHAR, P_SELECT_CNT        OUT NUMBER,
    P_INSERT_CNT        OUT NUMBER, P_UPDATE_CNT
      OUT NUMBER, P_DELETE_CNT        OUT NUMBER,
    P_REF_INS_CNT       OUT NUMBER, P_REF_UPD_CNT
      OUT NUMBER, P_SQLCODE           OUT NUMBER,
    P_SQLERRM           OUT VARCHAR2 ) AS
    E_MULTIPLE_UPDATES         EXCEPTION;
    E_MULTIPLE_REF_UPDATES     EXCEPTION;
    E_MULTIPLE_INITIALIZATIONS EXCEPTION; V_ROWID
                ROWID; V_ROW
    /BIC/FZ0SD_C03%ROWTYPE; V_NO_UPD_NEEDED_CNT
    NUMBER; V_RECORDTP
    /BIC/DZ0SD_C03P."SID_0RECORDTP"%TYPE; CURSOR
    SELECT_CSR (P_PDIMID NUMBER) IS SELECT ROWID ,
    KEY_Z0SD_C03T , "KEY_Z0SD_C03U" ,
    KEY_Z0SD_C031 , "KEY_Z0SD_C032" ,
    KEY_Z0SD_C033 , "KEY_Z0SD_C034" ,
    KEY_Z0SD_C035 , "KEY_Z0SD_C036" ,
    KEY_Z0SD_C037 , "KEY_Z0SD_C038" ,
    KEY_Z0SD_C039 , "KEY_Z0SD_C03A" ,
    KEY_Z0SD_C03B , "ACT_DL_QTY" , "BILL_QTY" ,
    COST , "COST_VAL_S" , "DEL_GR_WT" , "DEL_VAL" ,
    DENOMINTR , "DENOMINTRZ" , "DOCUMENTS" ,
    DOC_ITEMS , "EXCHG_CRD" , "EXCHG_STAT" ,
    EXRATE_ACC , "GROSS_VAL" , "GROSS_WGT" ,
    GRS_WGT_DL , "GR_WT_KG" , "HDCNT_LAST" ,
    INV_QTY , "NETVAL_INV" , "NET_PRICE" ,
    NET_VALUE , "NET_VAL_S" , "NET_WGT_DL" ,
    NET_WT_AP , "NO_INV_IT" , "NO_QUOT" ,
    NT_WT_KG , "NUMERATOR" , "NUMERATORZ" ,
    OPENORDQTY , "OPENORDVAL" , "OPORDQTYBM" ,
    OPORDVALSC , "QUANT_B" , "SCALE_QTY" ,
    SHP_PR_TMV , "SUBTOTAL_1" , "SUBTOTAL_2" ,
    SUBTOTAL_3 , "SUBTOT_1S" , "SUBTOT_2S" ,
    TAX_AMOUNT , "TAX_VALUE" , "VOLUME_AP" ,
    VOLUME_CDM , "VOLUME_DL" , "SID_0CALMONTH" FROM
    "/BIC/FZ0SD_C03" WHERE "KEY_Z0SD_C03P" =
    P_PDIMID; BEGIN P_SELECT_CNT            := 0;
    P_INSERT_CNT            := 0; P_UPDATE_CNT
        := 0; P_DELETE_CNT            := 0;
    P_REF_INS_CNT           := 0; P_REF_UPD_CNT
        := 0; P_SQLCODE               := 0; P_SQLERRM
                  := 'NO ERROR'; V_NO_UPD_NEEDED_CNT
       := 0; V_RECORDTP              := 0; IF
    P_NO_UPDATE_PHASE = ' ' THEN OPEN SELECT_CSR
    (P_PDIMID); LOOP <<BEGIN_OF_LOOP>> FETCH
    SELECT_CSR INTO V_ROWID , V_ROW."KEY_Z0SD_C03T" ,
    V_ROW."KEY_Z0SD_C03U" , V_ROW."KEY_Z0SD_C031" ,
    V_ROW."KEY_Z0SD_C032" , V_ROW."KEY_Z0SD_C033" ,
    V_ROW."KEY_Z0SD_C034" , V_ROW."KEY_Z0SD_C035" ,
    V_ROW."KEY_Z0SD_C036" , V_ROW."KEY_Z0SD_C037" ,
    V_ROW."KEY_Z0SD_C038" , V_ROW."KEY_Z0SD_C039" ,
    V_ROW."KEY_Z0SD_C03A" , V_ROW."KEY_Z0SD_C03B" ,
    V_ROW."ACT_DL_QTY" , V_ROW."BILL_QTY" ,
    V_ROW."COST" , V_ROW."COST_VAL_S" ,
    V_ROW."DEL_GR_WT" , V_ROW."DEL_VAL" ,
    V_ROW."DENOMINTR" , V_ROW."DENOMINTRZ" ,
    V_ROW."DOCUMENTS" , V_ROW."DOC_ITEMS" ,
    V_ROW."EXCHG_CRD" , V_ROW."EXCHG_STAT" ,
    V_ROW."EXRATE_ACC" , V_ROW."GROSS_VAL" ,
    V_ROW."GROSS_WGT" , V_ROW."GRS_WGT_DL" ,
    V_ROW."GR_WT_KG" , V_ROW."HDCNT_LAST" ,
    V_ROW."INV_QTY" , V_ROW."NETVAL_INV" ,
    V_ROW."NET_PRICE" , V_ROW."NET_VALUE" ,
    V_ROW."NET_VAL_S" , V_ROW."NET_WGT_DL" ,
    V_ROW."NET_WT_AP" , V_ROW."NO_INV_IT" ,
    V_ROW."NO_QUOT" , V_ROW."NT_WT_KG" ,
    V_ROW."NUMERATOR" , V_ROW."NUMERATORZ" ,
    V_ROW."OPENORDQTY" , V_ROW."OPENORDVAL" ,
    V_ROW."OPORDQTYBM" , V_ROW."OPORDVALSC" ,
    V_ROW."QUANT_B" , V_ROW."SCALE_QTY" ,
    V_ROW."SHP_PR_TMV" , V_ROW."SUBTOTAL_1" ,
    V_ROW."SUBTOTAL_2" , V_ROW."SUBTOTAL_3" ,
    V_ROW."SUBTOT_1S" , V_ROW."SUBTOT_2S" ,
    V_ROW."TAX_AMOUNT" , V_ROW."TAX_VALUE" ,
    V_ROW."VOLUME_AP" , V_ROW."VOLUME_CDM" ,
    V_ROW."VOLUME_DL" , V_ROW."SID_0CALMONTH" ; IF
    SELECT_CSR%NOTFOUND THEN CLOSE SELECT_CSR; EXIT;
    ELSE P_SELECT_CNT := P_SELECT_CNT + 1; END IF; IF
    V_RECORDTP = 0 THEN UPDATE /*+
    INDEX("/BIC/EZ0SD_C03" "/BIC/EZ0SD_C03~P"
    /BIC/EZ0SD_C03~0) */ "/BIC/EZ0SD_C03" SET
    ACT_DL_QTY = "ACT_DL_QTY" + V_ROW."ACT_DL_QTY"
    , "BILL_QTY" = "BILL_QTY" + V_ROW."BILL_QTY" ,
    COST = "COST" + V_ROW."COST" , "COST_VAL_S" =
    COST_VAL_S + V_ROW."COST_VAL_S" , "DEL_GR_WT" =
    DEL_GR_WT + V_ROW."DEL_GR_WT" , "DEL_VAL" =
    DEL_VAL + V_ROW."DEL_VAL" , "DENOMINTR" =
    DENOMINTR + V_ROW."DENOMINTR" , "DENOMINTRZ" =
    DENOMINTRZ + V_ROW."DENOMINTRZ" , "DOCUMENTS" =
    DOCUMENTS + V_ROW."DOCUMENTS" , "DOC_ITEMS" =
    DOC_ITEMS + V_ROW."DOC_ITEMS" , "EXCHG_CRD" =
    EXCHG_CRD + V_ROW."EXCHG_CRD" , "EXCHG_STAT" =
    EXCHG_STAT + V_ROW."EXCHG_STAT" , "EXRATE_ACC"
    = "EXRATE_ACC" + V_ROW."EXRATE_ACC" , "GROSS_VAL"
    = "GROSS_VAL" + V_ROW."GROSS_VAL" , "GROSS_WGT" =
    GROSS_WGT + V_ROW."GROSS_WGT" , "GRS_WGT_DL" =
    GRS_WGT_DL + V_ROW."GRS_WGT_DL" , "GR_WT_KG" =
    GR_WT_KG + V_ROW."GR_WT_KG" , "HDCNT_LAST" =
    HDCNT_LAST + V_ROW."HDCNT_LAST" , "INV_QTY" =
    INV_QTY + V_ROW."INV_QTY" , "NETVAL_INV" =
    NETVAL_INV + V_ROW."NETVAL_INV" , "NET_PRICE" =
    NET_PRICE + V_ROW."NET_PRICE" , "NET_VALUE" =
    NET_VALUE + V_ROW."NET_VALUE" , "NET_VAL_S" =
    NET_VAL_S + V_ROW."NET_VAL_S" , "NET_WGT_DL" =
    NET_WGT_DL + V_ROW."NET_WGT_DL" , "NET_WT_AP" =
    NET_WT_AP + V_ROW."NET_WT_AP" , "NO_INV_IT" =
    NO_INV_IT + V_ROW."NO_INV_IT" , "NO_QUOT" =
    NO_QUOT + V_ROW."NO_QUOT" , "NT_WT_KG" =
    NT_WT_KG + V_ROW."NT_WT_KG" , "NUMERATOR" =
    NUMERATOR + V_ROW."NUMERATOR" , "NUMERATORZ" =
    NUMERATORZ + V_ROW."NUMERATORZ" , "OPENORDQTY"
    = "OPENORDQTY" + V_ROW."OPENORDQTY" ,
    OPENORDVAL = "OPENORDVAL" + V_ROW."OPENORDVAL"
    , "OPORDQTYBM" = "OPORDQTYBM" +
    V_ROW."OPORDQTYBM" , "OPORDVALSC" = "OPORDVALSC"
    + V_ROW."OPORDVALSC" , "QUANT_B" = "QUANT_B" +
    V_ROW."QUANT_B" , "SCALE_QTY" = "SCALE_QTY" +
    V_ROW."SCALE_QTY" , "SHP_PR_TMV" = "SHP_PR_TMV" +
    V_ROW."SHP_PR_TMV" , "SUBTOTAL_1" = "SUBTOTAL_1"
    + V_ROW."SUBTOTAL_1" , "SUBTOTAL_2" =
    SUBTOTAL_2 + V_ROW."SUBTOTAL_2" , "SUBTOTAL_3"
    = "SUBTOTAL_3" + V_ROW."SUBTOTAL_3" , "SUBTOT_1S"
    = "SUBTOT_1S" + V_ROW."SUBTOT_1S" , "SUBTOT_2S" =
    SUBTOT_2S + V_ROW."SUBTOT_2S" , "TAX_AMOUNT" =
    TAX_AMOUNT + V_ROW."TAX_AMOUNT" , "TAX_VALUE" =
    TAX_VALUE + V_ROW."TAX_VALUE" , "VOLUME_AP" =
    VOLUME_AP + V_ROW."VOLUME_AP" , "VOLUME_CDM" =
    VOLUME_CDM + V_ROW."VOLUME_CDM" , "VOLUME_DL" =
    VOLUME_DL + V_ROW."VOLUME_DL" WHERE
    KEY_Z0SD_C03P = P_PDIMID_NORMAL AND
    KEY_Z0SD_C03T = V_ROW."KEY_Z0SD_C03T" AND
    KEY_Z0SD_C03U = V_ROW."KEY_Z0SD_C03U" AND
    KEY_Z0SD_C031 = v_row."KEY_Z0SD_C031" AND
    KEY_Z0SD_C032 = v_row."KEY_Z0SD_C032" AND
    KEY_Z0SD_C033 = v_row."KEY_Z0SD_C033" AND
    KEY_Z0SD_C034 = v_row."KEY_Z0SD_C034" AND
    KEY_Z0SD_C035 = v_row."KEY_Z0SD_C035" AND
    KEY_Z0SD_C036 = v_row."KEY_Z0SD_C036" AND
    KEY_Z0SD_C037 = v_row."KEY_Z0SD_C037" AND
    KEY_Z0SD_C038 = v_row."KEY_Z0SD_C038" AND
    KEY_Z0SD_C039 = v_row."KEY_Z0SD_C039" AND
    KEY_Z0SD_C03A = v_row."KEY_Z0SD_C03A" AND
    KEY_Z0SD_C03B = v_row."KEY_Z0SD_C03B" AND
    SID_0CALMONTH = V_ROW."SID_0CALMONTH" ; IF
    SQL%ROWCOUNT = 1 THEN P_UPDATE_CNT :=
    P_UPDATE_CNT + SQL%ROWCOUNT; elsif SQL%ROWCOUNT >
    1 then raise e_multiple_updates; else INSERT INTO
    /BI0/0400000069I VALUES (V_ROWID); END IF; END
    IF; END LOOP; end if; IF V_RECORDTP = 0 THEN if
    p_update_cnt != 0 OR V_NO_UPD_NEEDED_CNT != 0
    then INSERT INTO "/BIC/EZ0SD_C03" (
    KEY_Z0SD_C03P , "KEY_Z0SD_C03T" ,
    KEY_Z0SD_C03U , "KEY_Z0SD_C031" ,
    KEY_Z0SD_C032 , "KEY_Z0SD_C033" ,
    KEY_Z0SD_C034 , "KEY_Z0SD_C035" ,
    KEY_Z0SD_C036 , "KEY_Z0SD_C037" ,
    KEY_Z0SD_C038 , "KEY_Z0SD_C039" ,
    KEY_Z0SD_C03A , "KEY_Z0SD_C03B" ,
    SID_0CALMONTH , "ACT_DL_QTY" , "BILL_QTY" ,
    COST , "COST_VAL_S" , "DEL_GR_WT" , "DEL_VAL" ,
    DENOMINTR , "DENOMINTRZ" , "DOCUMENTS" ,
    DOC_ITEMS , "EXCHG_CRD" , "EXCHG_STAT" ,
    EXRATE_ACC , "GROSS_VAL" , "GROSS_WGT" ,
    GRS_WGT_DL , "GR_WT_KG" , "HDCNT_LAST" ,
    INV_QTY , "NETVAL_INV" , "NET_PRICE" ,
    NET_VALUE , "NET_VAL_S" , "NET_WGT_DL" ,
    NET_WT_AP , "NO_INV_IT" , "NO_QUOT" ,
    NT_WT_KG , "NUMERATOR" , "NUMERATORZ" ,
    OPENORDQTY , "OPENORDVAL" , "OPORDQTYBM" ,
    OPORDVALSC , "QUANT_B" , "SCALE_QTY" ,
    SHP_PR_TMV , "SUBTOTAL_1" , "SUBTOTAL_2" ,
    SUBTOTAL_3 , "SUBTOT_1S" , "SUBTOT_2S" ,
    TAX_AMOUNT , "TAX_VALUE" , "VOLUME_AP" ,
    VOLUME_CDM , "VOLUME_DL" ) SELECT /*+
    FIRST_ROWS PARALLEL (FACT , DEFAULT ) */
    P_PDIMID_NORMAL , FACT."KEY_Z0SD_C03T" ,
    FACT."KEY_Z0SD_C03U" , FACT."KEY_Z0SD_C031" ,
    FACT."KEY_Z0SD_C032" , FACT."KEY_Z0SD_C033" ,
    FACT."KEY_Z0SD_C034" , FACT."KEY_Z0SD_C035" ,
    FACT."KEY_Z0SD_C036" , FACT."KEY_Z0SD_C037" ,
    FACT."KEY_Z0SD_C038" , FACT."KEY_Z0SD_C039" ,
    FACT."KEY_Z0SD_C03A" , FACT."KEY_Z0SD_C03B" ,
    SID_0CALMONTH , SUM (FACT."ACT_DL_QTY") , SUM
    (FACT."BILL_QTY") , SUM (FACT."COST") , SUM
    (FACT."COST_VAL_S") , SUM (FACT."DEL_GR_WT") ,
    SUM (FACT."DEL_VAL") , SUM (FACT."DENOMINTR") ,
    SUM (FACT."DENOMINTRZ") , SUM (FACT."DOCUMENTS")
    , SUM (FACT."DOC_ITEMS") , SUM (FACT."EXCHG_CRD")
    , SUM (FACT."EXCHG_STAT") , SUM
    (FACT."EXRATE_ACC") , SUM (FACT."GROSS_VAL") ,
    SUM (FACT."GROSS_WGT") , SUM (FACT."GRS_WGT_DL")
    , SUM (FACT."GR_WT_KG") , SUM (FACT."HDCNT_LAST")
    , SUM (FACT."INV_QTY") , SUM (FACT."NETVAL_INV")
    , SUM (FACT."NET_PRICE") , SUM (FACT."NET_VALUE")
    , SUM (FACT."NET_VAL_S") , SUM
    (FACT."NET_WGT_DL") , SUM (FACT."NET_WT_AP") ,
    SUM (FACT."NO_INV_IT") , SUM (FACT."NO_QUOT") ,
    SUM (FACT."NT_WT_KG") , SUM (FACT."NUMERATOR") ,
    SUM (FACT."NUMERATORZ") , SUM (FACT."OPENORDQTY")
    , SUM (FACT."OPENORDVAL") , SUM
    (FACT."OPORDQTYBM") , SUM (FACT."OPORDVALSC") ,
    SUM (FACT."QUANT_B") , SUM (FACT."SCALE_QTY") ,
    SUM (FACT."SHP_PR_TMV") , SUM (FACT."SUBTOTAL_1")
    , SUM (FACT."SUBTOTAL_2") , SUM
    (FACT."SUBTOTAL_3") , SUM (FACT."SUBTOT_1S") ,
    SUM (FACT."SUBTOT_2S") , SUM (FACT."TAX_AMOUNT")
    , SUM (FACT."TAX_VALUE") , SUM (FACT."VOLUME_AP")
    , SUM (FACT."VOLUME_CDM") , SUM
    (FACT."VOLUME_DL") FROM "/BIC/FZ0SD_C03" FACT
    WHERE FACT.ROWID IN ( SELECT ENTRY FROM
    /BI0/0400000069I ) GROUP BY
    FACT."KEY_Z0SD_C03T" , FACT."KEY_Z0SD_C03U" ,
    FACT."KEY_Z0SD_C031" , FACT."KEY_Z0SD_C032" ,
    FACT."KEY_Z0SD_C033" , FACT."KEY_Z0SD_C034" ,
    FACT."KEY_Z0SD_C035" , FACT."KEY_Z0SD_C036" ,
    FACT."KEY_Z0SD_C037" , FACT."KEY_Z0SD_C038" ,
    FACT."KEY_Z0SD_C039" , FACT."KEY_Z0SD_C03A" ,
    FACT."KEY_Z0SD_C03B" , FACT."SID_0CALMONTH" ;
    P_INSERT_CNT := SQL%ROWCOUNT; else INSERT INTO
    /BIC/EZ0SD_C03 ( "KEY_Z0SD_C03P" ,
    KEY_Z0SD_C03T , "KEY_Z0SD_C03U" ,
    KEY_Z0SD_C031 , "KEY_Z0SD_C032" ,
    KEY_Z0SD_C033 , "KEY_Z0SD_C034" ,
    KEY_Z0SD_C035 , "KEY_Z0SD_C036" ,
    KEY_Z0SD_C037 , "KEY_Z0SD_C038" ,
    KEY_Z0SD_C039 , "KEY_Z0SD_C03A" ,
    KEY_Z0SD_C03B , "SID_0CALMONTH" , "ACT_DL_QTY"
    , "BILL_QTY" , "COST" , "COST_VAL_S" ,
    DEL_GR_WT , "DEL_VAL" , "DENOMINTR" ,
    DENOMINTRZ , "DOCUMENTS" , "DOC_ITEMS" ,
    EXCHG_CRD , "EXCHG_STAT" , "EXRATE_ACC" ,
    GROSS_VAL , "GROSS_WGT" , "GRS_WGT_DL" ,
    GR_WT_KG , "HDCNT_LAST" , "INV_QTY" ,
    NETVAL_INV , "NET_PRICE" , "NET_VALUE" ,
    NET_VAL_S , "NET_WGT_DL" , "NET_WT_AP" ,
    NO_INV_IT , "NO_QUOT" , "NT_WT_KG" ,
    NUMERATOR , "NUMERATORZ" , "OPENORDQTY" ,
    OPENORDVAL , "OPORDQTYBM" , "OPORDVALSC" ,
    QUANT_B , "SCALE_QTY" , "SHP_PR_TMV" ,
    SUBTOTAL_1 , "SUBTOTAL_2" , "SUBTOTAL_3" ,
    SUBTOT_1S , "SUBTOT_2S" , "TAX_AMOUNT" ,
    TAX_VALUE , "VOLUME_AP" , "VOLUME_CDM" ,
    VOLUME_DL ) SELECT /*+ PARALLEL (FACT , DEFAULT
    ) */ P_PDIMID_NORMAL , FACT."KEY_Z0SD_C03T" ,
    FACT."KEY_Z0SD_C03U" , FACT."KEY_Z0SD_C031" ,
    FACT."KEY_Z0SD_C032" , FACT."KEY_Z0SD_C033" ,
    FACT."KEY_Z0SD_C034" , FACT."KEY_Z0SD_C035" ,
    FACT."KEY_Z0SD_C036" , FACT."KEY_Z0SD_C037" ,
    FACT."KEY_Z0SD_C038" , FACT."KEY_Z0SD_C039" ,
    FACT."KEY_Z0SD_C03A" , FACT."KEY_Z0SD_C03B" ,
    SID_0CALMONTH , SUM (FACT."ACT_DL_QTY") , SUM
    (FACT."BILL_QTY") , SUM (FACT."COST") , SUM
    (FACT."COST_VAL_S") , SUM (FACT."DEL_GR_WT") ,
    SUM (FACT."DEL_VAL") , SUM (FACT."DENOMINTR") ,
    SUM (FACT."DENOMINTRZ") , SUM (FACT."DOCUMENTS")
    , SUM (FACT."DOC_ITEMS") , SUM (FACT."EXCHG_CRD")
    , SUM (FACT."EXCHG_STAT") , SUM
    (FACT."EXRATE_ACC") , SUM (FACT."GROSS_VAL") ,
    SUM (FACT."GROSS_WGT") , SUM (FACT."GRS_WGT_DL")
    , SUM (FACT."GR_WT_KG") , SUM (FACT."HDCNT_LAST")
    , SUM (FACT."INV_QTY") , SUM (FACT."NETVAL_INV")
    , SUM (FACT."NET_PRICE") , SUM (FACT."NET_VALUE")
    , SUM (FACT."NET_VAL_S") , SUM
    (FACT."NET_WGT_DL") , SUM (FACT."NET_WT_AP") ,
    SUM (FACT."NO_INV_IT") , SUM (FACT."NO_QUOT") ,
    SUM (FACT."NT_WT_KG") , SUM (FACT."NUMERATOR") ,
    SUM (FACT."NUMERATORZ") , SUM (FACT."OPENORDQTY")
    , SUM (FACT."OPENORDVAL") , SUM
    (FACT."OPORDQTYBM") , SUM (FACT."OPORDVALSC") ,
    SUM (FACT."QUANT_B") , SUM (FACT."SCALE_QTY") ,
    SUM (FACT."SHP_PR_TMV") , SUM (FACT."SUBTOTAL_1")
    , SUM (FACT."SUBTOTAL_2") , SUM
    (FACT."SUBTOTAL_3") , SUM (FACT."SUBTOT_1S") ,
    SUM (FACT."SUBTOT_2S") , SUM (FACT."TAX_AMOUNT")
    , SUM (FACT."TAX_VALUE") , SUM (FACT."VOLUME_AP")
    , SUM (FACT."VOLUME_CDM") , SUM
    (FACT."VOLUME_DL") FROM "/BIC/FZ0SD_C03" FACT
    WHERE "KEY_Z0SD_C03P" = P_PDIMID GROUP BY
    FACT."KEY_Z0SD_C03T" , FACT."KEY_Z0SD_C03U" ,
    FACT."KEY_Z0SD_C031" , FACT."KEY_Z0SD_C032" ,
    FACT."KEY_Z0SD_C033" , FACT."KEY_Z0SD_C034" ,
    FACT."KEY_Z0SD_C035" , FACT."KEY_Z0SD_C036" ,
    FACT."KEY_Z0SD_C037" , FACT."KEY_Z0SD_C038" ,
    FACT."KEY_Z0SD_C039" , FACT."KEY_Z0SD_C03A" ,
    FACT."KEY_Z0SD_C03B" , FACT."SID_0CALMONTH" ;
    P_INSERT_CNT := SQL%ROWCOUNT; IF P_SELECT_CNT = 0
    THEN P_SELECT_CNT := P_INSERT_CNT; END IF; end
    if; END IF; UPDATE RSMDATASTATE SET COMPR_DUAL =
    (SELECT "SID_0REQUID" FROM "/BIC/DZ0SD_C03P"
    WHERE "DIMID" = P_PDIMID ) WHERE INFOCUBE =
    'Z0SD_C03'; DELETE FROM "/BIC/DZ0SD_C03P" WHERE
    DIMID = P_PDIMID; P_SQLCODE := 0; EXCEPTION
    WHEN NO_DATA_FOUND THEN P_SQLCODE     := SQLCODE;
    P_SQLERRM     := SUBSTR(SQLERRM,1,255); WHEN
    E_MULTIPLE_INITIALIZATIONS THEN ROLLBACK;
    P_INSERT_CNT  := 0; P_UPDATE_CNT  := 0;
    P_DELETE_CNT  := 0; P_REF_INS_CNT := 0;
    P_REF_UPD_CNT := 0; P_SQLCODE     := 9998;
    P_SQLERRM     := 'Multiple Initialisation for the
    same Entry'; WHEN E_MULTIPLE_UPDATES THEN
    ROLLBACK; P_INSERT_CNT  := 0; P_UPDATE_CNT  := 0;
    P_DELETE_CNT  := 0; P_REF_INS_CNT := 0;
    P_REF_UPD_CNT := 0; P_SQLCODE     := 9999;
    P_SQLERRM     := 'Multiple Entries with same Key
    in Request 0'; WHEN E_MULTIPLE_REF_UPDATES THEN
    ROLLBACK; P_INSERT_CNT  := 0; P_UPDATE_CNT  := 0;
    P_DELETE_CNT  := 0; P_REF_INS_CNT := 0;
    P_REF_UPD_CNT := 0; P_SQLCODE     := 9997;
    P_SQLERRM     := 'Multiple Entries with same Key
    in REF-Request'; WHEN OTHERS THEN ROLLBACK;
    P_INSERT_CNT  := 0; P_UPDATE_CNT  := 0;
    P_DELETE_CNT  := 0; P_REF_INS_CNT := 0;
    P_REF_UPD_CNT := 0; P_SQLCODE     := SQLCODE;
    P_SQLERRM     := SUBSTR(SQLERRM,1,255); END;
    SQL-END: 12.01.2009 16:37:55 00:00:00
    SQL: 12.01.2009 16:37:55 BIADMIN
    ALTER TABLE "/BIC/FZ0SD_C03" MONITORING
    SQL-END: 12.01.2009 16:37:55 00:00:00
    START cond CUBE Z0SD_C03 at 163755 on 20090112 maxreqid       653 maxcnsid         0 refpoint update + NO NULL ELIM
    System error: ORA-12801: error signaled in parallel query server
    System error:  P003
    System error: ed
    System error: CONDENSE_FACTTABLE-5- ERROR:12801-
    Collapse terminated: Data target Z0SD_C03, from  to 653
    START cond CUBE Z0SD_C03 at 163755 on 20090112 maxreqid       653 maxcnsid         0 refpoint update + NO NULL ELIM
    System error: ORA-12801: error signaled in parallel query server
    System error:  P003
    System error: ed
    System error: CONDENSE_FACTTABLE-5- ERROR:12801-
    Collapse terminated: Data target Z0SD_C03, from  to                                               653
    Report RSCOMP1 ended with errors
    Job cancelled after system exception ERROR_MESSAGE

    usually the number of records is not an issue ... we have successfully condensed requests with 40 to 50 million records.....
    What you need to make sure is :
    1. Make sure that archive logs are not full
    2. Make sure that PSAPUNDO table space has space for your request...
    3. No loads happen to the cube / attribute change tuns are not happening....
    THings that might be more useful are :
    1. Time log for the job in SM37
    2. Version and SP for your BI system.

  • How to Read the String and break them in to TUPULES

    HI ALL,
    i have one String like THE STRING IS --- ---- --- >>
    3122078,12/12/2005
    3122079,12/1/1988
    3122076,12/12/1999
    I want to break them into STR :=3122078 and STR1:=12/12/2005 .

    SQL> select substr('3122078,12/12/2005',1,instr('3122078,12/12/2005',',')-1) from dual;
    SUBSTR(
    3122078
    SQL> select substr('3122078,12/12/2005',instr('3122078,12/12/2005',',')+1) from dual;
    SUBSTR('31
    12/12/2005
    SQL>

  • Problem in creating package

    When I am creating the following package in Oracle then it gives error. Can any body tell me what is the problem and how can I rectify the error.
    I am using the following version
    Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
    PL/SQL Release 8.1.5.0.0 - Production
    CORE Version 8.1.3.0.0 - Production
    TNS for Solaris: Version 8.1.5.0.0 - Production
    NLSRTL Version 3.4.0.0.0 - Production
    create or replace package aa_tt is
    type SelCursor is REF CURSOR;
    type AuErrCursor is REF CURSOR;
    procedure a_ret(p_KeyWord IN VARCHAR2,
    p_SelCursor               OUT      SelCursor,
    p_ErrCursor               OUT      AuErrCursor);
    end aa_tt;
    create or replace package body aa_tt is
    isACTIVE constant number(1):= 1;
    isNOTACTIVE constant number(1):= 0;
    p_returnVal number;
    p_returnText varchar2(500);
    p_Error_text varchar2(500);
    p_ORA_Error_Num number;
    p_Rowcount number;
    p_ORA_Error_Text varchar2(500);
    procedure a_ret(p_KeyWord IN VARCHAR2,
    p_SelCursor               OUT      SelCursor,
    p_ErrCursor               OUT      AuErrCursor)
    IS
    V_Cursor SelCursor;
    E_Aucursor AuErrCursor;
    p_RowNo NUMBER;
    begin
    OPEN V_Cursor FOR
    SELECT ROWNUM,t.MSG
    FROM (
    SELECT a.title ||' by '|| initcap(a.athr_director) ||' Rs.'|| b.base_price_inr MSG
    FROM oxf_cont_mgmt_disp_table a,
    oxf_sku_vep_mstr b
    WHERE a.sku= b.sku
    AND a.sku_srl_no = b.sku_srl_no
    AND a.category_id='B014'
    AND a.displayflag='Y'
    AND a.itemflag='MS'
    ORDER BY a.pref_no) t
    WHERE rownum<3
    p_SelCursor:= V_Cursor;
    p_returnText := ' Record successfully Fatched';
    p_ReturnVal := 1;
    p_ORA_Error_Num := SQLCODE;
    p_ORA_Error_Text := SUBSTR(SQLERRM,1,255);
    p_RowCount := SQL%ROWCOUNT;
    OPEN E_AUCURSOR for
    select p_returnval, p_returnText, p_RowCount,p_ORA_Error_Num, p_ORA_Error_Text from dual;
    p_errCursor := E_AUCURSOR;
    end a_ret;
    end aa_tt;
    /

    also try to use dynamic cursor
    SQL> create or replace package aa_tt is
    2 type SelCursor is REF CURSOR;
    3 type AuErrCursor is REF CURSOR;
    4 procedure a_ret(p_KeyWord IN VARCHAR2,
    5 p_SelCursor OUT SelCursor,
    6 p_ErrCursor OUT AuErrCursor);
    7 end aa_tt;
    8 .
    SQL> /
    Package created.
    SQL> create or replace package body aa_tt is
    2 isACTIVE constant number(1):= 1;
    3 isNOTACTIVE constant number(1):= 0;
    4 p_returnVal number;
    5 p_returnText varchar2(500);
    6 p_Error_text varchar2(500);
    7 p_ORA_Error_Num number;
    8 p_Rowcount number;
    9 p_ORA_Error_Text varchar2(500);
    10 procedure a_ret(p_KeyWord IN VARCHAR2,
    11 p_SelCursor OUT SelCursor,
    12 p_ErrCursor OUT AuErrCursor) IS
    13 V_Cursor SelCursor;
    14 E_Aucursor AuErrCursor;
    15 p_RowNo NUMBER;
    16 strg VARCHAR2(200);
    17 "ret V_CURSOR%TYPE;
    18 begin
    19 strg :='SELECT ROWNUM,t.ename
    20 FROM (
    21 SELECT *
    22 FROM emp a
    23 ORDER BY a.ename) t
    24 WHERE rownum<3';
    25 OPEN v_cursor FOR strg;
    26 LOOP
    27 FETCH v_cursor INTO ret;
    28 EXIT WHEN v_cursor%NOTFOUND;
    29 p_SelCursor:= V_Cursor;
    30 END LOOP;
    31 CLOSE v_cursor;
    32 END;
    33 END;
    34 /
    Package body created.Khurram

Maybe you are looking for