Dropping  table using procedure

Hi
I am trying to drop all the tables available in the tname column of temp table .I am using the following procedure
create or replace procedure xyz is
v_table temp.tname%type;
v_temp varchar2(100);
cursor c is select tname from temp;
begin
open c;
loop
fetch c into v_table;
exit when c%NOTFOUND;
v_temp:='drop table'||v_table;
execute immediate v_temp;
end loop;
close c;
end;
the procedure compiling successfully
but iam getting the following error while executing the procedure
ERROR at line 1:
ORA-00950: invalid DROP option
ORA-06512: at line 1
any can one help me in solving this isssue??
thanks,
Balaji tk

You forgot to give a space:
try this:
create or replace procedure xyz is
v_table temp.tname%type;
v_temp varchar2(100);
cursor c is select tname from temp;
begin
open c;
loop
fetch c into v_table;
exit when c%NOTFOUND;
v_temp:='drop table '||v_table; -- given a space between table and v_table.
execute immediate v_temp;
end loop;
close c;
end;
/

Similar Messages

  • How to create table using Procedure

    Hi,
    I want to create table using procedure .
    How to write procedure for the table creation?
    thanks in advance.

    Use dynamic sql or DBMS_UTILITY.EXEC_DDL_STATEMENT:
    SQL> desc tbl1
    ERROR:
    ORA-04043: object tbl1 does not exist
    SQL> begin
      2      execute immediate 'create table tbl1(x number)';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> desc tbl1
    Name                                      Null?    Type
    X                                                  NUMBER
    SQL> drop table tbl1
      2  /
    Table dropped.
    SQL> begin
      2      DBMS_UTILITY.EXEC_DDL_STATEMENT('create table tbl1(x number)');
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> desc tbl1
    Name                                      Null?    Type
    X                                                  NUMBER
    SQL>  SY.

  • How to update the data in sqlserver table using procedure in biztalkserver

    Hi,
    Please can any one answer this below question
    how to update the data in sqlserver table using procedure in biztalkserver
    while am using executescalar,typedprocedure getting some warning
    Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
    Please send me asap....
    Thanks...

    Hi Messip,
    A detailed error would have helped us to answer you more appropriately but
    You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
    http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
    Maheshkumar
    S Tiwari|User
    Page|Blog|BizTalk
    2013: Inserting RawXML (Whole Incoming XML Message) in SQL database

  • Operates on two table using procedure

    i want to handle two table using procedure in oracle 10g. i have created a procedure like this
    CREATE OR REPLACE PROCEDURE sold_car1(
    sid soldcar.sold_id%TYPE,
    cid soldcar.id%TYPE,
    cuid soldcar.customer_id%TYPE,
    eid soldcar.emp_id%TYPE,
    d soldcar.dat%TYPE
    ) IS
    BEGIN
    INSERT INTO soldcar VALUES(sid,cid,cuid,eid,to_date(d,'yyyy/mm/dd'));
    DELETE FROM pcar where id=cid;*
    COMMIT;
    END sold_car1;
    SHOW ERRORS
    i have found some errors. how can i do this.

    hi
    the errors are something like this ''the procedure is created with some errors''.
    actually i want to pass 4 parameters in the procedure that will insert in one table and among the 4 parameters by using one parameter i want to delete one row of another table.
    INSERT INTO soldcar VALUES(sid,cid,cuid,eid,to_date(d,'yyyy/mm/dd')); //soldcar is first table
    DELETE * FROM pcar where id=cid; //pcar is second table

  • How to update multiple records in a table using procedure?

    Dear All,
    1 am using 11.1.2.1.0
    my question is i have a table like
    emp id(primary key), empname,location
    1                             damby      blore
    2                             rocky       kormangala
    3                              biswa     india
    my question  is i need to write one procure that at a time i can update empname and location(wat the value are there in empname and location i  need to change at a time).
    thanks
    Damby

    Hi, Damby,
    That sounds like what the UPDATE statement does, exactly.  Just use an UPDATE statement to change any number of columns in existing rows.  You don't need a procedure, but, if you're using a procedure for some other reason, you can do the UPDATE in the procedure.  UPDATE works the same in SQL or PL/SQL.
    Sometimes MERGE is more convenient than UPDATE.  Like UPDATE, it can change any number of columns, either in SQL or PL/SQL.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Inserting a Flag value in to a table using Procedure

    Hi All-
    we are trying to write a procedure which can refresh Materialized views in the database and upon success full refresh it should insert a flag value say 'Y' or 'N' into a table can you guys give me your thoughts.

    Earlier, you said
    while i am trying to execute that one it is giving me an error.Multiple people have asked you to tell us what error you received. It is very difficult for us to guess the error that you're receiving and to then guess the solution. Perhaps you don't have permission to the DBMS_SNAPSHOT package, perhaps you mis-spelled the name of the materialized view, perhaps you don't own the materialized view, etc. If you tell us the error you're getting, it's far more likely that we're going to be able to help.
    Other than the fact that you're using the DBMS_SNAPSHOT package rather than the DBMS_MVIEW package, which I haven't seen done since the 8i days, I don't see anything obviously wrong with your implementation. As has been pointed out, the design is problematic-- it makes little sense to record in your own table less information than Oracle will record automatically in the data dictionary and to spend time writing additional code to do that lesser level of logging.
    Justin

  • I am unable to create a table using procedure..

    Hi everyone,
    I have given CREATE ANY TABLE privilege to user A and wants to insert data into TAB1 in schema B using a procedure "INSERT INTO B.TAB1 AS SELECT * FROM A.TAB1" but it shows the message--
    PL/SQL: ORA-01031: insufficient privileges
    Which privilege user A need to do the above task.
    Thanks,
    Abhijeet

    SQL> create user a identified by a;
    SQL>create user b identified by b;
    SQL> grant connect,resource to a;
    Grant succeeded.
    SQL> grant connect,resource to b;
    Grant succeeded.
    SQL> grant create any table to a;
    Grant succeeded.
    SQL> conn a/a
    Connected.
    SQL> create table tab1 (id number);
    Table created.
    SQL> insert into tab1 values (1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> conn b/b
    Connected.
    SQL> create table tab1 (id number);
    Table created.
    SQL> insert into b.tab1 select * from tab1;
    insert into b.tab1 select * from tab1
    ERROR at line 1:
    ORA-01031: insufficient privileges
    SQL> conn sys as sysdba
    Enter password:
    Connected.
    SQL> grant insert any table to a;
    Grant succeeded.
    SQL> conn a/a
    Connected.
    SQL> insert into b.tab1 select * from tab1;
    1 row created.
    So you need to grant “*insert any table* “ privileges to a;
    regards
    Liakat hossain

  • Analyze tables using procedure .

    Hello Friends,
    I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
    I have created a procedure -
    create or replace procedure proc_analyze_tables as
    table_count number :=0;
    sqlstatement varchar2(4000);
    begin
    for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
    sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
    EXECUTE IMMEDIATE sqlstatement ;
    dbms_output.put_line ( 'table name is ' || i.TNAME );
    end loop;
    end proc_analyze_tables;
    is it appropiate to use the folllowing statment.
    exec dbms_stats.gather_schema_stats(ownname=>'myschema_name', options=>'GATHER AUTO');
    When I execute the procedure , I am getting invalid analyze command .
    How I can use the procedure or is their any command that can be executed by execute immediate statement !!
    thanks/kumar

    kumar73 wrote:
    Hello Friends,
    I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
    I have created a procedure -
    create or replace procedure proc_analyze_tables as
    table_count number :=0;
    sqlstatement varchar2(4000);
    begin
    for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
    sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
    EXECUTE IMMEDIATE sqlstatement ;
    dbms_output.put_line ( 'table name is ' || i.TNAME );
    end loop;
    end proc_analyze_tables;
    When I execute the procedure , I am getting invalid analyze command .
    How I can use the procedure or is their any command that can be executed by execute immediate statement !!
    thanks/kumarANALYZE TABLE is obsoleted & deprecated.
    use DBMS_STATS instead
    The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing it to EXECUTE IMMEDIATE.
    COPY the statement & PASTE into sqlplus to validate its correctness.

  • DROP TABLE works through SSMS but not via T-SQL Query

    Hello All,
    I am trying to drop a number of tables (1,000+) in a particular database by scripting the actions in T-SQL. When I run the query I get error 3701 on every table which points to a permissions issue. However, I am able to delete tables one by one using
    the tree-view in the SSMS Object Explorer. 
    1. I have tried starting query sessions with both the DBO of the database and the SA account to no avail. (Both had the sysadmin role when I tried.)
    2. Both the DBO account and the SA account are able to drop tables using SSMS Object Explorer.
    Do I need a specific GRANT of permissions to use T-SQL versus SSMS or am I missing something even more fundamental?
    TIA, Simon
    <code>
    DECLARE @Company VARCHAR(max), 
    @ID VARCHAR(max), 
    @NAME VARCHAR(max), 
    @TABLE_CATALOG VARCHAR(max),
    @NAV_DATABASE VARCHAR(max),
    @TABLE_NAME VARCHAR(max), 
    @STATEMENT VARCHAR(max),
    @OBJECT_NAME VARCHAR(max),
    @OBJECT_NAME_BARE VARCHAR(max),
    @OBJECT_TYPE VARCHAR(max);
    SET @TABLE_CATALOG = 'NAV_PENTA_TEST_GAAP';
    SET @NAV_DATABASE = @TABLE_CATALOG
    IF @TABLE_CATALOG <> DB_NAME() 
    BEGIN
    DECLARE @ERRORMSG VARCHAR(max);
    SET @ERRORMSG =  'You are not in the correct database. You specified ' + @TABLE_CATALOG + ' but you are currently in a session for ' + db_name();
    RAISERROR(@ERRORMSG, 18, 1);
    RETURN;
    END;
    -- To hold the object names (tables) from Navision
    CREATE TABLE #NavisionObjects
    [CompanyName]
    VARCHAR(max),
    [ID] VARCHAR(max),
    [Name]
    VARCHAR(max),
    [TABLE_NAME]
    VARCHAR(max)
    -- To hold the object names (tables) from SQL only
    CREATE TABLE #NavisionSQLObjects
    [TABLE_NAME]
    VARCHAR(max)
    -- Holds the list of dependent objects
    CREATE TABLE #DependentObjects
    [name] VARCHAR(max),
    [type] VARCHAR(max)   
    WITH T AS (
    SELECT [Company Name],[ID],[Name],[Company Name]+'$'+[Name] AS TABLE_NAME 
    FROM [Object]   
    WHERE [Name] like '%IT IS%' AND [Company Name]>''
    UNION ALL
    SELECT [Company Name],[ID],[Name],[Name] AS TABLE_NAME 
    FROM [Object]   
    WHERE [Name] like '%IT IS%' AND [Company Name] IN ('',' ')
    INSERT INTO #NavisionObjects SELECT [Company Name],[ID],[Name],[TABLE_NAME] FROM T;
    UPDATE #NavisionObjects SET TABLE_NAME = TABLE_NAME+ID WHERE ID LIKE '1%';
    INSERT INTO #NavisionSQLObjects 
    SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_CATALOG = @TABLE_CATALOG AND TABLE_NAME LIKE '%IT IS%' AND TABLE_TYPE='BASE TABLE';
    --SELECT * FROM #NavisionObjects where CompanyName like 'E15%' order by TABLE_NAME;
    --SELECT * FROM #NavisionSQLObjects where TABLE_NAME like 'E15%' order by TABLE_NAME;
    DECLARE cTables CURSOR FOR SELECT A.CompanyName,A.ID,A.[TABLE_NAME] FROM #NavisionObjects A
    INNER JOIN #NavisionObjects B ON B.[TABLE_NAME]=A.[TABLE_NAME]
    OPEN cTables;
    FETCH NEXT FROM cTables INTO @Company,@ID,@TABLE_NAME;
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
    PRINT 'Storing dependencies for [' + @TABLE_NAME + ']';
    BEGIN TRY
    INSERT INTO #DependentObjects 
    EXEC sp_depends @TABLE_NAME;
    END TRY
    BEGIN CATCH
    PRINT 'Could not get dependencies for table [' + @TABLE_NAME + ']';
    END CATCH
    FETCH NEXT FROM cTables INTO @Company,@ID,@TABLE_NAME;
    END
    CLOSE cTables;
    Drop dependent objects first so that table drops are less likely to fail. 
    DECLARE cdo CURSOR FOR SELECT [Name],[Type] FROM #DependentObjects;
    OPEN cdo;
    FETCH NEXT FROM cdo INTO @OBJECT_NAME, @OBJECT_TYPE;
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
    BEGIN TRY
    SET @OBJECT_NAME_BARE = 
    CASE 
    WHEN CHARINDEX('dbo',@OBJECT_NAME) = 1
    THEN RIGHT(@OBJECT_NAME,LEN(@OBJECT_NAME)-4)
    ELSE @OBJECT_NAME
    END;
    SET @STATEMENT = 'DROP ' + @OBJECT_TYPE + ' [' + @OBJECT_NAME_BARE + ']';
    PRINT @STATEMENT;
    EXEC sys.sp_sqlexec @STATEMENT;
    END TRY
    BEGIN CATCH
    PRINT 'Could not DROP object [' + @OBJECT_NAME + '] of type ' + @OBJECT_TYPE + ', SQL Error ' + CAST(@@ERROR AS VARCHAR(max));
    END CATCH
    FETCH NEXT FROM cdo INTO @OBJECT_NAME, @OBJECT_TYPE;
    END
    CLOSE cdo;
    DEALLOCATE cdo;
    OPEN cTables;
    FETCH NEXT FROM cTables INTO @Company,@ID,@TABLE_NAME;
    WHILE (@@FETCH_STATUS = 0)
    BEGIN
    PRINT 'Removing [' + @TABLE_NAME + ']' ;
    BEGIN TRY
    SET @STATEMENT = 'TRUNCATE TABLE dbo.[' + @TABLE_NAME + ']';
    PRINT @STATEMENT;
    EXEC sys.sp_sqlexec @STATEMENT;
    END TRY
    BEGIN CATCH
    PRINT 'Could not truncate table [' + @TABLE_NAME + ']';
    END CATCH
    BEGIN TRY
    SET @STATEMENT = 'DROP TABLE dbo.[' + @TABLE_NAME + ']';
    PRINT @STATEMENT;
    EXEC sys.sp_sqlexec @STATEMENT;
    BEGIN TRY
    SET @STATEMENT = 'DELETE FROM [Object] WHERE [Company Name] = ' + CHAR(39) + @Company + CHAR(39) + ' AND [ID] = ' + CHAR(39) + @ID + CHAR(39) + ' AND [TABLE_NAME] = ' + CHAR(39) +
    @TABLE_NAME + CHAR(39) ;
    EXEC sys.sp_sqlexec @STATEMENT;
    print @STATEMENT;
    END TRY
    BEGIN CATCH
    PRINT 'Could not Delete Object [' + @TABLE_NAME + '], from Object table, SQL Error ' + CAST(@@ERROR AS VARCHAR(max));
    END CATCH
    END TRY
    BEGIN CATCH
    PRINT 'Could not DROP table [' + @TABLE_NAME + '], SQL Error ' + CAST(@@ERROR AS VARCHAR(max));
    END CATCH
    FETCH NEXT FROM cTables INTO @Company,@ID,@TABLE_NAME;
    END
    CLOSE cTables;
    DEALLOCATE cTables;
    DROP TABLE #DependentObjects;
    DROP TABLE #NavisionObjects;
    DROP Table #NavisionSQLObjects;
    </code>

    3701 = ...does not exist or you don't have permission.
    Most of the time it means the former. So there are probably some problems in your DROP TABLE statements. Since there is a whole lot about Navision in the script, I decline from trying to figure out what. But I encourage you to study the PRINT statements.
    I think that it would be a good idea to include the schema name, in cases these tables are not in dbo after all.
    Note: rather than writing:
       SET @STATEMENT = 'DROP ' + @OBJECT_TYPE + ' [' + @OBJECT_NAME_BARE + ']';
    write:
       SET @STATEMENT = 'DROP ' + @OBJECT_TYPE + quotename(@OBJECT_NAME_BARE)
    Somewhat briefer. And it works also when the object name includes a right bracket.
    sp_sqlexec is undocumented, use sp_executesql instead.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Dropping a Table Using PL/SQL

    I've read that PL/SQL doesn't support DDL, which seems to mean that I cannot use PL/SQL to create, alter, or drop a table. Is this true? I've written (but not tested) some PL/SQL code that needs to drop a table and rename another table under certain circumstances. Would this code work?:
    IF archAlertCount = 0 THEN
         EXECUTE IMMEDIATE 'DROP TABLE ' || tName(x);
         EXECUTE IMMEDIATE 'RENAME ' || tName(x) || '_temp TO ' || tName(x);
         COMMIT;
    ELSE
         ROLLBACK;
         END IF;
    END LOOP;
    I can't test it because my test environment isn't ready... that's why I'm asking instead of just trying it.
    As always, I appreciate any responses.
    Rebecca

    Hello;
    This Points you should have still in focus.
    * Implicit Commit's with DDL's
    your transaction before a DDL are automatically committed.
    * Invalid Package
    If your procedure references the Object, which should be dropped,
    in static code it will get invalid.
    Ciau
    Orca

  • Ceating table using PL/SQL procedure?

    Hello.
    I need to run a process (in Oracle) which creates some tables according to some specific logic. Before creating those tables I would like to check if it already exists and if it does - to drop it.
    (when trying to do it I got an error : 'ORA-01031' insufficient privileses)
    I was reading some forums on the net and I understand that it is a bad practise to create tables from Procedures in Oracle.
    Please advice which other option I have.
    Thanks!

    Thans for your responses.
    Example of what I need:
    create table TABLE1 as select * from
    SELECT TABLE1.x, TABLE2.y
    FROM TABLE1
    INNER JOIN TABLE2 ON TABLE1.X=TABLE2.X
    ... (it's just a short example. the query i use i much longer and more difficult).
    I need to create ~10 tables on the same manner.
    It has to be a kind of daily process. But if by mistake this table was previously deleted - I will get an error when dropping it. That's why I need to use a kind of condition in order to check this.
    Please let me know which alternatives I have.
    Thanks.

  • How to read I$ table using ODI procedure

    Hi
    Can any one help me how to drop a I$ table from out sie of interface.
    I have tried below approches but no luck
    I have created ODI procedure with technology oracle and target logical schema (I$ tables are creating on target DB) with and with out begin and end;
    Approch 1:
    Given below code in ODi procedure
    drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> <% if (new Integer(odiRef.getOption( "COMPATIBLE" )).intValue() >= 10 ) { out.print( "purge" ); }; %>
    Approch 2:
    drop table I$_<%=odiRef.getTable("L", "TARG_NAME", "A") %>;
    Approch 3:
    drop table <%=odiRef.getTable("L", "INT_NAME", "W")%> (but it is fetching target dtabase schema anme not I$ table)
    Please help me any other alternative way to drop a I$ table, more over this code should be unique for all interface
    Regards,
    Phanikanth

    Thanks bhabani,
    Actaul my requirement is some time my scenario is stoping due some issue at Merge Rows Step (I am using IKM Oracle Incremental Update(Merge) KM) when the next iteration starts it is thwoing and error at create flow table I$ step and error is table name is already exists, so i am doing is if the interface went failed I am storing those information in one table using ODI procedure (INF--ko-->ODI procedure) in same ODI procedure I want to call a I$ table to drop.
    Can you please provide the steps so it will very useful for me using Java variable.
    I have gievn a step as below on create I$ table step (after create I$ statement)
    <@ java.lang.String Idollertable = <%=odiRef.getTable("L", "INT_NAME", "W")%> ; @>
    I am calling Idollertable variable in ODI procedure which is ko>* of INF as <@=Idollertable@>
    Note: I have followed below approch
    ODI Procedure Code:
    drop table <@=Idollertable@>; --> *2nd approch*
    begin
    insert into ODI_EXECUTION_ERROR_DETAILS
    (SESSION_NO,
    SCENARIO_NAME,
    CONTEXT_NAME,
    ERR_MESSAGE,
    INSERT_COUNT,
    ERROR_COUNT)
    values
    <%=snpRef.getSession("SESS_NO")%>,
    '<%=odiRef.getPrevStepLog("STEP_NAME")%>',
    '<%=odiRef.getContext( "CTX_NAME" )%>',
    '<%=odiRef.getPrevStepLog("MESSAGE")%>',
    '<%=odiRef.getPrevStepLog("INSERT_COUNT")%>',
    '<%=odiRef.getPrevStepLog("ERROR_COUNT")%>'
    commit;
    drop table <@=Idollertable@>; --> * first approch *
    end;
    Please help me
    Regards,
    Phanikanth
    Edited by: Phanikanth on Mar 3, 2013 9:52 PM
    Edited by: Phanikanth on Mar 3, 2013 9:52 PM

  • How to list all tables/stored procedures used by the report

    All the reports i create are getting data from stored procedure(s). Is there a way to obtaining a listing of all the stored procedures without having to open report by report and check under Database > Set Datasource Location > Properties > Table Name?
    Finding this info it would be extremely valuable, as it would help me to judge the impact of any changes that i might be considering to one or more of the stored proc.
    So far i maintained a manual listing but it is not up-to-date and reliable. I would rather prefer to get an updated listing every time i want to change/drop a stored procedure.
    Thanks so much for your help.
    Rick

    Dell can you be a little bit more specific about the SDK solution. I could ask one of the developers to help me but i need to gather more details.
    I took a look .rpt inspector Pro but it does not do what i need. All i need is the the listing of all the database tables (in my case stored procs) used in my reports. No need to replace or change anything. I need to scan the directory where i have all the reports for the different applications and get report names and table/stored procs used. i can export the txt file to excel and that's all.

  • How to write a procedure to load the data into a table using xml file as input to the procedure?

    Hi,
    Iam new to the xml,
    can u please anyone help me how to write procedure to load the data into a table using xml as input parameter to a procedure and xml file is as shown below which is input to me.
    <?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>.
    Regards,
    vikram.

    here is the your XML parse in 11g :
    select *
      from xmltable('//Entity' passing xmltype
    '<?xml version="1.0"?>
    <DiseaseCodes>
    <Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    <Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity>
    </DiseaseCodes>
    ') columns
      "dcode" varchar2(4000) path '/Entity/dcode',
      "ddesc" varchar2(4000) path '/Entity/ddesc',
      "reauthflag" varchar2(4000) path '/Entity/reauthflag'
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    Using this parser you can create procedure as
    SQL> create or replace procedure myXMLParse(x clob) as
      2  begin
      3    insert into MyXmlTable
      4      select *
      5        from xmltable('//Entity' passing xmltype(x) columns "dcode"
      6                      varchar2(4000) path '/Entity/dcode',
      7                      "ddesc" varchar2(4000) path '/Entity/ddesc',
      8                      "reauthflag" varchar2(4000) path '/Entity/reauthflag');
      9    commit;
    10  end;
    11 
    12  /
    Procedure created
    SQL>
    SQL>
    SQL> exec myXMLParse('<?xml version="1.0"?><DiseaseCodes><Entity><dcode>0</dcode><ddesc>(I87)Other disorders of veins - postphlebitic syndrome</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J04)Acute laryngitis and tracheitis</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity><Entity><dcode>0</dcode><ddesc>(J17*)Pneumonia in other diseases - whooping cough</ddesc><claimid>34543></claimid><reauthflag>0</reauthflag></Entity></DiseaseCodes>');
    PL/SQL procedure successfully completed
    SQL> select * from MYXMLTABLE;
    dcode                                                                            ddesc                                                                            reauthflag
    0                                                                                (I87)Other disorders of veins - postphlebitic syndrome                           0
    0                                                                                (J04)Acute laryngitis and tracheitis                                             0
    0                                                                                (J17*)Pneumonia in other diseases - whooping cough                               0
    SQL>
    SQL>
    Ramin Hashimzade

  • Table name input. and output i need  all rows and columns  using procedures

    hi,
    question: table name input. and output i need all rows and columns by using procedures.
    thanks,
    To All

    An example of using DBMS_SQL package to execute dynamic SQL (in this case to generate CSV data in a file)...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

Maybe you are looking for

  • A665-s6056, windows 7 64, and a 32 bit windows?

    Hi, I've just purchased a Satellite A665-s6056 which is preinstalled with Windows 7 64 bit.  I'd like to be able to use a 32 bit Windows OS as well.  I'm wondering if I can install a Windows 7 32 bit system or a Windows XP 32 bit system alongside the

  • OUTGOING PAYMENT APPROVAL ERROR

    Hi All I m facing one issue while approving out going payment My user trying to open document for approval but system giving error No matching record found 'Docs, for Confirmation' (OWDD) ODBC 2028 Thanks Ricky

  • WLC5500 :: disable Dynamic Channel Assignment (DCA) for a group of APs

    Hi, Is it possible to disable DCA for a couple of APs and manually force the channels assignment ? Thks DV

  • Flash.filesystem not found

    Hi, i just install Flex builder 3, and i want to create files, but i dont have le pachage flash.filesystem nor class File. can you please tell me where can found it or where can i download it? thanks.

  • CAT6 and PT60 log search related

    Hi all, I have scheduled CAT6 and PT60 as scheduled back ground jobs. How do I check the error/processed log for both these Tcodes???