How to check whether a table exists in database

test9997 is table already made in database with 3 columns :1st-varchar,2nd-number,3rd-number
declare
var1 varchar2(20);
var2 number(20);
var3 number(20);
begin
plvar1 :='this is again pl/sql';
plvar2 := 12;
plvar3 := 13;
IF (???? condition for existence of table say test1111??????) then
create table test1111(
var1 varchar2(20);
var2 number(20);
var3 number(20);
insert into test1111(plvar1,plvar2,plvar3);
else
insert into test1111(plvar1,plvar2,plvar3);;
end if;
end;
in the above code i want to check existence of a table and insertion or updation will be based on it after creation if it doesnt exist.
how to do it
please help asap

You're in the wrong forum (this one is for issues with the SQL Developer tool). You'll get more answers in the SQL And PL/SQL forum.
Have fun,
K.

Similar Messages

  • How to test whether a table exists in database?

    How can I test whether a table exists in a database before I execute a query? If the table doesn't exist, I want first create a default table with certain name so that I can always display something in JTable.
    Thanks!

    Hi,
    There are tow ways :
    The first one is :
    - load the list of tables of the Database in a Vector for exemple by using methode DatabaseMetaData.getTables () and you can test if the table exist or not in the vector by using methode Vector.contains(Object o).
    The code seems Like that :
    // Loading List Of Tables
    // you need to load the list of tables at the begening of
    // your class
    Vector listOfTables = new Vector();
    try
    rs = yourConnection.getMetaData().getTables();
    while (rs.next())
    listOfTables.addElement(rs.getString(3));
    catch(SQLException exp)
    // When you need to test the existance of table name
    // you add this line
    if(listOfTables.contains(tableName))
    // your code
    The second one :
    try
    //execute your query
    catch
    //Create your default JTable
    I hope that my response can help you!
    Ciaou,
    Anis

  • How to  check whether any table(s) required to shrink on database

    Hi,
    How to check whether any table(s) required to shrink on database
    Regards,
    Venkat

    Venkat wrote:
    Hi,
    Thi is Oracle 10g. How to use this?. I am not using toad etc...
    I am on SQL prompt.
    Regards,
    Venkat.
    for starter
    Generate Script to Shrink Segment Advisor Recommendations [ID 1171054.1]
    Automatic Segment Advisor in Oracle 10g Release 2 (10.2) [ID 314112.1]
    10g and above SEGMENT ADVISOR [ID 242736.1]
    Cheers

  • How to check whether a file exist in the program folder or not?

    Hi guys,
    how to check whether a file exist in the program folder or not? Let is say i recieve a file name from user then i want to know if the file is there not and act on that base.
    abdul

    Look at the class java.io.File and the .exists() method:
    http://java.sun.com/j2se/1.4/docs/api/java/io/File.html

  • How to check whether portal user exists or not using UM API.

    Hi Experts,
    Let us say i need to create an user account "PortalUser",i know how to create an user,setting first name,lastname,password for that.
    but here before creating the portal user, i need to check whether that user exists or not.If user already exists ,then i  need to skip the below for creating the user.
    IUserFactory userFact = UMFactory.getUserFactory();
    IGroupFactory groupFact = UMFactory.getGroupFactory();
    IRoleFactory roleFact = UMFactory.getRoleFactory();
    IUser tuser = userFact.getUserByLogonID("PortalUser");
    IUserMaint newUser = userFact.newUser("PortalUser");
    newUser.setFirstName("PortalUser");
    newUser.setLastName("Test");
    newUser.setEmail("PortalUser.Testatgmaildotcom");
    //Locale PortalLanguage = new Locale(Lang.toLowerCase(), "");
    Locale PortalLang=new Locale("en");
    newUser.setLocale(PortalLang);
    newUser.save();
    newUser.commit();
    IUserAccount userAcc = UMFactory.getUserAccountFactory().newUserAccount("PortalUser", newUser.getUniqueID());
    userAcc.setPassword("test1test$");
    userAcc.save();
    userAcc.commit();     
    Thanks in advance.
    Thanks
    Sony.

    Hi,
    Try this code,
    IUserFactory factory = UMFactory.getUserFactory();
    IUser user = factory.getUserByLogonID(userId);
    lastName = user.getLastName();
    firstName = user.getFirstName();
    refer this pdf,its very helpful
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/events/webinars-nw-rig/using%20the%20user%20management%20api%20with%20ep%20applications%20-%20webinar%20powerpoint.pdf
    Regards,
    Sunaina Reddy T

  • How to check whether transport path exist between two systems in sld??

    Hi,
         I have two systems namely 'A' and 'B' and created business systems for both of them.Then i created transport path between the two systems.How i check whether what i have done is right in SLD.

    <b>WRT to CMS</b>
    am not sure with this but u can try:
    1. Start CMS: http://<host>:<J2EE Engine http port>/webdynpro/dispatcher/sap.com/tcSLCMS~WebUI/Cms.
    2. Goto lansdscape configurator and check there
    Message was edited by:
            Prabhu  S

  • How to check whether a Record Exists or not in Ztable

    Hi all,
    I have Req like this
    In ZTable i have 2 fields  * Legacy System , Legacy Material No*
    Environment Value is coming in one of the field in Idoc
    The logic is if the Environment Value is UK and a Record Exists on the ZTable for Legacy Sysyetm = Leg1 means i have send Legacy Material No , else  Send 01
    Please suggest me the process for this
    REgards
    Vamsi
    Edited by: Vamsi Krishna on May 19, 2009 5:31 PM

    Hi Michal / Aamir,
    Thanks for your replies.
    The ZTable is at R/3 side only, iam using RFC Lookup for this, but iam bit confuse on how to construct the logic to check whether there is a record Exists or not on Ztable
    Logic shld be If the Environment value is UK and a record exists on the Ztable for Legacy system "ABC" means then send Legacy material number else send 01
    In Table we will have the fields Legacy System   Legacy Material No  & Environment value is coming from Idoc itself( Ex: UK or US)
    Regards

  • How to check if internal table exists in dynamical called subroutine ?

    Hi,
    in a dynamically called subroutine i'm using a internal table, but in some calls this table is not exist.
    How can i check in the code whether the internal table exist or not ?
    regards,
    Hans

    In Horst Keller's blog /people/horst.keller/blog/2005/05/27/abap-geek-10--everything-functions-150-but-how my issue is talked about :
    All other parameters are handled in a way as they were declared as global data objects in the top include of the function group, that can be used only during the execution of the function module: They are visible throughout the function group but you can access them only while the function module is active. If you access such a parameter and the respective function module is not executed, you get the runtime error GETWA_NOT_ASSIGNED (Why? Well, technically thos guys are represented via field symbols which are valid only during the runtime of the function module).
    The code is in SD pricing. Sometimes the code is called from function module PRICING_BUILD_XKOMV or PRICING_SUBSCREEN_PBO where TKOMV is defined as globalized parameter.
    And sometimes it is called from function module PRCING_CHECK where TKOMV is NOT defined as parameter.
    In the call of last function the dump occures on the ASSIGN statement :
         data: ls_tkomv like line of tkomv,
                  lv_tablename(30) type c value 'TKOMV[]'.
        field-symbols: <lfs> type any table.
         assign (lv_tablename) to <lfs>.
         if <lfs> is assigned.
    Any suggestions to solve the issue ?
    regards,
    Hans

  • How to check whether a node exist in a Particular Level. (xmltype)

    hi,
    please help me to check whether a particular node exists in one level.
    for eg
    I have the following xml
    <map>
         <entry>
              <key>
                   heading1
                   </key>
              <map>
                   <entry>
                        <key> sub1 heading1</key>
                        <value> sub1 heading1 value  </value>
                   </entry>
                   <entry>
                        <key> sub2 heading1 </key>
                        <value> sub2 heading1 value  </value>
                   </entry>
              </map>
         </entry>
         <entry>
              <key>
                   heading2
                   </key>
              <map>
                   <entry>
                        <key> sub1 heading2</key>
                        <value> sub1 heading2 value  </value>
                   </entry>
                   <entry>
                        <key> sub2 heading2 </key>
                        <value> sub2 heading2 value  </value>
                   </entry>
              </map>
         </entry>
    </map>i need to check how many heading exists in this xml.
    I am checking like
            i:=1;
         l_section := ip_xml.extract('//map/entry');
         WHILE l_section.existsnode('entry[' || i|| ']') = 1 LOOP
              // extract the key name within entry tag
                  // print the key name.
    i:=i+1;
         end loop;but iam getting all the key name like
    heading1
    sub1 heading1
    sub2 heading1
    heading2
    sub1 heading2
    sub2 heading2
    I need only heading1 and heading2. how can I check whether a particular node exist in particular level.
    first level , second level etc. Please help

    but iam getting all the key nameThat's because you're using a descendant axis : //map/entry
    SQL> DECLARE
      2 
      3   ip_xml  xmltype := xmltype('<map>
      4       <entry>
      5            <key>
      6                 heading1
      7                 </key>
      8            <map>
      9                 <entry>
    10                      <key> sub1 heading1</key>
    11                      <value> sub1 heading1 value  </value>
    12                 </entry>
    13                 <entry>
    14                      <key> sub2 heading1 </key>
    15                      <value> sub2 heading1 value  </value>
    16                 </entry>
    17            </map>
    18       </entry>
    19       <entry>
    20            <key>
    21                 heading2
    22                 </key>
    23            <map>
    24                 <entry>
    25                      <key> sub1 heading2</key>
    26                      <value> sub1 heading2 value  </value>
    27                 </entry>
    28                 <entry>
    29                      <key> sub2 heading2 </key>
    30                      <value> sub2 heading2 value  </value>
    31                 </entry>
    32            </map>
    33       </entry>
    34  </map>');
    35 
    36  BEGIN
    37 
    38    for r in (
    39      select heading, headno
    40      from xmltable( '/map/entry/key'
    41                     passing ip_xml
    42                     columns heading varchar2(30) path '.'
    43                           , headno  for ordinality )
    44    )
    45    loop
    46      dbms_output.put_line('Heading '||r.headno||' = '||r.heading);
    47    end loop
    48    ;
    49 
    50  END;
    51  /
    Heading 1 =
                   heading1
    Heading 2 =
                   heading2
    PL/SQL procedure successfully completed

  • How to check if the table exists in teh database

    Hi,
    I am using MS Acess and how do i check using the query if the table already exist in the db?
    What is the exact query. Can any one help me.
    Thanks
    Deepti

    This will do it for you and print out the results using JDOM. - %
    package database;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.output.XMLOutputter;
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    public class TableLister
       public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
       public static final String DATABASE = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\Michael\\My Documents\\Projects\\Java\\Forum\\data\\DataConnection.mdb";
       public static final String USERNAME = "admin";
       public static final String PASSWORD = "";
       public static void main(String[] args)
          Connection conn = null;
          ResultSet tables = null;
          String driver = "";
          try
             driver = ((args.length > 0) ? args[0] : DRIVER);
             String url = ((args.length > 1) ? args[1] : DATABASE);
             String username = ((args.length > 2) ? args[2] : USERNAME);
             String password = ((args.length > 3) ? args[3] : PASSWORD);
             Class.forName(driver);
             conn = DriverManager.getConnection(url, username, password);
             DatabaseMetaData meta = conn.getMetaData();
             // Bring back ALL tables and views, including SYSTEM tables.
             tables = meta.getTables(null, null, null, null);
             ResultSetMetaData rsmd = tables.getMetaData();
             int numColumns = rsmd.getColumnCount();
             List columnNames = new ArrayList();
             for (int j = 0; j < numColumns; ++j)
                columnNames.add(rsmd.getColumnName(j + 1));
             Element root = new Element("tables");
             int tableCount = 0;
             while (tables.next())
                Element table = new Element("table");
                table.setAttribute("id", Integer.toString(++tableCount));
                for (int j = 0; j < numColumns; ++j)
                   Element column = new Element((String) columnNames.get(j));
                   column.setText(tables.getString((String) columnNames.get(j)));
                   table.addContent(column);
                root.addContent(table);
             conn.close();
             Document doc = new Document(root);
             XMLOutputter outputter = new XMLOutputter("   ", true);
             System.out.println(outputter.outputString(doc));
          catch (ClassNotFoundException e)
             System.err.println("Couldn't load JDBC driver class " + driver);
             e.printStackTrace();
          catch (SQLException e)
             System.err.println("SQL state: " + e.getSQLState());
             System.err.println("SQL error: " + e.getErrorCode());
             e.printStackTrace();
          catch (Exception e)
             e.printStackTrace();
          finally
             close(tables);
             close(conn);
       public static void close(Connection c)
          try
             if (c != null)
                c.close();
          catch (SQLException e)
             e.printStackTrace();
       public static void close(Statement stmt)
          try
             if (stmt != null)
                stmt.close();
          catch (SQLException e)
             e.printStackTrace();
       public static void close(ResultSet result)
          try
             if (result != null)
                result.close();
          catch (SQLException e)
             e.printStackTrace();
    }

  • How to Check whether a table is indexed or not?

    Hi all,
    I am writing a c++ program where i have to create an Index if Index not exists.
    Oracle 10.2 is the oracle version and i am using oracle text for indexing.
    table -- create table xmltable (versionnumber number,instance xmltype);
    index -- create index configindex on xmltable (instance) indextype is ctxsys.context;
    drop -- drop index configindex force;
    My algorithm should something like,
    if(configindex is exists)---------->What i have to write here to check if index is present.
    { drop index  configindex force; }
    create index configindex on xmltable (instance) indextype is ctxsys.context;
    Thanks......

    Hi,
    You could check the system view ALL_INDEXES .
    HTH,
    Chris

  • How to check whether a file exists or not

    i am in an image uploading utility. i hav succesfully uploaded the image to the server directory (say /uploads). but when displaying the uploaded image, i wanna show the picture only if the image exits (bcoz for some records there is no image). so i hav used this code
    if(new File("uploads/1.jpg").exists())
         out.print("image exists");
    but its not working for me. i got it working fine when i give the full path "D:/Tomcat/webapps/diary/admin/uploads/1.jpg". but i think giving this absolute path is not an efficient method bcoz its a web application, bcoz i may not be able get the absolute path always. so how can i do this by specifieing the relative path
    help me ASAP if u can
    aleens

    Haii ameen
    This is one way to rectify your problem..
    if(new File("uploads/1.jpg").exists())
    out.print("image exists");
    instead of this u can write like
    <%
    ServletConfig cf=getServletConfig();
    ServletContext c=cf.getServletContext();
    if(new File(c.getRealPath("uploads")+"/test.txt").exists())
    out.print("image exists");
    %>If u are not clear of what it is done let me know..i will xplain to you furthur...
    Happy New Year
    Shanu

  • How can I write a SQL statement which checks if a table exists?

    How can I write a SQL statement which tells me whether a table exists?

    execute an sql query: select * from <tablename>
    catch the exception n check whether the erroe code
    matches the one that occurs for table doesn't exist
    that's itHow is your answer any different from the one given in the first reply?
    It isn't.
    As WorkForFood says DatabaseMetaData has a bunch of methods for getting information about tables but this is more useful when you don't know the names of any of the tables.. it sounds like you do so I would concur SELECT from table is probably the quickest way to go. If it helps the Xopen error should be either S1000 or 42S01 (I think) but I would try and see if there is a specific vendor code for table not found/not exists error and check for that.

  • How to check whether follow on document is created for sc or po,is there any table or fm available?

    How to check whether follow on document is created for sc or po,is there any table or fm available?

    Hello Venu
    Check FM: BBP_PD_SC_GETDETAIL and BBP_PD_PO_GETDETAIL table E_HEADER_REL
    Check this: SRM Shopping cart and PO tables link
    Regards

  • How to check whether file exist or not?

    hello,
    i wanted to know that how can i check whether a file exist or not independent of underlying Operating system?
    please help .
    Thank you.

    Use exists() on a File instance.

Maybe you are looking for