Debug the anonymous block

Hello
DBMS_METADATA. GET_DDL package can be used to extract any database object DDL script. I use it to extract the tablespace script. I want to write all the script maps to file. for this I use UTL. FILE to write the file. She run but write a single tablespace file in script. here my Code
create or replace
PROCEDURE dpr_clobToFile(p_clob IN CLOB ) 
   IS

  c_amount         CONSTANT BINARY_INTEGER := 32767;
  l_buffer         VARCHAR2(32767);
  l_chr10          PLS_INTEGER;
  l_clobLen        PLS_INTEGER;
  l_fHandler       UTL_FILE.FILE_TYPE;
  l_pos            PLS_INTEGER    := 1;

BEGIN

  l_clobLen  := DBMS_LOB.GETLENGTH(p_clob);
  l_fHandler := UTL_FILE.FOPEN('DATA_PUMP_DIR', 'MY_FILE','W',c_amount);

  WHILE l_pos < l_clobLen LOOP
    l_buffer := DBMS_LOB.SUBSTR(p_clob, c_amount, l_pos);      
    EXIT WHEN l_buffer IS NULL;
    l_chr10  := INSTR(l_buffer,CHR(10),-1);
    IF l_chr10 != 0 THEN
      l_buffer := SUBSTR(l_buffer,1,l_chr10-1);
    END IF;
    UTL_FILE.PUT_LINE(l_fHandler, l_buffer,TRUE);
    l_pos := l_pos + LEAST(LENGTH(l_buffer)+1,c_amount);
  END LOOP;

  UTL_FILE.FCLOSE(l_fHandler);

EXCEPTION
WHEN OTHERS THEN
  IF UTL_FILE.IS_OPEN(l_fHandler) THEN
    UTL_FILE.FCLOSE(l_fHandler);
  END IF;
  RAISE;

END;
the call of this block anonymous sp
   declare c clob;
--fHandle  UTL_FILE.FILE_TYPE;
   begin
   -- fHandle := UTL_FILE.FOPEN('DATA_PUMP_DIR', 'MYFILE.TXT', 'w');
    for t in( select tablespace_name from dba_tablespaces where tablespace_name like 'ECP01V1_B010_DATA%')
    loop
     select dbms_metadata.get_ddl('TABLESPACE', t.tablespace_name) into c from dual;
    
     *dpr_clobToFile(c);*
    end loop;
   end;
There are nearly 100 spaces of tables in my database where the above script write a single script of tablespace to output file. any idea? How can I debug this scenario through SQL DEVELOPER

Published by: user10858330 on April 2, 2012 02:42

Hello

user10858330 wrote:
There are nearly 100 spaces of tables in my database where the above script write a single script of tablespace to output file. any idea?

Well, you open the output mode 'w' file each time, take a look at [url http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/u_file.htm#i1003526] UTL_FILE documentation:

* open_mode *.

Specifies how the file is opened. Modes include:
r - read the text
w - write text
to add text
RB - reading bytes
World Bank - in mode writing bytes
AB - append mode bytes

Therefore, for a loop of 100 case, you replace the DDL 99 times past.

I see 3 lines of resolution that:
-Open the file in Add mode (a or ab). But you have to make sure that it contains no tricks of previous test cycles. (ideally, first open the file in mode 'w', then all subsequent occurrences in Add mode ("a" or "ab"))
-Open outside of the loop (in mode 'w') and close the file when the loop ends
-Open a different DDL file for each tablespace (perhaps by adding the nom_tablespace in the output file)
I would prefer #2 or #3 +(depending on how you will be re-using those DDLs) solution.

Tags: Database

Similar Questions

  • Scheduling of the anonymous blocks

    Is it possible to predict an anonymous block? If so, how can I do it? a code example is appreciated.

    Edited by: jdude on October 20, 2011 04:34

    This is an example of stored procedure, I can't understand how to write one for an anonymous block

    Start
    dbms_scheduler.create_job
    (job_name = > ' SCOTT.) RUN_SCOTTS_PROC',.
    job_type = > 'procedure_stockee ',.
    job_action = > ' SCOTT. SCOTTS_PROC',.
    start_date = > trunc (sysdate + 1) + 1/24.
    repeat_interval = > ' FREQ = DAILY; BYDAY IS MON, MAR, SEA, GAME, FRI, SAT.; BYHOUR = 1;',
    enabled = > true,
    auto_drop = > false,
    Comments = > 'convert 152152 work');
    end;

    Edited by: jdude on October 20, 2011 04:42

    If you have single quotes in your anonymous block you have to do a single quote 2 x or use the q rating.
    Otherwise, the first apostrophe in the plsql block ends the string of the parameter program_action isn't?

  • Passage of the Arguments to the anonymous block

    I have a unix script that calls an anonymous block / sql file.
    The sql file read a flat file via UTL_FILE utility and insert/update to update these data to the table.
    When calling SQL script, I put
     'SET DEFINE OFF' 
    to get rid of the * '&' * char in the string (input file).
    Now I have to deal with several files on the same trial, I invoke the SQL script from arguments like:

    Invoke:
    start xx.sql FILE_NAME
    Inside to access the xx.sql arguments like:
    declare
    y varchar2(20);
    begin
    dbms_output.put_line('Y= '||y);
    y:='&1';
    dbms_output.put_line('Y= '||y);
    end;
    /
    It only works if I put
     'SET DEFINE ON' 
    In this case no * '&' * char being treated as read from the standard input.
    Create procedure/function is out of reach.
    Someone can suggest... that should be the approach and is there a way to manage it?

    Hello

    Linda wrote:
    I have a unix script that calls an anonymous block / sql file.
    The sql file read a flat file via UTL_FILE utility and insert/update to update these data to the table.
    When calling SQL script, I put

     'SET DEFINE OFF' 
    

    to get rid of the * '&' * char in the string (input file).

    Are your really get into single quotes? If this is not the case, why you put them in this message?

    Now I have to deal with several files on the same trial, I invoke the SQL script from arguments like:

    Invoke:

    start xx.sql FILE_NAME
    

    Who is using SQL * more variable substitution. You must SET SET to retrieve the value of a variable substitution.
    You do not have to use & to mark the substitution variables; If you know iof some other special characters (such as ~) which is not used in your code, you can do the marker by saying:

    SET     DEFINE  ~
    

    Moreover, if the variable represents a value of sclar (wuch as the string "Filename" in your example), you can use bind variables to pass data in your anonymous block.
    For example, at the beginning of xx.sql, you can declare and set a varibale bind like this:

    VARIABLE     arg_1     VARCHAR2 (20);
    
    SET     DEFINE     ON
    
    EXEC :arg_1 := '&1';
    
    SET     DEFINE     OFF
    

    DEFINE must be enabled only for the statement that sets: arg_1.
    After that, your script can use: arg_1 instead of & 1:

    declare
        y varchar2(20);
    begin
        dbms_output.put_line('Y= '||y);
        y:=:arg_1;
        dbms_output.put_line('Y= '||y);
    end;
    /
    

    Note that you do not quote the variable name to bind when it is used. You had to mention the name of substitution variable, because SQL * Plus solves the substitution variables before sending the code for the compiler, but SQL * more passes the variable binding for the compiler, and the compiler can see that: arg_1 is a VARCHAR2.

    You can also define and set the binding variable in the calling script, but the passage of an argument tends to be a better way.

    There are other alternatives (such as escape &s);) We can Explorer if the two methods I described above do not work for you.

  • Error in the anonymous block

    Hello

    DECLARE
    NOM_TABLE_P VARCHAR2 (40): = "T_ID_BUSINESS_MESSAGE_MASTER";
    P_OUT VARCHAR2 (15);
    BEGIN
    SELECT P_OUT MESSAGE_CODE
    OF nom_table_p WHERE ROWNUM < 2;

    DBMS_OUTPUT. PUT_LINE (' O/P "|") P_OUT);

    END;

    If I run the block above, it displays error below.

    Error report:
    ORA-06550: line 6, column 6:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 5, column 1:
    PL/SQL: SQL statement ignored
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.
    * Action:

    Kind regards
    Fame

    You must use dynamic SQL statements using a table name stored in a variable.

    DECLARE
    P_TABLE_NAME VARCHAR2(40) := 'EMP';
    P_OUT VARCHAR2(15);
    V_QUERY VARCHAR2(100);
    BEGIN
       V_QUERY := 'SELECT ENAME FROM ' || P_TABLE_NAME || ' WHERE ROWNUM < 2';
       EXECUTE IMMEDIATE V_QUERY INTO P_OUT;
    DBMS_OUTPUT.PUT_LINE('O/P' ||P_OUT );
    END;
    
  • debug this anonymous block

    assistance required in the present case I am trying to print all the values of the record as below, but error "LAST" must be declared...

    declare

    type t1 is (record

    EmpNo, emp. EMPNO % type,

    Ename emp.ename%type

    );

    T1 t2;

    Start

    Select empno, ename in t2 from emp where deptno = 10;

    I'm looping 1.t2.last

    dbms_output.put_line (T2.empno (i) |) «, » || T2.ename (i));

    end loop;

    end;

    a_cute_person wrote:

    assistance required in the present case I am trying to print all the values of the record as below, but error "LAST" must be declared...

    declare

    type t1 is (record

    EmpNo, emp. EMPNO % type,

    Ename emp.ename%type

    );

    T1 t2;

    Start

    Select empno, ename in t2 from emp where deptno = 10;

    I'm looping 1.t2.last

    dbms_output.put_line (T2.empno (i) |) «, » || T2.ename (i));

    end loop;

    end;

    Why are you a loop in a record? You must set a record collection and use.

    Like this

    declare
      type rec is record
      (
        empno emp.EMPNO%type,
        ename emp.ename%type
      );
      type tbl is table of rec;
      t2 tbl;
    begin
      select empno,ename bulk collect into t2 from emp where deptno = 10;
      for i in 1..t2.count
      loop
        dbms_output.put_line(t2(i).empno||','||t2(i).ename);
      end loop;
    end;
    
  • Oracle SQL Developer 3.0: Debugging of PL/SQL anonymous blocks: ISSUES

    Hello
    I just downloaded the Oracle SQL Developer 3.0. I used EA versions because they have emerged and was happy to see the final version. So I immediately tried to debug an anonymous block (something I was not looking to do in EA versions) and nothing happened.

    The "Debug" is grayed out and the string 'ctrl-SHIFT-F10' key did nothing. I found this forum:
    Re: 30EA1: debugging of anonymous block?
    and Vadim Tropashko follow-up advice. This has nothing to my anonymous block but has worked well for a simple example.

    So I started to whittle my anonymous block to the bottom to find the culprit, here's a breaking point repeatable for me:
    declare
        stmt1 long;
        stmt2 long;
        stmt3 long;
        stmt4 long;
        p_data varchar2( 500 );
        i      varchar2( 10 );
    BEGIN
        STMT1 := 1;
        STMT2 := 1;
        STMT3 := 1;
        STMT4 := 1;
        
        --the moment this is in the block "Debug" is no longer an option
         select
            SendDocumentResult
           into
            p_data
           from
            XMLTABLE( '/data' 
                    PASSING 
                    xmltype.createxml( '<?xml version="1.0" encoding="utf-8"?><data><SendDocumentResult>test</SendDocumentResult></data>' ) 
                    COLUMNS SendDocumentResult varchar2( 1000 ) PATH 'SendDocumentResult' ) ;
    end;
    The moment that I SELECT INTO... XMLTABLE() it fails (a normal SELECT INTO works very well).

    Is this a problem with my environment or there's a problem with SQL Developer 3.0.04. Overlooking the comments of K, it seems that debugging has worked for 'simple' blocks, so I wonder if it's just out of reach...

    My environment:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production     
    PL/SQL Release 11.2.0.1.0 - Production                                           
    CORE     11.2.0.1.0     Production                                                         
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production                
    NLSRTL Version 11.2.0.1.0 - Production
    
    and Oracle SQL Developer
    3.0.04 (Buld Main 04.34 with bundled Java) on a Window's XP box.

    The analysis has been the problem indeed. Can offer no alternative workaround, that packing horror XML in a view.

  • Dbms_metadata in a stored procedure. If the table is in the schema, run the stored procedure the procedure works very well.  If I try to get the table ddl to a different scheme it can't find table in a schema.  I run as an anonymous blocks and it works

    create or replace FUNCTION get_table_md (p_owner in varchar2, p_table IN VARCHAR2) RETURN CLOB IS
    -Define local variables.
    / * declare
    p_owner varchar2 (30): = "AVTYM";
    p_table IN VARCHAR2 (30): = "TRANSACTION_HEADER";
    */
    h NUMBER; -handle returned by OPEN
    e NUMBER; -handle returned by ADD_TRANSFORM
    p_tableref varchar2 (30);
    doc CLOB.
    Doc2 CLOB.
    BEGIN

    -Specify the type of object.
    h: = DBMS_METADATA. OPEN ('TABLE');

    -Use filters to specify the desired object.
    DBMS_METADATA. SET_FILTER (h, 'SCHEMA', p_owner);
    DBMS_METADATA. SET_FILTER (h, 'NAME', p_table);

    -Request that the metadata be transformed into creation DDL.
    th: = DBMS_METADATA. ADD_TRANSFORM (h, 'DDL');

    -Retrieves the object.
    doc: = DBMS_METADATA. FETCH_CLOB (h);


    -Free resources.
    DBMS_METADATA. Close (h);
    p_tableref: = substr (p_table, 1, 25). ' $RDEF';
    Doc2: is REGEXP_replace(doc,p_table,p_tableref,1,1,'im');.
    doc: = REGEXP_replace(doc2,'"CREATE_DT"','"EXCHANGE_DT"',1,2,'im');
    -dbMS_OUTPUT. Put_line (doc);
    RETURN doc;

    END;

    Hello

    check the privilege you may have granted by a role that you need direct access to the object and not by the role. You can test if you are granted by a role, by running the SET command role no and see if you can still run the anonymous block.

    Thank you

  • Works of anonymous block - failure of the procedure

    Hi guys,.

    I am new to PL/SQL, and right now, I have problems with a new procedure.

    If I execute the instructions of an anonymous block, then everything works fine.
    As a stored procedure, it fails: PLS-00306: wrong number or types of arguments.

    I don't understand - could you please help me?


    Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
    PL/SQL Release 10.2.0.1.0 - Production
    "CORE 10.2.0.1.0 Production."
    AMT for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production


    The procedure inserts data in multiple tables - so the original procedure has 800 lines.
    I tested it with a shorter version, but it still does not work as a procedure.


    Here is the execute statement:
    begin
    P_P5020_test (
      i_GespAnrede_tx                   => 'Herr',
      i_GespName_tx                     => 'GespName',
      i_GespVorname_tx                  => 'GespVorname',
      i_GespTitel_tx                    => 'GespTitel',
      i_GespStelle_tx                   => 'GespStelle',
      i_GespFunktion_isn                => 1,
      i_GespBereich_isn                 => 1,
      i_GespTelNr_nr                    => '1111',
      i_GespTelNrArt_isn                => 1,
    -- Daten vom Ansprechpartner:
      i_ApAnrede_tx                     => 'Frau',
      i_ApName_tx                       => 'ApName',
      i_ApVorname_tx                    => 'ApVorname',
      i_ApTitel_tx                      => 'Aptitel',
      i_ApStelle_tx                     => 'ApStelle',
      i_ApFunktion_isn                  => 2,
      i_ApBereich_isn                   => 2,
      i_ApTelNr_nr                      => '2222',
      i_ApTelNrArt_isn                  => 1,
    -- Allgemeine Parameter:
      i_UN_nr                           => 110532,
      i_TelNr_isn                       => 54,
      i_hiber_isn                       => 4,
      i_AnlVon_tx                       => 'SMY',
      i_TaskArt_isn                     => 12,
      i_Bemerkung_tx                    => 'Bemerkung'
             );
    END; 
    and here is the procedure:

    create or replace
    PROCEDURE p_P5020_test
    --
    -- Parameter:
    --
      (
    -- Daten vom Gesprächspartner:
      i_GespAnrede_tx varchar2,
      i_GespName_tx varchar2,
      i_GespVorname_tx varchar2,
      i_GespTitel_tx varchar2,
      i_GespStelle_tx varchar2,
      i_GespFunktion_isn number,
      i_GespBereich_isn number,
      i_GespTelNr_nr varchar2,
      i_GespTelNrArt_isn number,
    -- Daten vom Ansprechpartner:
      i_ApAnrede_tx varchar2,
      i_ApName_tx varchar2,
      i_ApVorname_tx varchar2,
      i_ApTitel_tx varchar2,
      i_ApStelle_tx varchar2,
      i_ApFunktion_isn number,
      i_ApBereich_isn number,
      i_ApTelNr_nr varchar2,
      i_ApTelNrArt_isn number,
    -- Allgemeine Parameter:
      i_UN_nr number,
      i_TelNr_isn number,
      i_hiber_isn number,
      i_anlVon_tx varchar2,
      i_TaskArt_isn number,
      i_sonstGrund_tx varchar2,
      i_Bemerkung_tx varchar2,
    -- für die Task:
      i_BeginnDatum_dt date,
      i_BeginnZeit_ts timestamp,
      i_FaelligVonDatum_dt date,
      i_FaelligVonZeit_ts timestamp,
      i_FaelligBisDatum_dt date,
      i_FaelligBisZeit_ts timestamp,
      i_TaskPrio_isn number
      )
    --
    --------------------------------------------------------------------------------
    --
    IS
    --
    -- Variablen:
    --
      v_MA_nr number := 4;
      v_GespBez_nr number;                -- return BezNr vom Gesprächspartner
      v_ApBez_nr number;                  -- return BezNr vom Ansprechpartner
      v_Task_nr number;                   -- return TaskNr für die Kon
      v_TaskThema_tx varchar2(40);            -- anhand taskart ermitteln
    -- für die Beziehung:
      v_BezGueltigVon_dt date := sysdate;
      v_BezGueltigBis_dt date := to_date('31.12.2099', 'DD.MM.YYYY');
    -- für die Notiz / Kon:
      v_KonThema_tx varchar2(40);
      v_KonArt_isn number;
      v_KonWeg_isn number := 2;           -- 2 = Telefon
      v_KonDatum_dt date := sysdate;
      v_KonUhrzeit_ts timestamp := systimestamp;
    --
    --
    --------------------------------------------------------------------------------
    --
    BEGIN
    -- select into für variablen durchführen
    --
    --
    -- v_taskThema_tx füllen
      IF i_taskArt_isn != 999999
      THEN
        SELECT
          TASK_ART_NAME
        INTO v_taskThema_tx
        FROM T_TASK_ART
        WHERE task_art_isn = i_taskArt_isn;
    
    --
    --
    -- v_KonArt_ISN füllen
        IF i_TaskArt_isn = 10    -- Nennung verweigert
        THEN v_KonArt_ISN := 13;
        END IF;
        IF i_TaskArt_isn = 11    -- krank 
        THEN v_KonArt_ISN := 7; 
        END IF;
        IF i_TaskArt_isn = 12    -- Urlaub
        THEN v_KonArt_ISN := 8;
        END IF;
        IF i_TaskArt_isn = 13    -- nicht am Platz
        THEN v_KonArt_ISN := 9;
        END IF;
        IF i_TaskArt_isn = 14    -- Feierabend
        THEN v_KonArt_ISN := 10;
        END IF;
        IF i_TaskArt_isn = 15    -- Besprechung
        THEN v_KonArt_ISN := 11;
        END IF;
        IF i_TaskArt_isn = 16    -- zu Tisch
        THEN v_KonArt_ISN := 12;
        END IF;
        IF i_TaskArt_isn = 17    -- sonstiger Grund
        THEN v_KonArt_ISN := 14;
        END IF;
    --
    --
    -- v_konThema_tx füllen
        SELECT
          kon_art_name
        INTO v_konThema_tx
        FROM T_KON_ART
        WHERE kon_art_isn = v_konArt_isn;
    --
    --
      END IF; -- i_taskArt_isn != 999999
    --
    --
    --------------------------------------------------------------------------------
    --
    --
    --
        IF i_ApName_tx IS NOT NULL      -- AP gefüllt? 
     -- dann Gesp anlegen
        THEN
          INSERT INTO t_bez
            (
            bez_un_nr,
            bez_anrede,
            bez_titel,
            bez_name,
            bez_vorname,
            bez_stelle,
            bez_funktion_isn,
            bez_bereich_isn,
            bez_bemerkung,
            bez_gueltig_von,
            bez_gueltig_bis,
            bez_anlvon
            )
          VALUES
            (
            i_un_nr,              -- bez_un_nr
            i_GespAnrede_tx,      -- bez_anrede
            i_GespTitel_tx,       -- bez_titel
            i_GespName_tx,        -- bez_name
            i_GespVorname_tx,     -- bez_vorname
            i_GespStelle_tx,      -- bez_stelle
            i_GespFunktion_isn,   -- bez_funktion_isn
            i_GespBereich_isn,    -- bez_bereich_isn
            'Als Gesprächspartner angelegt, '||           -- bez_bemerkung 
            to_char(sysdate, 'DD.MM.YYYY - hh24:mi')||
            ' '||
            i_AnlVon_tx||
            ' ',                  
            v_BezGueltigVon_dt,   -- bez_gueltig_von
            v_BezGueltigBis_dt,   -- bez_gueltig_bis
            i_AnlVon_tx           -- bez_anlvon        
            )
          RETURN t_bez.bez_nr INTO v_GespBez_nr;
      -- telefonnummer anlegen
          INSERT INTO t_telnr
            (
            telnr_von,
            telnr_vonnr,
            telnr_nr,
            telnr_art_isn,
            telnr_anlvon
            )
          VALUES
            (
            'BEZ',                  -- telnr_von
            v_GespBez_nr,           -- telnr_vonnr
            i_GespTelNr_nr,         -- telnr_nr
            i_GespTelNrArt_isn,     -- telnr_art_isn
            i_AnlVon_tx             -- telnr_anlvon        
            )
          ;
    --
    --
    -- jetzt AP anlegen
          INSERT INTO T_BEZ
            (
            bez_un_nr,
            bez_anrede,
            bez_titel,
            bez_name,
            bez_vorname,
            bez_stelle,
            bez_funktion_isn,
            bez_bereich_isn,
            bez_bemerkung,
            bez_gueltig_von,
            bez_gueltig_bis,
            bez_anlvon        
            )
          VALUES
            (
            i_un_nr,            -- bez_un_nr
            i_ApAnrede_tx,      -- bez_anrede
            i_ApTitel_tx,       -- bez_titel
            i_ApName_tx,        -- bez_name
            i_ApVorname_tx,     -- bez_vorname
            i_ApStelle_tx,      -- bez_stelle
            i_ApFunktion_isn,   -- bez_funktion_isn
            i_ApBereich_isn,    -- bez_bereich_isn
            'Als Ansprechpartner angelegt, '||           -- bez_bemerkung 
            to_char(sysdate, 'DD.MM.YYYY - hh24:mi')||
            ' '||
            i_AnlVon_tx||
            ' ',                  
            v_BezGueltigVon_dt,   -- bez_gueltig_von
            v_BezGueltigBis_dt,   -- bez_gueltig_bis
            i_AnlVon_tx           -- bez_anlvon          
            )
          RETURN t_bez.bez_nr INTO v_ApBez_nr;
    -- jetzt TelNr anlegen
          INSERT INTO t_telnr
            (
            telnr_von,
            telnr_vonnr,
            telnr_nr,
            telnr_art_isn,
            telnr_anlvon
            )
          VALUES
            (
            'BEZ',                -- telnr_von
            v_ApBez_nr,           -- telnr_vonnr
            i_ApTelNr_nr,         -- telnr_nr
            i_ApTelNrArt_isn,     -- telnr_art_isn
            i_AnlVon_tx           -- telnr_anlvon        
            )
          ;  
        END IF; -- i_ApName_tx IS NOT NULL
    --
    ---------------------------------------
    --
    --
    -- AP nicht gefüllt:
    --
        IF i_ApName_tx IS NULL
        THEN
      -- Gesprächspartner als Ansprechpartner anlegen
          INSERT INTO t_bez
            (
            bez_un_nr,
            bez_anrede,
            bez_titel,
            bez_name,
            bez_vorname,
            bez_stelle,
            bez_funktion_isn,
            bez_bereich_isn,
            bez_bemerkung,
            bez_gueltig_von,
            bez_gueltig_bis,
            bez_anlvon
            )
          VALUES
            (
            i_un_nr,              -- bez_un_nr
            i_GespAnrede_tx,      -- bez_anrede
            i_GespTitel_tx,       -- bez_titel
            i_GespName_tx,        -- bez_name
            i_GespVorname_tx,     -- bez_vorname
            i_GespStelle_tx,      -- bez_stelle
            i_GespFunktion_isn,   -- bez_funktion_isn
            i_GespBereich_isn,    -- bez_bereich_isn
            'Als Ansprechpartner angelegt, '||           -- bez_bemerkung 
            to_char(sysdate, 'DD.MM.YYYY - hh24:mi')||
            ' '||
            i_AnlVon_tx||
            ' ',                  
            v_BezGueltigVon_dt,   -- bez_gueltig_von
            v_BezGueltigBis_dt,   -- bez_gueltig_bis
            i_AnlVon_tx           -- bez_anlvon        
            )
          RETURN t_bez.bez_nr INTO v_ApBez_nr;    -- Achtung: wird als AP angelegt!
      -- telefonnummer anlegen
          INSERT INTO t_telnr
            (
            telnr_von,
            telnr_vonnr,
            telnr_nr,
            telnr_art_isn,
            telnr_anlvon
            )
          VALUES
            (
            'BEZ',                  -- telnr_von
            v_ApBez_nr,           -- telnr_vonnr ACHTUNG: vom AP!
            i_GespTelNr_nr,         -- telnr_nr
            i_GespTelNrArt_isn,     -- telnr_art_isn
            i_AnlVon_tx             -- telnr_anlvon        
            )
          ;      
        END IF; -- i_ApName_tx IS NULL
    --------------------------------------------------------------------------------
    --
    END;
    Here are the variables of the anonymous block work - the instructions are the same:
    declare
      i_GespAnrede_tx varchar2(4)       := 'Herr';
      i_GespName_tx varchar2(60)        := 'GespName';
      i_GespVorname_tx varchar2(30)     := 'GespVorname';
      i_GespTitel_tx varchar2(10)       := 'GespTitel';
      i_GespStelle_tx varchar2(60)      := 'GespStelle';
      i_GespFunktion_isn number         := 1;
      i_GespBereich_isn number          := 1;
      i_GespTelNr_nr varchar2(20)       := '111111';
      i_GespTelNrArt_isn number         := 1;
    -- Daten vom Ansprechpartner:
      i_ApAnrede_tx varchar2(4)         := 'Frau';
      i_ApName_tx varchar2(60)          := 'ApName';
      i_ApVorname_tx varchar2(30)       := 'ApVorname';
      i_ApTitel_tx varchar2(10)         := 'ApTitel';
      i_ApStelle_tx varchar2(60)        := 'ApStelle';
      i_ApFunktion_isn number           := 2;
      i_ApBereich_isn number            := 2;
      i_ApTelNr_nr varchar2(20)         := '222222';
      i_ApTelNrArt_isn number           := 1;
    -- Allgemeine Parameter:
      i_UN_nr number                    := 110532;
      i_TelNr_isn number                := 54;
      i_hiber_isn number                := 4;
      i_AnlVon_tx varchar2(5)           := 'SMY';
      i_TaskArt_isn number              := 12;
      i_sonstGrund_tx varchar2(15);
      i_Bemerkung_tx varchar2(50);
      --
      v_MA_nr number := 4;
      v_GespBez_nr number;                -- return BezNr vom Gesprächspartner
      v_ApBez_nr number;                  -- return BezNr vom Ansprechpartner
      v_Task_nr number;                   -- return TaskNr für die Kon
      v_TaskThema_tx varchar2(40);            -- anhand taskart ermitteln
    -- für die Beziehung:
      v_BezGueltigVon_dt date := sysdate;
      v_BezGueltigBis_dt date := to_date('31.12.2099', 'DD.MM.YYYY');
    -- für die Notiz / Kon:
      v_KonThema_tx varchar2(40);
      v_KonArt_isn number;
      v_KonWeg_isn number := 2;           -- 2 = Telefon
      v_KonDatum_dt date := sysdate;
      v_KonUhrzeit_ts timestamp := systimestamp;
    Why is - it works for anonymous block - bute the procedure fails with PLS-00306: wrong number or types of arguments?

    Thank you

    Sven

    Edited by: 923182 the 25.03.2012 06:38

    Welcome to the forum!

    Thank you for providing your information to Oracle version. You must provide this whenever you post a new question.

    All parameters for procedures and functions must be listed in the method call unless the parameter has a DEFAULT value.

    You said a procedure with 32 settings but have listed only 24 in the method call.
    It's ok if the 8 other parameters have default values, but they do not. You can use NULL by DEFAULT, if a parameter does not need to have a value or cannot be used.

    Your anonymous block does not call the procedure, there is no 'settings', that's why you don't see the problem there.

    See specification of default values for the parameters of subprogramme in the PL/SQL language reference
    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/subprograms.htm#i23202

    >
    By initializing formal IN the settings to the default values, you can pass a different number of actual parameters to a subprogram, accepting the default values to the actual parameters is omitted. You can also add new formal parameters without having to change all calls to the subprogramme.

    If a real parameter is omitted, the default value of the corresponding formal parameter is used.

    You can't ignore a formal parameter by omitting its actual parameter. To omit the first parameter and specify the second, use named notation (see passing parameters real subprogramme positional, Named or mixed Notation).

    You cannot assign NULL to an uninitialized formal parameter by omitting its actual parameter. You must assign NULL as default or explicitly pass null.
    >
    You can also use nototation "Named" when you specify parameters by name

    See passing parameters real subprogramme positional, Named or mixed Notation in the same doc.

    raise_salary(amount => bonus, emp_id => emp_num);
    
  • Anonymous blocks that goes down and creates a table

    Version: 11.2.0.3

    I'm relatively new to PL/SQL.

    We have a table named CHK_CNFG_DTL.

    I want to create a backup table for CHK_CNFG_DTL who will be named as CHK_CNFG_DTL_BKP_ < timestamp > for example: CHK_CNFG_DTL_BKP_JULY_22_2013

    Creating this backup table must be automated, so I want to create an anonymous block that will first remove the existing backup table and then create a new backup of the original table.

    The code below works fine. But the first time when you run it, the loop will not iterate because there is no such table named % CHK_CNFG_DTL_BKP.

    declare

    v_stmt varchar2 (1000);

    date of T_DATE;

    Start

    for rec in

    (select * from user_tables where table_name like '% CHK_CNFG_DTL_BKP')

    loop

    Start

    run immediately "alter session set nls_date_format =" DD_MON_YYYY "';"

    v_stmt: = 'drop table' | Rec.table_name | "purge."

    dbms_output.put_line (v_stmt);   -Old backup drops table

    immediately run v_stmt;

    Select sysdate in double T_DATE;

    v_stmt: = "create table CHK_CNFG_DTL_BKP_ | TO_DATE (V_DATE): ' in select * from CHK_CNFG_DTL';

    dbms_output.put_line ('Bkp création table CHK_CNFG_DTL_BKP_' | to_date (v_date));

    dbms_output.put_line (v_stmt);

    immediately run v_stmt;  -Creates the new table of backup

    exception

    while others

    then

    dbms_output. Put_line (rec.table_name |'-'|) SQLERRM);

    end;

    end loop;

    end;

    /

    PL/SQL procedure successfully completed.

    -Backup table was not created.

    SQL > select table_name from user_Tables where table_name like '% CHK_CNFG_DTL ';

    TABLE-NAME

    ------------------------------

    CHK_CNFG_DTL

    Of course, this can fixed by creating a table as bleow before running the anonymous block

    SQL > create table CHK_CNFG_DTL_BKP_JULY_22_2013 (x varchar2 (37));

    Table created.

    and now the block will be executed with success as

    24 end;

    25.

    drop table CHK_CNFG_DTL_BKP_JULY_22_2013 purge

    Creating table Bkp CHK_CNFG_DTL_BKP_22_JUL_2013

    create the table CHK_CNFG_DTL_BKP_22_JUL_2013 select * from CHK_CNFG_DTL

    PL/SQL procedure successfully completed.

    But it goes to production. We cannot have a table like CHK_CNFG_DTL_BKP_JULY_22_2013 without an appropriate reason.

    How can I change the code above so that if even if there is no such like '% CHK_CNFG_DTL_BKP' table, he will create the backup table?

    Hello

    Why don't you press the create backup of the loop?

    declare

    v_stmt varchar2 (1000);

    date of T_DATE;

    Start

    for rec in

    (select * from user_tables where table_name like 'CHK_CNFG_DTL_BKP %')

    loop

    Start

    run immediately "alter session set nls_date_format =" DD_MON_YYYY "';"

    v_stmt: = 'drop table' | Rec.table_name | "purge."

    dbms_output.put_line (v_stmt);   -Old backup drops table

    immediately run v_stmt;

    exception

    while others

    then

    dbms_output. Put_line (rec.table_name |'-'|) SQLERRM);

    end;

    end loop;

    Select sysdate in double T_DATE;

    v_stmt: = "create table CHK_CNFG_DTL_BKP_ | TO_DATE (V_DATE): ' in select * from CHK_CNFG_DTL';

    dbms_output.put_line ('Bkp création table CHK_CNFG_DTL_BKP_' | to_date (v_date));

    dbms_output.put_line (v_stmt);

    immediately run v_stmt;  -Creates the new table of backup

    end;

  • Anonymous block Source code

    How can I request/access to the source code of an anonymous block? For example, if I want the source of a particular procedure, it is accessible from the table 'all_source. Even if she throws the source for an anonymous block after it is done with her, always store it somewhere while it's executing analysis, it should at least be accessible as part of the package as follows:
    declare
        src_code varchar2;
    begin
        select source
        into   src_code
        from   wherever the DB stores it;
    
        dbms_output.put_line(src_code);
    end;

    How can I request/access to the source code of an anonymous block

    If you give the anonymous block a unique label, you might be able to query v$ sql:

    SQL> col guid new_val guid
    SQL>
    SQL> select sys_guid() guid from dual
      2  /
    
    GUID
    --------------------------------
    C418F340066DF07FE04017AC25922063
    
    SQL>
    SQL> declare
      2    sql_text   long;
      3    label      long := '&&guid';
      4  begin
      5    select sql_fulltext
      6      into sql_text
      7      from v$sql
      8     where sql_fulltext like '%' || label || '%';
      9
     10    dbms_output.put_line ('SQL of anonymous block:');
     11    dbms_output.put_line (sql_text);
     12  end;
     13  /
    old   3:   label      long := '&&guid';
    new   3:   label      long := 'C418F340066DF07FE04017AC25922063';
    SQL of anonymous block:
    declare
      sql_text   long;
      label      long := 'C418F340066DF07FE04017AC25922063';
    begin
      select sql_fulltext
        into sql_text
        from v$sql
    
    where sql_fulltext like '%' || label || '%';
    
      dbms_output.put_line ('SQL of anonymous block:');
      dbms_output.put_line (sql_text);
    end;
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • In PL/SQL anonymous block

    How we refer the anonymous block in PL/SQL? And what is the purpose of anonymous blocks?

    This can be useful
    http://DocStore.Mik.UA/orelly/Oracle/PROG2/ch15_03.htm

  • Anonymous block with Variable and SELECT

    Hi guys,.
    I'm fighting to connect the material that I am learning. I read on the anonymous blocks and variable so I want to write a
    Nice and neat select with all the fancy stuff (variables, exceptions) to get it right and what I read in the book.

    DECLARE
    MYSTRING AS VARCHAR (10);
    MYSTIRNG: = 'X '.
    BEGIN
    SELECT * FROM DUAL WHERE DUMMY = MYSTRING
    END;


    but... This causes an error after another. I get the wrong concept here or is this a syntax error?

    PL/SQL, you will need to use SELECT... IN...
    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/sqloperations.htm#sthref1348

    SQL> declare
      2    mystring varchar(10) := 'X';
      3    myvar varchar(10);
      4  begin
      5    select dummy into myvar
      6    from   dual
      7    where  dummy = mystring;
      8    dbms_output.put_line(myvar);
      9  end;
     10  /
    X
    
    PL/SQL procedure successfully completed.
    
  • The output is always 'anonymous block completed.

    Hello

    I wrote a simple stored procedure as shown:

    create or replace procedure display
    *(*
    Ename on emp.ename%type
    *)*
    is
    Start
    Select ename ename from emp where empno = '7369';
    end;

    I tried to run the help above this block

    declare
    Ename emp.ename%type;
    Start
    Display (ename);
    dbms_output.put_line (ename);
    end;

    I always get the output as "anonymous block filled" and nothing else.

    Help, please. Thank you.

    I tried myself and her work.
    In any case, environment in which you work: DB, OS version and software...

    Saad,

  • update happens inside the anonymous PL/SQL block

    Hello

    I use oracle 10g 3.2.
    I'll have a report with checkbox (separate column) so that only certain lines that I chose, I am able to update db.
    At the click of a button following the anonymous PL/SQL block, I'll call you.

    I use the "anonymous PL/SQL block following. The update happens.

    F112_CHECKBOX is a level applocation element

    Start
    : F112_CHECKBOX: = HTMLDB_UTIL. TABLE_TO_STRING (HTMLDB_APPLICATION. G_F01, ",");

    Insert into dumy values(:F112_CHECKBOX);
    commit;

    update set patient_id_code = '123' exp where f_id = 1 and patient_id_code = '12345' and method_internal_index in (: F112_CHECKBOX);
    end;

    The problem is with F112_CHECKBOX. The values I get in F112_Checkbox properly (in the dumy table I checked it shows) but by updating its not taking.
    Can someone tell me something wrong with the syntax of update? method_internal_index column is varchar2 (100).

    Thank you
    Olivier

    The problem is that: F112_CHECKBOX is a string that contains a list of values that you want to update.
    You cannot use it in an IN clause because in doing so, you are running something like:

    update exp
    set patient_id_code='123'
    where f_id=1
    and patient_id_code='12345'
    and method_internal_index in ('111,222,333,444');
    

    This is equivalent to:

    update exp
    set patient_id_code='123'
    where f_id=1
    and patient_id_code='12345'
    and method_internal_index = '111,222,333,444';
    

    And cannot find any line to be updated.

    You can change your update in this way:

    update exp
    set patient_id_code='123'
    where f_id=1
    and patient_id_code='12345'
    and ','||:F112_CHECKBOX||',' like '%,'||method_internal_index||',%' ;
    

    Ensure that: F112_CHECKBOX contains no spaces...

    Max
    http://oracleitalia.WordPress.com

  • PL/SQL anonymous block - try to call the function within cursor

    Hello-

    I need to create an anonymous block that contains a cursor and function. I want to call the function from the cursor and function will essentially have an ID as parameter and will return a list of values comma separated.

    However, when I try to do it I get the error 'function 'GET_PAYMENT_DATES' is not usable in SQL.

    Does anyone know of a workaround? I'm trying to avoid having to store this function.

    Thank you
    Christine

    Well you can't do this using an sql not stored function.
    What you could do is to increase your sort_area_size which can help you to overcome the performance Bug.

    for example: alter session set sort_area_size = 64000;

    other than that, it seems that you need a stored function

Maybe you are looking for

  • I ERASED MY DOWNLOADS BY MISTAKE-HOW RECOVER AND RETURN THEM?

    I looked for answers on how to restore and as someone who doesn't understand computer-ESE - it's confusing. I only meant to clear the cache - and accidentally erased my downloads. I tried to look for them in the downloads from my computer, but they a

  • Newbie Skype - no bar menus

    I have a machine to win 10 almost new.The onboard or on the version line Skype program will display a menu bar, no matter what I navigate to the page. This must be the most counterintuitive software, I already tried to use.

  • subscriptions

    I travel and I want to use Skype to communicate with my husband at home, do I have to buy 2 accounts or can I use the same account. We use the same email.

  • How can I fix a node library to compose with a terminal unwired or bad?

    I am currently working on a program that is designed to send and receive analog data to/from a BNC-2090. Somewhere along the line, LabVIEW has encountered a problem in the library node call the AO Channel.vi create. For this reason, most of the impor

  • After the hard disk configuration, system assigns an incorrect letter to the reader

    I've completely dumped my HDD and it washed. Configured the drive hard and re - format to NTFS with no partitions. I unplug everything not used during reinstallation except monitor, keyboard and mouse "Wired." Reinstalled XP from the disk. Guard syst