Creating tables in pl/sql block

I have the following piece of code that I execute in sqlplusw as @c:\process.sql
On running @c:\process.sql, an input is provided as prompted. There is a
declare and begin that processes some code. What I am looking for is -- Is there
a way that I can check the all_tables view for the following 3 tables :
TABLE1, TABLE2, TABLE3. Only on finding these tables, this
anonymous sql (that is inside starting from declare ... should execute).
If these tables are not found, I want to attempt creating the tables. If the attempt
was successful, then process. If creating tables attempt fails, exit with a dbms_output.put_line message and don't process
anything....
Can this be done ? If so, any hints would be great.....
Thanks
ACCEPT input_ssn prompt 'Enter SSN :'
SET feedback off
SET serveroutput on
SET echo off
SET term off
SET heading off
SET pagesize 0
SET linesize 10000
SET verify off
undefne sdate input_ssn
COL sdate new_value sdate
COL input_ssn new_value input_ssn
SELECT TO_CHAR (SYSDATE, 'YYYYMMDD') sdate
FROM DUAL;
SPOOL C:\SCRUB_DATA_&&sdate._&&input_ssn..TXT
SELECT 'REPORT GENERATED ON : ' || SYSDATE
FROM DUAL;
ALTER TRIGGER TRIG1 DISABLE;
DECLARE
BEGIN
FOR i IN .........
LOOP
END LOOP;
BEGIN
SELECT ..........
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...........
FOR i IN .....
LOOP
UPDATE ....
BEGIN
SELECT ...
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...
BEGIN
SELECT ....
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
UPDATE ...
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
     NULL;
WHEN OTHERS
THEN
ecode := SQLCODE;
emesg := SQLERRM;
DBMS_OUTPUT.put_line ('Error code is : '||' - '|| ecode);
DBMS_OUTPUT.put_line ('Error message is :' || ' - ' || emesg);
END;
COMMIT ;
ALTER TRIGGER TRIG1 ENABLE;
SET term on
SET HEADING on
SELECT 'Processing complete for ' || '&&input_ssn'
FROM DUAL;
SPOOL off;
SET verify on
SET feedback on
----------------------------------------------------------

This is what I am doing :
ACCEPT input_ssn prompt 'Enter SSN :'
SET feedback on
SET serveroutput on
SET echo on
SET term on
SET heading on
SET pagesize 0
SET linesize 10000
SET verify on
undefne sdate input_ssn
COL sdate new_value sdate
COL input_ssn new_value input_ssn
SELECT TO_CHAR (SYSDATE, 'YYYYMMDD') sdate
FROM DUAL;
SPOOL C:\TEMP_DATA_&&sdate._&&input_ssn..TXT
ALTER TRIGGER TRIG1 DISABLE;
DECLARE
v_postal cheque.postal%TYPE;
v_count NUMBER;
l_tabexist NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('HELLO THERE');
     BEGIN
          DBMS_OUTPUT.PUT_LINE('HI THERE');
          SELECT 1 INTO l_tabexist FROM all_tables
               WHERE table_name = 'TABLE1_TEMP' AND owner='HARPER';
     EXCEPTION
          WHEN NO_DATA_FOUND THEN
               EXECUTE IMMEDIATE 'CREATE TABLE TABLE1_TEMP AS SELECT * FROM TABLE1 WHERE 1=2';
               EXECUTE IMMEDIATE 'ALTER TABLE TABLE1_TEMP ADD(TEMP_STATUS VARCHAR2(1))';
     END;
     BEGIN
               SELECT 1 INTO l_tabexist FROM all_tables
                    WHERE table_name = 'TABLE2_TEMP' AND owner='HARPER';
          EXCEPTION
               WHEN NO_DATA_FOUND THEN
                    EXECUTE IMMEDIATE 'CREATE TABLE TABLE2_TEMP AS SELECT * FROM TABLE2 WHERE 1=2';
                    EXECUTE IMMEDIATE 'ALTER TABLE TABLE2_TEMP ADD(TEMP_STATUS VARCHAR2(1))';
     END;
BEGIN
<my code that uses TABLE1_TEMP and TABLE2_TEMP supposed to be created above>
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('No Data Found Exception encountered');
END;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.Put_Line('Something bad happened');
RAISE;
END;
COMMIT ;
ALTER TRIGGER TRIG1 ENABLE;
SET term on
SET HEADING on
SPOOL off;
SET verify on
SET feedback on
What is happening here is that until ALTER TRIGGER DISABLE, things are fine.
Then, it tries to process <my code> and cries saying 'Table or view not found'. Finally it enables the trigger back.
It is not even displaying either the 'HELLO THERE' or 'HI THERE' - which I suppose is the first thing it should have done.
Thanks

Similar Messages

  • Creating temporary table in pl/sql block problem

    hello
    i have a problem in creating and using temporary table in pl/sql block
    please verify below block
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    insert into alitemp1 (co_t,color) values ('001','red');
    execute immediate 'DROP TABLE alitemp1';
    end;
    when i execute that block i will receive this error
    insert into alitemp1 (co_t,color) values ('001','red');
    ERROR at line 3:
    ORA-06550: line 3, column 14:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 3, column 2:
    PL/SQL: SQL Statement ignored
    i think it because that alitemp1 table don't create
    but two below block run fine
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    execute immediate 'DROP TABLE alitemp1';
    end;
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    end;
    select table_name from user_tables where table_name='ALITEMP1';
    TABLE_NAME
    ALITEMP1
    it means that problem is when the below line exists in block
    insert into alitemp1 (co_t,color) values ('001','red');
    if may please guide me

    In addition to the comments by Justin and 3360, you cannot do what you want the way you are doing it.
    All objects referred to in a PL/SQL block must exist at the time the block is compiled. In your case, since it is an anonomous block, that is run time. Since you are dynamically creating the temporary table you need to refer to it dynamically as well. More like:
    BEGIN
    EXECUTE IMMEDIATE 'create global temporary table alitemp1 (co_t varchar2(10),
                                                               color varchar2(10))';
    EXECUTE IMMEDIATE 'insert into alitemp1 (co_t,color) values (:b1,:b2)' USING '001', 'red';
    EXECUTE IMMEDIATE 'DROP TABLE alitemp1';
    END;However, don't do that it is a really bad idea. Just create the temporary table, if you really need it, once and use it in your processing.
    In most cases, things that SQL Server needs temporary tables for can be done easily in Oracle with a single SQL statement,
    John

  • How To Create User through Pl SQL Block

    Want to create user from pl sql block using dynamic SQl. Used dbms_sql package . But when I run the block it does not recognises the parameter v7 which is a constant in dbms_sql package. Message displayed is Can not access parameter from package being restricted procedure.
    Is there any method to create user through PL SQl block

    hi ranjit,
    hope this will work
    declare
    uname varchar2(30):=&uname;
    pword varchar2(30):=&pword;
    begin
    execute immediate ('grant connect, resource to '&#0124; &#0124;uname&#0124; &#0124;' identified by '&#0124; &#0124;pword);
    end;
    regards

  • Create table in PL/SQL proc not working

    Hello,
    Here is a procedure I have tried to create & run in SQL Developer:
    create or replace procedure transpose as
    begin
    create table lines as (select level line from dual connect by level <= 5),
    create table cols as (select level col from dual connect by level <= 5),
    select max(decode(col, 1,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col1,
    max(decode(col, 2,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col2,
    max(decode(col, 3,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col3,
    max(decode(col, 4,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col4,
    max(decode(col, 5,
    decode(line, 1, line_id,
    2, description,
    3, statetax,
    4, freight,
    5, weightedAvg))) col5
    from lines, cols,
    (select rownum rn, tfe_line_info.* from tfe_line_info)
    where rn = col
    group by line
    order by line;
    end transpose;
    I however get the error:
    Error(3,7): PLS-00103: Encountered the symbol "CREATE" when expecting one of the following: begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
    I cannot understand what is wrong with my Create statement at line 3?

    It looks like you have no PL/SQL experience. I suggest reading PL/SQL manual. Yes, single row select requires INTO clause. Multi-rows select requires cursor. But this is least of your problems. Your SPp will not complile even if you fix select. Why? SP creates tables dynamically at run time, so tables do not exist at SP compile time. Therefore select from these yet non-existent tables will not compile. By creating tables via dynamic SQL you forced yourself into querying them via dynamic SQL. Now you are trying to transpose (pivot) table. What Oracle version do you have? Oracle 11g provides PIVOT/UNPIVOT operators. Check them out before writing code.
    SY.

  • ERROR creating table with dynamic SQL :-(

    Hi friends,
    I have a problem when I try to create a table using dynamic SQL.
    (Env.: Forms 6i, WinXP, Oracle 9i)
    I only want to create a table, insert data and drop the table.
    I have a user with the correct privileges (At least ....I think so), because I can to make the three actions in SQL*PLUS (CREATE TABLE, INSERT .. and DROP TABLE).
    I want to do the same in Forms using dynamic SQL...
    I've made a package with 3 procedures:
    1st to create the table, 2nd to insert data , 3rd to drop the table.
    Only the 1st fails with the error ORA-01031 (insufficient privileges).
    Here it is:
    PROCEDURE PRO_DM_CreaTabla(pe_nombre_tabla VARCHAR2) IS
    id_cursor INTEGER;
    ls_sentencia VARCHAR2(500);
    v_dummy integer;
    BEGIN
    id_cursor := DBMS_SQL.OPEN_CURSOR;
    ls_sentencia := 'CREATE TABLE '||pe_nombre_tabla||' ( campo1 VARCHAR2(100), campo2 VARCHAR2(100), campo3 VARCHAR2(100),campo4 VARCHAR2(100))';
    DBMS_SQL.PARSE(id_cursor, ls_sentencia, dbms_sql.NATIVE);
    v_dummy := dbms_sql.execute(id_cursor);
    DBMS_SQL.CLOSE_CURSOR(id_cursor);
    END;
    The DROP_table procedure is exactly the same as this (with the difference of the 'CREATE' sentence, where I have a DROP sentence)... then.. why the DROP procedure works?... and.. why this CREATE procedure doesn't work?
    Any ideas?
    Thanks a lot.
    Jose.

    From a different thread, Jose wrote:
    V_INSERT:='INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4)';
    Forms_DDL(V_INSERT);
    commit;First, try your statement in SQL Plus:
    INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4);
    Then if that works, try doing this right after the Forms_DDL(V_INSERT);
    If not form_success then
      Message('   Insert has failed');
      Raise form_trigger_failure;
    Else
      Forms_DDL('COMMIT');
    End if;

  • Create Schema via PL/SQL block from textbox

    I'm trying create a user based on a text box that the user/dba will enter. Is there not a way to use a bind variable for what is entered into the textbox, here is my pl/sql block:
    BEGIN
    EXECUTE IMMEDIATE 'create user :SCHEMA identified by :SCHEMA
    DEFAULT TABLESPACE USERS
         TEMPORARY TABLESPACE TEMP
         QUOTA 0 ON SYSTEM
         QUOTA UNLIMITED ON USERS
         PROFILE DEFAULT';
    end;
    Any help is appreciated!

    Ok, This work for creating the user now:
    BEGIN
    EXECUTE IMMEDIATE 'create user &SCHEMA. identified by &SCHEMA_PWD.
    DEFAULT TABLESPACE USERS
    TEMPORARY TABLESPACE TEMP
    QUOTA 0 ON SYSTEM
    QUOTA UNLIMITED ON USERS
    PROFILE DEFAULT';
    END;
    All I did was change the textbox to just a textbox w/o submit and made the password a submit password and it worked, now I am getting insufficient priviledges when I try to add in:
    BEGIN
    EXECUTE IMMEDIATE 'create user &SCHEMA. identified by &SCHEMA_PWD.
    DEFAULT TABLESPACE USERS
    TEMPORARY TABLESPACE TEMP
    QUOTA 0 ON SYSTEM
    QUOTA UNLIMITED ON USERS
    PROFILE DEFAULT';
    EXECUTE IMMEDIATE 'GRANT CONNECT,RESOURCE TO &SCHEMA.';
    EXECUTE IMMEDIATE 'ALTER USER &SCHEMA. DEFAULT ROLE ALL';
    END;
    I have disabled Authentication and made it DAD..which is the HTMLDB_PUBLIC_USER which has dba role..but still gives me insufficient priviledges. Any help is appreciated!

  • Create table with PL/SQL

    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Hi,</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">I would like to create a table with PL/SQL statement. I wrote that :</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">IF</font><font SIZE="2"> T_Exists </font><font SIZE="2" COLOR="#0000f0">=</font><font SIZE="2"> </font><font SIZE="2" COLOR="#ff0000">'N'</font><font SIZE="2"> </font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">THEN</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#008000" face="Courier New">-- Create the table</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  CREATE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">TABLE</font></font><font face="Courier New" size="2"> T_Name</font></p>
    <p style="margin-top: 0; margin-bottom: 0"><font SIZE="2" COLOR="#0000f0" face="Courier New">  (</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    EXPLICITKEY </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000"> VARCHAR2</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">25</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    BALANCE </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">     NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD01 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD02 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">),</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">    PERIOD03 </font></font><font face="Courier New"><font SIZE="2" COLOR="#ff0000">    NUMBER</font><font SIZE="2" COLOR="#0000f0">(</font><font SIZE="2" COLOR="#800000">15</font><font SIZE="2" COLOR="#0000f0">,</font><font SIZE="2" COLOR="#800000">2</font></font><font face="Courier New" SIZE="2" COLOR="#0000f0">),</font></p>
    <font SIZE="2" face="Courier New"><p style="margin-top: 0; margin-bottom: 0">  </font><font SIZE="2" COLOR="#0000f0" face="Courier New">);</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#0000f0" face="Courier New">ELSE</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font SIZE="2" COLOR="#008000" face="Courier New">-- Truncate the table</p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  DELETE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2"> T_Name</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">;</font></p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">END</font><font SIZE="2"> </font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">IF;</font></p>
    </font>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">But there is an error :</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">PLS-00103: Encountered the symbol &quot;CREATE&quot; when expecting one of the following:</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">begin case declare exit for goto if loop mod null pragma</font></p>
    <p style="margin-left: 10; margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">raise return select update while with &lt;an identifier&gt;</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Do you know why ?</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Thank you for you help.</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><i><b><font face="Tahoma" size="2">Patrick</font></b></i></p>

    Thank you very much. And you're right because there is an error with the table <b>T_Name</b> because it doesn't exit. But <b>T_Name</b> is a variable with the name of the table to manage.
    How can I send a variable name of table in the part :
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    </font><font SIZE="2"><p style="margin-top: 0; margin-bottom: 0"></font><font face="Courier New"><font SIZE="2" COLOR="#0000f0">  DELETE</font><font SIZE="2"> </font><font SIZE="2" COLOR="#0000f0">FROM</font><font SIZE="2"> T_Name</font></font><font SIZE="2" COLOR="#0000f0"><font face="Courier New">;</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2">Thank you.</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><i><b><font face="Tahoma" size="2">Patrick</font></b></i></p>

  • Error creating table on MS SQL Server with OC4J standalone

    Hi there,
    I'm trying to deploy an EJB application to OC4J standalone using a MS SQL Server 2000 database, MS SQL Server JDBC Drivers and OC4J 9.0.3 standalone but i keep getting this error:
    Auto-creating table: create table Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb (Functieprofiel_FUNCTIE_ID bigint identity not null, COMP_ID bigint identity null, NIVEAU_ID sql_variant(255) null)
    Error creating table: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Could not create IDENTITY attribute on nullable column 'COMP_ID', table 'Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb'.
    Deployment succeeds after this but the application does not run properly. Can anyone help me with this? I have no idea what to do.
    Rob Heikoop

    Rb -
    if you want to stop the auto-creation of tables, try going to the j2ee/home/config directory of your OC4J installation. Open the application.xml file and modify the attribute autocreate-tables to be set to false.
    That should stop the default table creation as a global property, unless you specifically override it at the specific deployed application level.
    You can then manually create the tables on the sql-server database instance. If you keep the column names the same as the field names in the bean, then you shouldn't need to do any manual mapping. To be sure of the column names to use, take a look in the orion-ejb-jar.xml which gets generated in the j2ee/home/application-deployments/<app-name>/<ejb-module-name> to see what table/column names the generator defaulted to
    -steve-
    -steve-

  • Error while selecting  from nested table in PL/SQL block ............

    SQL> create type string_table is table of varchar(100);
    2 /
    Type created.
    declare
    v_names string_table := string_table();
    begin
    v_names.EXTEND(3);
    v_names(1) := 'name1';
    v_names(2) := 'name2';
    v_names(3) := 'name3';
    dbms_output.put_line(v_names(1));
    dbms_output.put_line(v_names(2));
    dbms_output.put_line(v_names(3));
    dbms_output.put_line(v_names.COUNT());
    select * from table(v_names);
    end;
    select * from table(v_names);
    ERROR at line 12:
    ORA-06550: line 12, column 7:
    PLS-00428: an INTO clause is expected in this SELECT statement

    select * from table(v_names);
    I guess ,here you were trying to put the content of the NT into another NT, or just trying to print it.
    But, I don't think INTO Clause is mandatory here.
    Please check your modified code (w/o INTO) and the output :
    DECLARE
       TYPE string_table IS TABLE OF VARCHAR (100);
       v_names   string_table := string_table ();
       v_test    string_table := string_table ();
    BEGIN
       v_names.EXTEND (3);
       v_names (1) := 'name1';
       v_names (2) := 'name2';
       v_names (3) := 'name3';
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (1));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (2));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names (3));
       DBMS_OUTPUT.put_line ('Old collection - '||v_names.COUNT ());
       DBMS_OUTPUT.put_line (CHR(10));
       /* SELECT * FROM TABLE (v_names); */
       v_test := v_names;
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (1));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (2));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test (3));
       DBMS_OUTPUT.put_line ('New collection -- '||v_test.COUNT ());
       DBMS_OUTPUT.put_line (CHR(10));
       /* Printing using FOR LOOP */
       FOR i IN v_test.FIRST..v_test.LAST
       LOOP
         DBMS_OUTPUT.put_line ('In FOR Loop --- '||v_test (i));
       END LOOP;
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error ' ||SQLERRM|| DBMS_UTILITY.format_error_backtrace);
    END;gives o/p :
    Old collection - name1
    Old collection - name2
    Old collection - name3
    Old collection - 3
    New collection -- name1
    New collection -- name2
    New collection -- name3
    New collection -- 3
    In FOR Loop --- name1
    In FOR Loop --- name2
    In FOR Loop --- name3Refer this link -- http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/tuning.htm#CIHGGBGF
    Edited by: ranit B on Dec 26, 2012 2:29 PM
    -- code modified
    Edited by: ranit B on Dec 26, 2012 2:45 PM
    -- code 'again' updated -- FOR LOOP added

  • EXEC SQL & CREATE TABLE

    Hi,
    I am trying to create table using EXEC SQL. But, the table that I had created using EXEC SQL is not shown in data dictionary. I can not see that table from SE11. If I run the same program again, then gives error about there is already a table that I want to create. So, How can see it? Is seeing that table possible?
    EXEC SQL.
    CREATE TABLE ZCOPYTABLE(
    NAME CHAR(15) NOT NULL,
    SURNAME CHAR(15) NOT NULL,
    TEL CHAR(10) NOT NULL,
    PRIMARY KEY (NAME, SURNAME)
    ENDEXEC.

    Hello Huseyin,
    I don't think you can use the Native SQL statements for DDL (data definition language) statements in SQL.
    The reason is that the Native SQL statements by-pass the SAP Application Server and are executed directly at the Database Server. You will find more information on the SAP Online Help Documentation site.
    Since the ABAP Dictionary is very much an application, it fails to recognize the tables which were not created through it.
    The DDL statements in Native SQL are only for advanced database adminstration tasks.
    Hope this helps.
    Regards,
    Anand Mandalika.

  • SQL Developer  Create Table Statement to ERD Visio Diagram

    I have the following Create table statement from SQL Developer and I am trying to generate an ERD Diagram using 2003 Visio. I was wondering what I need to do to convert the Create Table to an ERD Diagram Using Visio. Thanks
    CREATE TABLE “TT_TEAM”.”HR_REVOKED_SECURITY_ORGS”
    “ID” NUMBER NOT NULL ENABLE,
    “ACAT_CODE” VARCHAR2(6 BYTE) NOT NULL ENABLE,
    “APPR_SEQ_NO” NUMBER(3,0) NOT NULL ENABLE,
    “USER_ID” VARCHAR2(30 BYTE) NOT NULL ENABLE,
    “ACTION_IND” VARCHAR2(1 BYTE) NOT NULL ENABLE,
    “ACTIVITY_DATE” DATE NOT NULL ENABLE,
    “COAS_CODE” VARCHAR2(1 BYTE),
    “ORGN_CODE” VARCHAR2(6 BYTE),
    “POSN” VARCHAR2(6 BYTE) NOT NULL ENABLE,
    “MANDATORY_APPR_IND” VARCHAR2(1 BYTE),
    “APPR_POSN” VARCHAR2(6 BYTE),
    “ORGN_MANAGER” VARCHAR2(6 BYTE) NOT NULL ENABLE;

    I'm pretty Visio is a non-Oracle product.
    In the mean-time, you can easily import a DDL script file and create a relational model/diagram using SQL Developer. Use the Import feature and point to your CREATE TABLE script(s)

  • Db_link name and synonym in PL/SQL block

    Hi,
    I'm having a problem with synonyms in PL/SQL block.
    Say, I have two schemas A and B.
    In schema A, I create some tables and stored procedures.
    In schema B, I create a db link connecting to schema A. Then I create some synonyms for tables and stored procedures in schema A with the db link. In stored procedures created in schema B, I need to access or reference objects in schema by using synonyms.
    My problem is, if schema A and schema B reside on the same db instance and the instance's global_names is set to true, I will not be able to reference any synonyms in stored procedures created in schema B. The error message is,
    PL/SQL: ORA-00980: synonym translation is no longer valid.
    A simple example:
    In schema A,
    create table mytable (A char(2));
    In schema B,
    create database link <global_name-for-schema-A>@loopback connect to A identified by <A-pwd> using '<net-service-name-for-schema-A>';
    create synonym mytable for mytable@<global_name-for-schema-A>@loopback;
    declare
    a char;
    begin
    select * from mytable;
    end;
    But I have no problem to access the synonym-ed objects in SQL*PLUS.
    Please help.
    Thanks

    I had the similar problem i did a work around like below
    SQL>select max(col1) from tab1;
    MAX(COL1)
    21161910
    SQL>get a
    1 declare
    2 a number;
    3 begin
    4 select max(col1) into a from tab1;
    5 dbms_output.put_line(a);
    6* end;
    SQL>@a
    select max(col1) into a from tab1;
    ERROR at line 4:
    ORA-06550: line 4, column 1:
    PL/SQL: ORA-00980: synonym translation is no longer valid
    ORA-06550: line 4, column 1:
    PL/SQL: SQL Statement ignored
    Created a view on top of the synonym
    SQL>create or replace view tab1_v as select * from tab1@db1;
    View created.
    changed the pl/sql block as below to get it from view instead of synonymn
    declare
    a number;
    begin
    select max(col1) into a from tab1;
    dbms_output.put_line(a);
    end;
    Now it worked
    SQL>@a
    21161910
    PL/SQL procedure successfully completed.

  • PL/SQL block to generate i/o

    Dear all,
    10.2.0.4 on solaris
    I want to generate I/O on a table. how can I create a a PL/SQL block which loops into and inserts/updates/deletes and commits on this table and thereby testing the I/O on the table ?
    Kai

    KaiS wrote:
    I want to generate I/O on a table. how can I create a a PL/SQL block which loops into and inserts/updates/deletes and commits on this table and thereby testing the I/O on the table ?What about the db buffer cache? What about Oracle attempting to optimise I/O performance by reducing physical I/O? What about the file system used and the o/s file system cache that does the exact same thing?
    How do you now "+test+" I/O? What exactly are you testing? The Oracle buffer cache? The o/s file system cache? The speed of the file system? The speed of the disk(s)?
    And if you get a result like "+100 inserts/per second+" - just what does that mean? How are you going to use this number to determine performance for application code, determine potential bottlenecks and so on?
    A journey can only start when you know the route and most importantly, the destination. Else you're just wandering around without a clue.

  • [Solved] ADF BC - PL/SQL block 6 times faster than CreateRow/InsertRow

    THE ENVIRONMENT:
    - JDeveloper 10.1.2.0.0
    - Oracle 9.2.0.8.0
    THE PROBLEM:
    I found one of my pages in an ADF BC Web Application to be quite slow. After some profiling, I found a significant bottleneck in a loop which inserts approximately 270 rows in a table (only inserts into the table using insertRow). Would there be an improvement if we rewrite the transaction in PL/SQL code? To find out, I came up with the following simple test case:
    1) Table
    create table TES_FSOLICFONDO
    ID_SOLICITUD NUMBER not null,
    A_PAIS VARCHAR2(2),
    C_IDEMPRESA NUMBER,
    A_CODMONEDA VARCHAR2(3),
    C_LOCAL NUMBER,
    D_FECSOLICIT DATE,
    C_IDBILLMONE NUMBER not null,
    M_MONTO NUMBER,
    A_CREADOPOR VARCHAR2(30),
    D_CREACION DATE,
    A_MODIFPOR VARCHAR2(30),
    D_MODIF DATE);
    alter table TES_FSOLICFONDO
    add primary key (ID_SOLICITUD);
    create index IND_TES_FSOLICFONDO_01 on TES_FSOLICFONDO (C_IDBILLMONE, C_LOCAL, D_FECSOLICIT);
    create index IND_TES_FSOLICFONDO_02 on TES_FSOLICFONDO (C_IDEMPRESA, A_CODMONEDA, C_LOCAL, D_FECSOLICIT,C_IDBILLMONE);
    2) Sequence
    create sequence SEQ_TES_FSOLICFONDO
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 1
    increment by 1
    cache 2;
    3) ADF BC
    - Create a Business Components Project with a BC package
    - Create new Entity Object based on the previous table, with standard wizard settings (this will be named TesFsolicfondo)
    - Create new View Object linked to previous Entity Object, with standard wizard settings (this will be named TesFsolicfondoVO).
    - Create an Application Module named AMTESAsignaSuperAvance, and include the previous View Object in the Data Model
    4) The test case
    - Create a test() method in the AMTESAsignaSuperAvanceImpl class as follows:
    public void test() throws Exception
    TesFsolicfondoVOImpl solVO = getTesFsolicfondoVO1();
    TesFsolicfondoVORowImpl r = null;
    for (int i = 0; i < 270; i++)
    r = (TesFsolicfondoVORowImpl) solVO.createRow();
    Sequence seq = new Sequence("SEQ_TES_FSOLICFONDO",this);
    r.setIdSolicitud(new Number(seq.getData().toString()));
    r.setAPais("PE");
    r.setCIdempresa(new Number(637292));
    r.setACodmoneda("USD");
    r.setCLocal(new Number(388));
    r.setDFecsolicit(new Date("2006-04-07"));
    r.setCIdbillmone(new Number(116));
    r.setMMonto(new Number(0));
    r.setACreadopor("10000003480");
    r.setDCreacion(new Date("2006-04-03"));
    solVO.insertRow(r);
    getTransaction().commit();
    - Create a test.jsp page including the following code within a scriptlet:
    AMTESAsignaSuperAvanceImpl am = null;
    try
    am = (AMTESAsignaSuperAvanceImpl) Configuration.createRootApplicationModule("cl.falabella.fpi.tes.bc.AMTESAsignaSuperAvance","AMTESAsignaSuperAvanceLocal");
    am.test();
    catch (Exception e)
    am.getTransaction().rollback();
    finally
    Configuration.releaseRootApplicationModule(am,true);
    - Create an equivalent PL/SQL block as follows:
    BEGIN
    FOR I IN 1..270
    LOOP
    INSERT INTO TES_FSOLICFONDO (ID_SOLICITUD, A_PAIS, C_IDEMPRESA, A_CODMONEDA, C_LOCAL,
    D_FECSOLICIT, C_IDBILLMONE, M_MONTO, A_CREADOPOR, D_CREACION)
    VALUES (SEQ_TES_FSOLICFONDO.NEXTVAL, 'PE', 637292, 'USD', 388, TO_DATE('07-04-2006', 'DD-MM-YYYY'), 116, 0,
    '10000003480', TO_DATE('03-04-2006', 'DD-MM-YYYY'));
    END LOOP;
    COMMIT;
    END;
    THE RESULTS:
    The PL/SQL block was executed on a standard SQL* Plus window, and the test() method within the AM was called from the test.jsp page.
    The PL/SQL block takes 1125 milliseconds in my setup, the test() method within the AM takes 6017 milliseconds, so PL/SQL is about 6 times faster in this test.
    THE QUESTION:
    Is this supposed to be this way? I want to avoid creating a PL/SQL package, I would rather use the ADF BC framework throughout the application. Would someone kindly point out any configuration issues I may have missed that will improve the BC performance?

    Hello Jan,
    Thanks for the tip, good to be born again as a name instead of a number.
    I omitted the code used for timing, but here goes:
    test.jsp:
    java.util.Date d1 = new java.util.Date();
    AMTESAsignaSuperAvanceImpl am = null;
    try
    am = (AMTESAsignaSuperAvanceImpl) Configuration.createRootApplicationModule("cl.falabella.fpi.tes.bc.AMTESAsignaSuperAvance","AMTESAsignaSuperAvanceLocal");
    am.test();
    catch (Exception e)
    am.getTransaction().rollback();
    finally
    Configuration.releaseRootApplicationModule(am,true);
    java.util.Date d2 = new java.util.Date();
    System.out.println("Time (ms) = " + Double.toString(d2.getTime()-d1.getTime()));
    PL/SQL:
    I use a tool called "PL/SQL Developer". It has a "Command Window" with a user interface which is extremely similar to SQL* Plus. After running the PL/SQL code, it reported "PL/SQL procedure successfully completed in 1.125 seconds".
    From the tool documentation:
    The Command Window
    The Command Window allows you to execute SQL scripts in a way that is very much similar to Oracle's SQL*Plus. To create a Command Window press the New button on the toolbar or select the New item in the File menu. A Command Window is created and you can type SQL and SQL*Plus commands like you are used to, without leaving PL/SQL Developer’s IDE.
    Regards
    Rodrigo

  • Create Table using DBMS_SQL package and size not exceeding 64K

    I have a size contraint that my SQL size should not exceed 64K.
    Now I would appriciate if some one could tell me how to create a table using
    Dynamic sql along with usage of DBMS_SQL package.
    Brief Scenario: Users at my site are not given permission to create table.
    I need to write a procedure which the users could use to create a table .ALso my SQL size should not exceed 64K. Once this Procedure is created using DBMS_SQL package ,user should pass the table name to create a table.
    Thanks/

    "If a user doesn't have permission to create a table then how do you expect they will be able to do this"
    Well, it depends on what you want to do. I could write a stored proc that creates a table in my schema and give some other user execute privilege on it. They would then be able to create a able in my schema without any explicitly granted create table privilege.
    Similarly, assuming I have CREATE ANY TABLE granted directly to me, I could write a stroe proc that would create a table in another users schema. As long as they have quota on their default tablespace, they do not need CREATE TABLE privileges.
    SQL> CREATE USER a IDENTIFIED BY a
      2  DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
    User created.
    SQL> GRANT CREATE SESSION TO a;
    Grant succeeded.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01950: no privileges on tablespace 'USERS'So, give them quota on the tablespace and try again
    SQL> ALTER USER a QUOTA UNLIMITED ON users;
    User altered.
    SQL> CREATE TABLE a.t (id NUMBER, descr VARCHAR2(10));
    Table created.Now lets see if it really belongs to a:
    SQL> connect a/a
    Connected.
    SQL> SELECT table_name FROM user_tables;
    TABLE_NAME
    T
    SQL> INSERT INTO t VALUES (1, 'One');
    1 row created.Yes, it definitely belongs to a. Just to show that ther is nothing up my sleeve:
    SQL> create table t1 (id NUMBER, descr VARCHAR2(10));
    create table t1 (id NUMBER, descr VARCHAR2(10))
    ERROR at line 1:
    ORA-01031: insufficient privilegesI can almost, but not quite, see a rationale for the second case if you want to enforce some sort of naming or location standards but the whole thing seems odd to me.
    Users cannot create tables, so lets give them a procedure to create tables?
    John

Maybe you are looking for

  • Photoshop CS4 quits unexpectedly on startup

    I installed all of CS4 Master Collection yesterday, on a brand new iMac.  All programs were working fine.  Today, Photoshop gives the "application quit unexpectedly" message when I try to open it.  However, all of the other programs are still working

  • Importing iTunes music, apps, device backups from Time Capsule

    Recently my old iMac hard drive crashed.  Fortunately, the data is safe on a Time Capsule, and I'd now like to move all the relevant iTunes data (music, photos, device info and apps) to an existing computer and account.  Any suggestions on how to app

  • Library organization

    Hi, I don't understand why the music folder separates tracks according to artist and the featured artist. For example, "Dreamgirls" is split into multiple ablums depending on who the artist and featured artists are for that song. How can I fix this s

  • Update for the z10

    Hi, im holding blackberry z10 from UAE, im not able to see option to update to the new software, please help!!

  • Access Violation R26.4.0

    We received the following dump while testing JRockit R26.4.0 on a dual core E6400 Intel Win XP. (32bit). It's only happened the one time so far. The application in use is a db test application using jdbc to a Pervasive db engine. It's repeatedly just