Reg : print spaces in pl/sql block

Hi friends,
How can i print spaces in pl/sql block .
Eg :
1
'onespace '1
'2 spaces'1
'3spaces'1
etc..
Thanks in Advance,
Chinnu.
Edited by: chinnu on Jul 8, 2009 10:55 PM
Edited by: chinnu on Jul 8, 2009 10:56 PM

Can you please elaborate more on your requirement?
What data is in your tables? What outcome do you expect?
Use around your code to preserve formatting..
Edited by: Alex Nuijten on Jul 9, 2009 8:00 AM                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • How to print/store in file the ref cursor in pl/sql block ?

    How to print/store in file the ref cursor in pl/sql block ?.

    How to print/store in file the ref cursor in pl/sql block ?.You question is quite confusing?
    So, i'm providing link in this manner.
    For RefCursor,
    http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
    http://www.oracle.com/technology/oramag/code/tips2003/042003.html
    For UTL_FILE,
    http://www.morganslibrary.org/reference/utl_file.html
    Regards.
    Satyaki De.
    Updated with new morgan library link.
    Edited by: Satyaki_De on Feb 24, 2010 9:03 PM

  • Call to concurrent program in a pl/sql block does not COMMIT data to table

    I have the following PL/SQL block.
                             apps.create_po(x_org_id,x_document_num,x_agent_name,x_vendor_id,x_vendor_site_id,x_ship_to_location,x_bill_to_location,x_creation_date,new_isbn,new_print_key,new_unit_setup_cost,new_unit_run_cost,x_item,x_category_id,x_item_description,x_unit_of_measure,x_quantity,x_unit_price,x_ship_to_org_id,x_promise_date,x_qty_rcv_tolerance, x_deliver_to_location,x_destination_org_id, x_destination_subinventory,x_segment2,x_segment4);
                                  COMMIT;
    FND_GLOBAL.APPS_INITIALIZE(v_user_id,v_resp_id,201);
    v_po_req_id := apps.fnd_request.submit_request('PO','POXPOPDOI',NULL,NULL,NULL,
                                  NULL,'STANDARD',NULL,'Y',NULL,'APPROVED',NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
                                  DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_po_req_id);
                                  IF v_po_req_id <> 0 THEN
                                       dbms_lock.sleep(60);
                                       dbms_output.Put_line('Sleep executed');
                                       COMMIT;
                                       select PHASE_CODE,STATUS_CODE INTO v_phase_code,v_status_code
                                       FROM FND_CONCURRENT_REQUESTS
                                       WHERE REQUEST_ID = v_po_req_id;
                                       dbms_output.put_line('After commit Phase and status codes are = '||v_phase_code || v_status_code);
                                  ELSE
                                       ROLLBACK;
                                  END IF;
                                  dbms_output.put_line('New Po is' || x_document_num);
                                  dbms_output.put_line('Quantity Is'|| x_quantity);
                                  apps.receive_po(x_document_num,x_quantity);
                                  v_rcv_req_id := apps.fnd_request.submit_request('PO','RVCTP',NULL,NULL,NULL,
                                  'BATCH',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
                                  DBMS_OUTPUT.PUT_LINE('Request ID is:' || v_rcv_req_id);
                                  IF v_rcv_req_id <> 0 THEN
                                       COMMIT;
                                       DBMS_OUTPUT.PUT_LINE('COMMITED RECEIVING');
                                  ELSE
                                       ROLLBACK;
                                  END IF;
    Presently when this block runs, i can see the new PO number created. Commit is also successfully executed. The last output for the program is
    New Po is 20651
    Quantity Is 450
    But due to some reason, the receiving program(receive_po) cannot retrieve the same PO from the base table.
    But once this pl/sql block is complete, and i call the receving procedure from a different session, the Po is retrieved and receiving against the PO is executed successfully.
    Can someone please suggest a work around ? Is the code missing something ? Since POXPOPDOI is a concurrent program which is executed as an asyncronous process, the commit statement after the call to concurent program does not work but the commit is executed only after it exits the pl/sql block.

    Thanks for responding.
    receive_po() program just inserts the data into RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE tables based on the PO that is created in the previous step. So basically the new PO created has to be received and the receive_po() just inserts data into the interface tables so that RVCTP can be called after that for receiving.
    Here is the code for the procedure.
    SET SERVEROUTPUT ON;
    --FND_GLOBAL.APPS_INITIALIZE(3,20707,201);
    --Procedure for receiving interface to load data to RCV_HEADERS_INTERFACE and RCV_TRANSACTIONS_INTERFACE
    CREATE OR REPLACE PROCEDURE receive_po (x_ponum IN VARCHAR2,x_quantity IN NUMBER) AS
    v_vendor_site_id NUMBER;
    v_vendor_id NUMBER;
    v_agent_id NUMBER;
    v_ship_to_organization_id NUMBER;
    v_item_id NUMBER;
    v_uom_code varchar2(25);
    v_subinventory varchar2(25);
    v_ship_to_location_id NUMBER;
    BEGIN
    --header information in variables
    dbms_output.put_line('Entering Receiving Insert Procedure');
    dbms_output.put_line('Po number ='||x_ponum||'$');
    dbms_output.put_line('Quantity is ='||x_quantity||'$');
    select pvsa.vendor_site_id into v_vendor_site_id
    FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
    where pha.vendor_id = pv.vendor_id
    and pv.vendor_id = pvsa.vendor_id
    and pha.segment1 = x_ponum;
    dbms_output.put_line('Vendor Site ID is' ||v_vendor_site_id);
    select pv.vendor_id into v_vendor_id
    FROM po_headers_all pha,po_vendors pv, po_vendor_sites_all pvsa
    where pha.vendor_id = pv.vendor_id
    and pv.vendor_id = pvsa.vendor_id
    and pha.segment1 = x_ponum;
    dbms_output.put_line('Vendor ID is' ||v_vendor_id);
    select plla.SHIP_TO_ORGANIZATION_ID into v_ship_to_organization_id
    from PO_HEADERS_ALL pha, PO_LINE_LOCATIONS_ALL plla
    where pha.PO_HEADER_ID = plla.PO_HEADER_ID
    and pha.segment1 = x_ponum;
    dbms_output.put_line('Ship to org is' ||v_ship_to_organization_id);
    select agent_id into v_agent_id
    FROM po_headers_all
    WHERE segment1 = x_ponum;
    dbms_output.put_line('Agent ID is' ||v_agent_id);
    --printing header table information
    dbms_output.put_line('vendor id is:'||v_vendor_id);
    dbms_output.put_line('vendor site id is:'||v_vendor_site_id);
    dbms_output.put_line('agent id is:'||v_agent_id);
    dbms_output.put_line('ship to organization id is:'||v_ship_to_organization_id);
    --line information in variables
    --derive item id
    select pla.item_id into v_item_id
    from po_headers_all pha, po_lines_all pla
    where pha.po_header_id = pla.po_header_id
    and pha.org_id = pla.org_id
    and pha.segment1 = x_ponum;
    --derive uom
    select pla.unit_meas_lookup_code into v_uom_code
    from po_headers_all pha, po_lines_all pla
    where pla.po_header_id = pha.po_header_id
    and pla.org_id = pha.org_id
    and pha.segment1 = x_ponum;
    --derive subinventory
    select pda.destination_subinventory into v_subinventory
    from po_headers_all pha, po_lines_all pla,po_distributions_all pda
    where pha.po_header_id = pla.po_header_id
    and pla.po_header_id = pda.po_header_id
    and pla.po_line_id = pda.po_line_id
    and pha.org_id = pla.org_id
    and pla.org_id = pda.org_id
    and pha.segment1 = x_ponum;
    --derive ship to location id
    select ship_to_location_id into v_ship_to_location_id
    from po_headers_all
    where segment1 = x_ponum;
    --printing transaction table details
    dbms_output.put_line('item id is:'||v_item_id);
    dbms_output.put_line('UOM is:'||v_uom_code);
    dbms_output.put_line('subinventory is:'||v_subinventory);
    dbms_output.put_line('ship to location id is:'||v_ship_to_location_id);
    --insert data into the receiving interface header table
    INSERT INTO RCV_HEADERS_INTERFACE
    HEADER_INTERFACE_ID          ,
    GROUP_ID               ,
    PROCESSING_STATUS_CODE      ,
    RECEIPT_SOURCE_CODE          ,
    TRANSACTION_TYPE          ,
    LAST_UPDATE_DATE          ,
    LAST_UPDATED_BY          ,
    LAST_UPDATE_LOGIN,
    CREATION_DATE               ,
    CREATED_BY               ,
    VENDOR_ID               ,
    VENDOR_SITE_ID               ,
    SHIP_TO_ORGANIZATION_ID ,
    EXPECTED_RECEIPT_DATE          ,
    EMPLOYEE_ID               ,
    VALIDATION_FLAG          
    SELECT
    RCV_HEADERS_INTERFACE_S.NEXTVAL,
    RCV_INTERFACE_GROUPS_S.NEXTVAL,
    'PENDING',
    'VENDOR',
    'NEW', -- 'CANCEL',
    sysdate,
    3,
    3,
    sysdate,
    3,
    v_vendor_id,
    v_vendor_site_id,
    v_ship_to_organization_id,
    sysdate+5,
    v_agent_id,
    'Y'
    FROM DUAL;
    commit;
    --insert data into the interface transaction table
    for i in 1..1 loop
    INSERT INTO RCV_TRANSACTIONS_INTERFACE
    (INTERFACE_TRANSACTION_ID     ,
    HEADER_INTERFACE_ID     ,
    GROUP_ID               ,
    LAST_UPDATE_DATE          ,
    LAST_UPDATED_BY          ,
    CREATION_DATE               ,
    CREATED_BY               ,
    LAST_UPDATE_LOGIN,
    TRANSACTION_TYPE          ,
    TRANSACTION_DATE          ,
    PROCESSING_STATUS_CODE      ,
    PROCESSING_MODE_CODE          ,
    TRANSACTION_STATUS_CODE     ,
    QUANTITY               ,
    UNIT_OF_MEASURE          ,
    ITEM_ID ,
    AUTO_TRANSACT_CODE          ,
    RECEIPT_SOURCE_CODE          ,
    SOURCE_DOCUMENT_CODE          ,
    SUBINVENTORY               ,
    DOCUMENT_NUM               ,
    SHIP_TO_LOCATION_ID           ,
    VALIDATION_FLAG
    SELECT
    RCV_TRANSACTIONS_INTERFACE_S.NEXTVAL,
    RCV_HEADERS_INTERFACE_S.CURRVAL,
    RCV_INTERFACE_GROUPS_S.CURRVAL,
    SYSDATE,
    3,
    SYSDATE,
    3,
    3,
    'RECEIVE', --'RECEIVE', -- 'SHIP', --'06-JAN-1998',--question here
    sysdate,
    'PENDING',
    'BATCH',
    'PENDING',
    x_quantity,
    v_uom_code,
    v_item_id,
    'DELIVER', -- 'RECEIVE', --'DELIVER',
    'VENDOR',
    'PO',
    v_subinventory,
    x_ponum,
    v_ship_to_location_id,
    'Y'
    FROM DUAL;
    end loop;
    commit;
    END receive_po;
    I am really stuck and looking out for work arond. Please help.
    Thanks,
    Natasha

  • HTML in PL/SQL block

    How to add "Welcome" using HTML in the following PL/SQL block. I want to add the Welcome user message when user login in to the Apex application.
    BEGIN
      HTP.prn(get_app_user);
    END;Sanjay

    Got the solution. Modified the PL/SQL block as follows :
    BEGIN
    htp.print('<p>Welcome');
    HTP.prn(get_app_user);
    htp.print(' to My application.<p>');
    END;
    Sanjay
    Edited by: user12957777 on 8 Nov, 2010 10:35 PM

  • FETCHING OUTPUT  VALUE FROM PL/SQL BLOCK

    hI aLL,
    I'm working on ODP.NET. I'm executing below pl/sql command. while executing this command in pl/sql it's showing the output which is an xml.
    declare
    xmloutput xmltype;
    xmldata varchar(32767);
    teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N');
    tgetinfo to_info := NULL;
    RETVAL NUMBER;
    begin
    RETVAL := GET_DTLS(teid,tgetinfo);
    dbms_output.put_line(RETVAL);
    xmldata := tgetinfo.XML_info.getclobval();
    dbms_output.put_line(xmldata);
    end;
    I passed above command in string variable for passing in code. like below
    string StrQry = "";
    StrQry += "declare \n";
    StrQry += "xmloutput xmltype; \n";
    StrQry += "xmldata varchar(32767); \n";
    StrQry += "teid t_id := t_en_id( 'L','L',NULL,12121,'ABC','USER','N'); \n";
    StrQry += "tgetinfo to_info := NULL; \n";
    StrQry += "RETVAL NUMBER; \n";
    StrQry += "begin \n";
    StrQry += "RETVAL := GET_DTLS(teid,tgetinfo); \n";
    StrQry += "dbms_output.put_line(RETVAL); \n";
    StrQry += "xmldata := tgetinfo.XML_info.getclobval(); \n";
    StrQry += "dbms_output.put_line(xmldata); \n";
    StrQry += "end; \n";
    I'm passing output parameter ":temp" for this command. I want to catch output xml in ":temp" variable
    which is varchar2 type.
    Added below line before printing xmldata;
    StrQry += ":temp := xmldata; \n";
    cn.Open();
    OracleCommand cmd = new OracleCommand(StrQry, cn);
    cmd.Parameters.Add(":temp", OracleDbType.Varchar2, 32767, ParameterDirection.Output);
    cmd.ExecuteNonQuery();
    But which executing through c# code it's showing the below error.
    Oracle.DataAccess.Client.OracleException ORA-06502: PL/SQL: numeric or value err
    or: character string buffer too small
    ORA-06512: at line 11 at Oracle.DataAccess.Client.OracleException.HandleError
    Helper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOp
    oSqlValCtx, Object src, String procedure)
    at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle
    Connection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx
    , Object src)
    at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
    at orclGetDetails.Program.DoProcess()
    How can i get the output to output variable ":temp".
    Pls help.
    Ideas are appreciated.

    Your PL/SQL block isn't returning anything. DBMS_OUTPUT is, at best, a way of debugging code, not passing data around. Assuming you configure and enable an appropriately sized buffer, I suppose your ODP.Net application could make DBMS_OUTPUT.GET_LINE calls to retrieve the XML. But that's not not a way to design an application.
    If you want a PL/SQL block that returns XML, you'll need to create a function and have the function return the XML (you could also create a procedure with an OUT parameter in which you could return the XML).
    Justin

  • Oracle pl/sql  block in java

    Hi,
    Everybody I just want to know how we execute the pl/sql (oracle9i)block(not store Procedure)
    in java that have explicit cursor and how we print or display the value in cursor..
    pl/sql block declare
    v_id number;
    cursor cv1 IS
    select request_id from requests where sys_id = 3
    begin\n
    open cv1;
    loop
    fetch cv1 into v_id;
    exit when cv1%notfound;
    dbms_output.put_line(v_id);
    end loop; \n"
    end;;
    i try it like simple sql query
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    conn = DriverManager.getConnection(url, name, pass);
    stmt = conn.createStatement();
    rs = stmt.executeQuery(pl/sql block);
    I want display the value store in cursor............in java....
    kindly help me........
    regard's
    paritosh tomar

    Paritosh,
    You can execute anonymous PL/SQL blocks in JDBC.
    I suggest searching this forum's archives for the word "anonymous".
    If I remember correctly, there should be a relevant post from David Rolfe from a few years ago.
    Good Luck,
    Avi.

  • How to convert pl/sql block into single update statement

    Dear all gurus,
    I have pl/sql block mention below, Can I convert this pl/sql block to single update statement if possible?
    If not how to optimize this block?
    Pleaese suggest.
    thanks in advance.
    Vijay
    DECLARE
    CURSOR vt_mlr_cursor IS Select master_key, user4 from vt_mlr Where USER4 is not null;
    USERFIELD VARCHAR2(100);
    C1 VARCHAR2(3); /* this will return location of first space = 12 */
    C2 VARCHAR2(3); /* this will return location of second space = 20 */
    C3 VARCHAR2(3); /* this will return location of third space = 28 */
    C4 VARCHAR2(3); /* this will return location of forth space = 35 */
    Field1 VARCHAR2(40); /* this will return FTMYFLXA04W */
    Field2 VARCHAR2(10); /* this will return VPI0043 */
    Field3 VARCHAR2(10); /* this will return VCI0184 */
    Field4 VARCHAR2(10); /* this will return 005 */
    Field5 VARCHAR2(10); /* this will return 00001 */
    Field_2_n_3 VARCHAR2(25);
    key VARCHAR2(10);
    BEGIN
    FOR vt_mlr_record IN vt_mlr_cursor
    LOOP
    key := vt_mlr_record.master_key;
    USERFIELD := vt_mlr_record.user4;
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); /* this will return location of first space = 12 */
    C2 := INSTR(vt_mlr_record.user4,' ',1,2); /* this will return location of second space = 20 */
    C3 := INSTR(vt_mlr_record.user4,' ',1,3); /* this will return location of third space = 28 */
    C4 := INSTR(vt_mlr_record.user4,' ',1,4); /* this will return location of forth space = 35 */
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1); /* this will return FTMYFLXA04W */
    Field2 := SUBSTR(vt_mlr_record.user4,C1+4,C2-C1-4); /* this will return VPI0043 */
    Field3 := SUBSTR(vt_mlr_record.user4,C2+4,C3-C2-4); /* this will return VCI0184 */
    Field4 := SUBSTR(vt_mlr_record.user4,C3+4,C4-C3-4); /* this will return 005 */
    Field5 := SUBSTR(vt_mlr_record.user4,C4+4,LENGTH(vt_mlr_record.user4)-C4-3); /* this will return 00001 */
    Field_2_n_3 := Field2 || '/' || Field3;
    /*DBMS_OUTPUT.PUT_LINE ('Current key is: ' || vt_mlr_record.master_key);*/
    UPDATE vt_mlr
    SET
    aggregator_clli = Field1,
    aggregator_vpi_vci = Field_2_n_3,
    aggregator_slot = Field4,
    aggregator_port = Field5
    WHERE
    master_key = vt_mlr_record.master_key;
    END LOOP;
    END;
    /

    Hi Vijay,
    Here's something to start with, you should be able to complete it.
    First, combine your select and update statements:
    update vt_mlr
       set aggregator_clli = field1
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null;Then put these two
    C1 := INSTR(vt_mlr_record.user4,' ',1,1); 
    Field1 := SUBSTR(vt_mlr_record.user4,1,C1-1);into
    Field1 := SUBSTR(vt_mlr_record.user4,1,INSTR(vt_mlr_record.user4,' ',1,1) -1);And put it into the update statement, removing reference to record
    (I have also removed default values for position and occurrence in instr function):
    update vt_mlr
       set aggregator_clli = substr(user4, 1, instr(user4,' ') - 1)
          ,aggregator_vpi_vci = field_2_n_3
          ,aggregator_slot = field4
          ,aggregator_port = field5
    where user4 is not null; I think you can do the rest from here ;-)
    Regards
    Peter

  • Error executing pl sql block

    Hii All,
    I'm facing the following error
    ERROR at line 66:
    ORA-06550: line 66, column 20:
    PLS-00306: wrong number or types of arguments in call to '||'
    ORA-06550: line 66, column 11:
    PL/SQL: Statement ignoredVersion Details
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - ProductionMy pl sql block
    Declare
        p_table_name  clob := 'CP_CA_DTLS' ;
        Type t_column_name_tab is table of varchar2(4000)
        index by binary_integer;
        l_table_tab      t_column_name_tab;
        l_file_name constant varchar2(5000) := 'column_counts';
        l_count      number;
        l_tab_count    number;
        l_str    varchar2(32000);
        l_tbl_str  varchar2(32000);
      Cursor c_table_columns(c_table_name user_tables.table_name%type)
      Is
        Select  column_name
        from  user_tab_cols
        where  table_name = upper(c_table_name);
      Type t_table_columns is table of c_table_columns%rowtype;
       l_column_name_tab  t_table_columns;
    Begin
        --Splitting comma seperated data
        Select  regexp_substr(p_table_name,'[^,]+{1}',1,level)
        bulk collect into  l_table_tab
        from  dual
        connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
        for k in 1..l_table_tab.count
        loop
         -- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');   
          Begin
              l_tbl_str := 'Select count(*) from '||l_table_tab(k);
              execute immediate l_tbl_str into l_tab_count;
            --  dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_count);   
          End;
       -- dbg_print(l_file_name,'Column Name '||','||'Count'); 
        Open c_table_columns(l_table_tab(k));
        loop
          Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
          exit when l_column_name_tab.count = 0;
          dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
            for i in 1..l_column_name_tab.count
            loop
            Begin
              l_str := 'Select count(*) ' ;
              l_str := l_str||' from  '||l_table_tab(k) ;
              l_str := l_str||' where '||l_column_name_tab(i);
              l_str := l_str||' is null'  ;
              Execute Immediate l_str into l_count;
            End;
            --dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
            end loop;
        end loop;
        Close c_table_columns;
      end loop;
          dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    End;Even I'm not able to print l_column_name_tab(i) using dbms_output.
    (Later I came to know that this information can be achieved using user_tab_col_statistics table)
    But would like to know whats wrong with my code.???
    Plz help me .
    Edited by: 792353 on Dec 3, 2010 1:26 AM

    Hii RDB,
    when I comment this part of code
      --   l_str := l_str||' where '||l_column_name_tab(i);
           --   l_str := l_str||' is null'  ;
    SQL> Declare
      2 
      3 
      4      p_table_name  clob := 'CP_CA_DTLS' ;
      5 
      6      Type t_column_name_tab is table of varchar2(4000)
      7      index by binary_integer;
      8     
      9      l_table_tab      t_column_name_tab;
    10    
    11 
    12 
    13 
    14      l_file_name constant varchar2(5000) := 'column_counts';
    15      l_count      number;
    16      l_tab_count    number;
    17      l_str    varchar2(32000);
    18      l_tbl_str  varchar2(32000);
    19   
    20    Cursor c_table_columns(c_table_name user_tables.table_name%type)
    21    Is
    22      Select  column_name
    23      from  user_tab_cols
    24      where  table_name = upper(c_table_name);
    25     
    26     
    27    Type t_table_columns is table of c_table_columns%rowtype;
    28   
    29   
    30     l_column_name_tab  t_table_columns;
    31   
    32  Begin
    33      --Splitting comma seperated data
    34     
    35      Select  regexp_substr(p_table_name,'[^,]+{1}',1,level)
    36      bulk collect into  l_table_tab
    37      from  dual
    38      connect by level <= length(regexp_replace(p_table_name,'[^,]*'))+1;
    39     
    40      for k in 1..l_table_tab.count
    41      loop
    42       -- dbg_print(l_file_name,'***'||l_table_tab(k)||'***');   
    43       
    44        Begin
    45            l_tbl_str := 'Select count(*) from '||l_table_tab(k);
    46       
    47            execute immediate l_tbl_str into l_tab_count;
    48       
    49          --  dbg_print(l_file_name,'Overall Count of table '||l_table_tab(k)||' is '||l_tab_coun
    t);   
    50 
    51        End;
    52 
    53     -- dbg_print(l_file_name,'Column Name '||','||'Count'); 
    54 
    55      Open c_table_columns(l_table_tab(k));
    56      loop
    57        Fetch c_table_columns bulk collect into l_column_name_tab limit 50;
    58        exit when l_column_name_tab.count = 0;
    59        dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    60          for i in 1..l_column_name_tab.count
    61          loop
    62          
    63          Begin
    64            l_str := 'Select count(*) ' ;
    65            l_str := l_str||' from  '||l_table_tab(k) ;
    66         --   l_str := l_str||' where '||l_column_name_tab(i);
    67         --   l_str := l_str||' is null'  ;
    68         
    69            Execute Immediate l_str into l_count;
    70 
    71          End;
    72         
    73          --dbg_print(l_file_name,l_column_name_tab(i)||','||l_count);
    74       
    75          end loop;
    76      end loop;
    77      Close c_table_columns;
    78    end loop;
    79 
    80        dbms_output.put_line('l_column_name_tab.count count is : '||l_column_name_tab.count);
    81  End;
    82  /
    PL/SQL procedure successfully completed.its running fine so the problem is l_column_name_tab(i) !!!!!!
    and there is nothing wrong with l_table_tab(k) and its declaration.
    Edited by: 792353 on Dec 3, 2010 2:17 AM

  • Execute immediate will work in SQL Block in shell script?

    Hi Friends,
    i am wirting script to get the account id's corresponding to CIF from oracle table and need to pass to procedure.
    Here first_org and last_org are shell variables.
    When i execute the below program it is throwing execute not found.
    Can you please correct me where i made a mistake? and also please let me know how to display some content in below sql block ?dbms_output.put_line or print which need to use and provide me the syntax for both.
    `sqlplus -s crmuser/******@dotis11<<ENDOFSQL
    whenever sqlerror exit 1
    declare
    qstr varchar2(200);
    facid varchar2(20);
    Lacid varchar2(20);
    begin
    qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
    execute immediate qstr into facid using $first_org;
    dbms_output.put_line(facid);
    qstr:='select ACCOUNTID from accounts where ORGKEY=:1';
    execute immediate qstr into Lacid using $last_org;
    dbms_output.put_line(Lacid);
    exec Retail_Otu_Dedup_Account(facid,Lacid)
    end;
    exit;
    ENDOFSQL`
    Thanks,
    Venkat Vadlamudi.

    Hi SY,
    I Included set serveroutput on but i didn't include single quotes for shell variable in execute immediate.
    Now iam able to execute and getting proper o/p.
    Thanks SY for your help...
    and how to print shell variable in above sql block..i tried like this. but throwing error.
    dbms_output.put_line('$first_org');
    dbms_output.put_line('VCIF1320');
    ERROR at line 5:
    ORA-06550: line 5, column 12:
    PLS-00103: Encountered the symbol "." when expecting one of the following:
    constant exception <an identifier>
    *<a double-quoted delimited-identifier> table long double ref*
    char time timestamp interval date binary national character
    nchar
    The symbol "<an identifier>" was substituted for "." to continue.
    ORA-06550: line 6, column 5:
    PLS-00103: Encountered the symbol "=" when expecting one of the following:
    constant exception <an identifier>
    *<a double-quoted delimited-identifier> table long double ref*
    char time timestamp interval date binary national characte
    Thanks,
    Venkat Vadlamudi.

  • Calling sql script from pl/sql block

    Hi
    I want to call a sql script from pl/sql block.
    like
    CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
    as
    begin
    execute immediate  '@ C:\Documents and Settings\umesh\emp.sql';
    end DataBaseExport;
    /

    Try something like this -
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host
         public static void executeCommand(String command)
         try {
                String[] finalCommand;
                   if (isWindows())
                        finalCommand = new String[4];
                        // Use the appropriate path for your windows version.
                        finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
                        //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
                        finalCommand[1] = "/y";
                        finalCommand[2] = "/c";
                        finalCommand[3] = command;
                   else
                        finalCommand = new String[3];
                        finalCommand[0] = "/bin/sh";
                        finalCommand[1] = "-c";
                        finalCommand[2] = command;
              final Process pr = Runtime.getRuntime().exec(finalCommand);
             pr.waitFor();
             new Thread(new Runnable()
                public void run()
                      BufferedReader br_in = null;
                   try
                        br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                        String buff = null;
                        while ((buff = br_in.readLine()) != null)
                                  System.out.println("Process out :" + buff);
                               try {Thread.sleep(100); } catch(Exception e) {}
                        br_in.close();
                   catch (IOException ioe)
                        System.out.println("Exception caught printing process output.");
                        ioe.printStackTrace();
                 finally
                     try {
                              br_in.close();
                          } catch (Exception ex) {}
         ).start();
         new Thread(new Runnable()
           public void run()
                BufferedReader br_err = null;
                try
                   br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                   String buff = null;
                   while ((buff = br_err.readLine()) != null)
                        System.out.println("Process err :" + buff);
                        try
                           Thread.sleep(100);
                         } catch(Exception e) {}
                   br_err.close();
               catch (IOException ioe)
                   System.out.println("Exception caught printing process error.");
                   ioe.printStackTrace();
              finally
                  try
                          br_err.close();
                   catch (Exception ex) {}
          ).start();
         catch (Exception ex)
                  System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows()
              if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
              return true;
              else
              return false;
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    --- THE PERMISSIONS ---
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
    create or replace procedure call_sql_file(usr  in varchar2,
                                              pwd  in varchar2,
                                              host_str in varchar2)
    is
    begin
       host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
    exception
      when others then
        dbms_output.put_line(sqlerrm);
    end;Now, you can pass all the argument in order to execute that file.
    N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Pl sql block doesn't do anything

    I have a pl/sql block and it doesn't do anything why?
    Code is as follows:
    DECLARE @day varchar(10)
    BEGIN
    set @day='select to_char('sysdate','DAY') from dual;
    PRINT @day
    END;
    Any ideas would be highly appreciated.
    Thanks !

    991121 wrote:
    @Dave
    It is Oracle 11g DB. Not SQL server.Your Database is Oracle but your code is T-SQL and not PL/SQL
    DECLARE
      @day varchar(10)
    BEGIN
      set @day='select to_char('sysdate','DAY') from dual;
      PRINT @day
    END;
    / You cannot just copy past a T-SQL code into Oracle and expect it to Run.
    You need to stop writing code and start learning PL/SQL. You can start with [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/toc.htm]Oracle Database PL/SQL Users Guide and Reference
    A PL/SQL code would look like this
    set serveroutput on
    delcare
       my_day varchar2(10);
    begin
       select to_char(sysdate, 'DAY') into my_day
         from dual;
       dbms_output.put_line(my_day);
    end;
    /

  • While executing the following pl/sql block   Iam getting  following error

    While executing the following pl/sql block
    Iam getting following error
    ORA-06550: line 5, column 11:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 5, column 11:
    PL/SQL: Item ignored
    declare
    TYPE t_customer_details IS REF CURSOR;
    o_customer_details t_customer_details;
    v_rec o_customer_details%ROWTYPE;
    begin
    o_customer_details:=pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329);
    LOOP
    FETCH o_customer_details INTO rec ;
    EXIT WHEN o_customer_details%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(' print' );
    END LOOP;
    CLOSE o_customer_details;
    end;

    sorry
    declare
    TYPE t_customer_details IS REF CURSOR;
    o_customer_details t_customer_details;
    begin
    o_customer_details:= pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329);
    FOR v_rec IN o_customer_details
    LOOP
      DBMS_OUTPUT.PUT_LINE(' print' );
    END LOOP;
    END;I changed code,
    Can you say , o_customer_details:= pkg_search.fngetcustdetails( 2727,1000841, NULL,NULL,119105329); is it right?
    pkg_search.fngetcustdetails return ref cursor??

  • SQL within PL/SQL block

    This question sound funny. I just want to make sure this rule. In Oracle database before 10g, we can only use DML and transaction control code within PL/SQL block. We can not use DDL or other control languages within PL/SQL block. How about 10g? can I use DDL in PL/SQL block in 10g?
    I have created a procedure to drop all materialized view. Drop object is DDL. I used a piece of code like this:
    v_sql_stmt1 := 'DROP MATERIALIZED VIEW'||v_schema||'.'||x.mview_name;
    EXECUTE IMMEDIATE v_sql_stmt1;
    The procedure was compiled successfully. However, when I run this SP, it generate ORA-00905 missing keyword error on EXECUTE IMMEDIATE statement part. Is this caused by missing keyword in sql statement or DROP as DDL can not be used in PL/SQL block? If it is first one, what is the keyword for DROP MATERIALIZED VIEW statement?

    The versions of Oracle that run on this planet have been able to do DDL in PL/SQL for quite some time now. The DBAs who blasted off into space with you and worked in a vacuum the past however many years you feel you've been limited by this need to be replaced or re-introduced to Oracle.
    For what it's worth, the error looks like you're missing a space.

  • Pl/sql block to count no of vowels and consonents in a given string

    hi,
    I need a pl/sql block to count no of vowels and consonants in a given string.
    Program should prompt user to enter string and should print no of vowels and consonants in the given string.
    Regards
    Krishna

    Edit, correction to my above post which was wrong
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select '&required_string' as txt from dual)
      2  --
      3  select length(regexp_replace(txt,'([bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ])|.','\1')) as cons_count
      4        ,length(regexp_replace(txt,'([aeiouAEIOU])|.','\1')) as vowel_count
      5* from t
    SQL> /
    Enter value for required_string: This is my text string with vowels and consonants
    old   1: with t as (select '&required_string' as txt from dual)
    new   1: with t as (select 'This is my text string with vowels and consonants' as txt from dual)
    CONS_COUNT VOWEL_COUNT
            30          11
    SQL>

  • Where does a PL/SQL block run? PGA or SGA?

    Hi all,
    11g
    I'm not familiar with the oracle memory structure, if I have a simple pl/sql block as below
    DECLARE
      v1 number;
    BEGIN
      v1:=100;
      DBMS_OUTPUT.PUT_LINE(v1);
    END;in my mind, even though it's a small block, when i execute it, it would also consume some memory, where does this memory come from, pga or sga?
    in other words, when 'pl/sql engine' needs some memory, for example, for the local variables, where does this memory come from?
    many thanks.

    in my mind, even though it's a small block, when i execute it, it would also consume some memory, where does this memory come from, pga or sga?
    in other words, when 'pl/sql engine' needs some memory, for example, for the local variables, where does this memory come from?SGA
    The SGA comprises a number of memory components, which are pools of memory used to satisfy a particular class of memory allocation requests. Examples of memory components include the shared pool (used to allocate memory for SQL and PL/SQL execution), the java pool (used for java objects and other java execution memory), and the buffer cache (used for caching disk blocks). All SGA components allocate and deallocate space in units of granules. Oracle Database tracks SGA memory use in internal numbers of granules for each SGA component.
    for any sort operations, hash joings, it uses PGA.
    Read http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/memory.htm

Maybe you are looking for

  • How do I create and display a text file?

    Hello friends, I am trying to create a simple unix like operating system with very basic functionality. I have a hard time trying to create a "mktext" file and actually display the contents of the text file with the "cat" command. For example: // If

  • Install Leopard and maintain POPFile, Anacron

    I am interested in upgrading to Leopard. I have a few custom things going on with my Tiger install. I run POPFile for email filtering. I had to install some Perl modules, and make a startup script. Additionally, I have installed Anacron for Mac OS 10

  • Some questions about 11gR2

    All, I just upgraded to 11gR2. But now voting disk and ocr are all in ASM. How do i do voting disk backup? We used to use dd to backup voting disk, now i got [oracle@np-testrac1 ~]$ crsctl query css votedisk ## STATE File Universal Id File Name Disk

  • 2 Pass VBR Stops Responding

    Hi Guys I'm using Win7 on a Dell Precision M6700 with a Nvidia Quadro K3000M. When I'm working on the timeline, the preview is smooth and sharp but my exports are a bit disappointing. So I thought I'd try setting 2 Pass VBR as well as checking render

  • Connecting imqadmin tool to Sun App Server 8

    I have been using the Standalone platform edition of MessageQueue on solaris with no problems (V3.5 SP2). I am currently looking up my ConnectionFactory on an LDAP server. This is working fine. However, I am also trying to connect the imqadmin tool t