Create table with timestamp
Hello All,
I am trying to create table within a procedure. All I am looking for is a way to create a table with timestamp (sysdate) appended to the table name.
Below is my attempt of doing so. Can you please help me out?
CREATE OR REPLACE PROCEDURE CREATE_TABLE1 AS
V_SYSDATE VARCHAR2(20);
V_TABLENAME VARCHAR2(40);
BEGIN
SELECT TRUNC(SYSDATE) into V_SYSDATE FROM DUAL;
SELECT CONCAT('ORDERS_BACKUP_',V_SYSDATE) into V_TABLENAME FROM DUAL;
EXECUTE IMMEDIATE 'CREATE TABLE ''||V_TABLENAME||'' as SELECT * from ORDERS
END;
Thanks,
TT
Despite also having concerns about your approach, maybe this is what you were looking for...
CREATE OR REPLACE PROCEDURE CREATE_TABLE1 AS
V_SYSDATE VARCHAR2(20);
V_TABLENAME VARCHAR2(40);
BEGIN
SELECT TO_CHAR(TRUNC(SYSDATE),'DDMMYYYY') into V_SYSDATE FROM DUAL;
SELECT CONCAT('ORDERS_BACKUP_',V_SYSDATE) into V_TABLENAME FROM DUAL;
EXECUTE IMMEDIATE 'CREATE TABLE '||V_TABLENAME||' as SELECT * from ORDERS';
END;Greg Pike
http://www.singlequery.com
Similar Messages
-
OID users ( EUS) problem with grant create table with admin
Hi,
We activated enterprise users in the OID.
There is a role APP_ADMIN that has the following grants:
create user
drop user
create table with admin option
this is for an application that creates BI schemas, so it needs to be able to create other users.
I have granted these to a local role, and the user has access to the local role, thanks to the OID setup.
The create and drop user work.
however, the grant create table to another user does not work.
Is there an issue with 'with admin option' grants in Enterprise user security?
Regards,
PeterIf I grant
grant create table to test_role with admin option;
it does not work
if I grant
GRANT GRANT ANY PRIVILEGE to test_role WITH ADMIN OPTION;
it does work.
The test command as user with test_role is:
grant create table to test_usr;
very strange!
If the user is a standard user and I create role test_role
and grant create table to test_role with admin option it works.
but if I convert the user to an EUS user and the same privilege is given to the role ( role is granted to a global role to an enterprise role)
it doesnt work
Edited by: Peter on Dec 7, 2012 2:36 PM -
Unable to create table with column default value with date interval
Please help to create table with calculated date defaullt value:
CREATE TABLE emp (
birth_date DATE DEFAULT sysdate + interval '3' day NOT NULL
or
CREATE TABLE emp (
some_date DATE,
birth_date DATE DEFAULT some_date NOT NULL
or
CREATE TABLE emp (
some_date DATE,
birth_date DATE DEFAULT some_date + interval '3' day NOT NULL
below syntax error:
TT1001: Syntax error in SQL statement before or at: "+"I'm afraid this is not possible; as per the SQL Reference, TimesTen only supports 'constant expressions' for the DEFAULT clause and none of these are constant expressions.
Chris -
Problem CREATE TABLE with PRIMARY KEY Still in Trouble ! Please Help!
Hi there !
I use the orcle 8i, and i don't know why i can't create table with any primary key EXample:
SQL> CREATE TABLE O_caisses
2 (No_caisse NUMBER(3) constraint caisses_pk PRIMARY KEY,
3 NB_BILLETS NUMBER(5)
4 )
5 /
CREATE TABLE O_caisses
ERROR at line 1:
ORA-18008: cannot find OUTLN schema
***********some Debuger show me this way: *********************
Well there r certain point u got to notice when creating a table with constraints.
1) U can create table with COLUMN level constraint.
2) U can create table with TABLE level constraint.
3) In COLUMN level constraint u can't give a constraint a name
but only mention the type of constraint.
4) In TABLE level constraint u can give a name to constraint.
Following are the examples of both
--COLUMN LEVEL
CREATE TABLE O_caisses
(No_caisse NUMBER(3) PRIMARY KEY,
NB_BILLETS NUMBER(5));
--TABLE LEVEL
CREATE TABLE O_caisses
(No_caisse NUMBER(3),
NB_BILLETS NUMBER(5),
constraint pk_caisse primary key (No_caisse));
********************And this is another one:*****************
SQL>grant create any outline to username;
BUT the problem is still present, i don't know what to do now !
Please could some body help me !
Thanks alot!
Luong.The clue is in the error message: the OUTLN schema is missing.
This is something Oracle 8i introduced to help manage the CBO (or soemthing equally geeky and internal). For some reason your database no longer has this user. It ought to be created automatically during installation (or upgrade) but catproct may not have completed probably or some over zealous admin type has dropped it.
Solution is to re-install (or re-upgrade) as you cannot create this user on their own. Alas.
HTH, APC -
How to create table with dynamic rows
Hi Ppl,
I have an array lets say with length of n. I want to creata table with 2 columns and no of rows = array length.
lets say array length is 3 ( array[0] = 1, array[1] = 2, array[2] = 3) so the table should have 2 columns and 3 rows.
After creation of table I want to display each array value in each row.
Can somebody help me in this asap.
Thanks \
AshishHi, Thanks for reply... actually this is one part of rtf. I have put values from xml to an array and now I want to create a table with no of rows = length of array. so here xml will not be useful. could you pls think of it without xml.
result is like
lets says below is the array
array[0] = a
array[1] = b
array[2] = c
array length = 3
so there should be a table of 2 coulmns and 3 rows. Second column of first row will show 'a', Second column of second row wil show 'b' and Second column of third row will show 'c'.
Hope this is useful.
Thakns
Ashish -
How to create table with table description
Hi,
I would like create table with table description(like creating package or procedure with comments).
Is it possible to achieve through oracle, if possible please help me how to achieve this.
Thanks and regards,
Ibrahim Sayyed.> create table test (col1 number);
> comment on table test is 'this is a comment';
> select comments from user_tab_comments where table_name = 'TEST';
COMMENTS
this is a comment -
How to create table with row type in smart forms
How to create table with row type in smart forms with out line type
please explain me the procedureHI,
A table type describes the structure and functional attributes of an internal table in ABAP. In ABAP programs you can reference a table type TTYP defined in the ABAP Dictionary with the command DATA <inttab> TYPE TTYP. An internal table <inttab> is created in the program with the attributes defined for TTYP in the ABAP Dictionary.
A table type is defined by:
its line type, that defines the structure and data type attributes of a line of the internal table
the options for managing and accessing the data ( access mode) in the internal table
the key ( key definition and key category) of the internal table
The row type is defined by directly entering the data type, length and number of decimal places or by referencing a data element, structured type ( structure, table or view) or other table type. Or the row type can be a reference type.
<b>for more info :</b> http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm
Internal table
Regards
Sudheer -
How to create table with resizable row ?
how to create table with resizable row ?
I'd suggest you start here:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html -
Problem on CREATING TABLES with PRIMARY KEY
Hi there !
I use the orcle 8i, and i don't know why i can't create table with any primary key EXample:
SQL> CREATE TABLE O_caisses
2 (No_caisse NUMBER(3) constraint caisses_pk PRIMARY KEY,
3 NB_BILLETS NUMBER(5)
4 )
5 /
CREATE TABLE O_caisses
ERROR at line 1:
ORA-18008: cannot find OUTLN schema
Please could some body help me !
Thanks alot!
Luong.Luong,
Your syntax is fine. It looks like you don't have the correct database privileges to create the table. The error message you're getting suggests that you don't have CREATE ANY OUTLINE privileges. You should log in as a user than can grant these privileges and give yourself the correct privileges. I think the syntax is
SQL>grant create any outline to username;
Alison -
How i can create table with data
How i can create table with data from dev to production?
How i can create table with data
[url=http://en.wikipedia.org/wiki/Black_Beast_of_Aa
aaarrrrrrggghhh]from dev to production?
[url=http://img2.travelblog.org/Photos/3800/14977/t
/64816-Col-Kurtz-0.jpg]The horror, the
horror.lol, you gonna scare somebody here.
Are we helping devil? -
Create table with variables enviroment
Hi all,
I would create a table by a schedule procedure when an event occurs.
Can I create a table with these or similar syntax:
create table acme_%s_%t as select * from a;
I would use this syntax because this event could happen more time a day and so I can check.
is it possible?
Thanx a lot
Ciao
AlbertoAlbertofro wrote:
Hi all,
I would create a table by a schedule procedure when an event occurs.
Can I create a table with these or similar syntax:
create table acme_%s_%t as select * from a;
I would use this syntax because this event could happen more time a day and so I can check.
is it possible?
Thanx a lot
Ciao
AlbertoTo create a table dynamically you need to use EXECUTE IMMEDIATE. If you want your table name to be padded with timestamp you can do it with TO_CHAR and SYSDATE functions.
An example
execute immediate 'create table acme_' || to_char(sysdate, 'DDMMYYYYHH24MISS') || ' as select * from a'; -
Creating table with null and not null values.
I have to create a table with 5 Null nd 5 Not Null fields.My questionis which fields are place first?Not or Not Null and why???
What you mean is: the person who asked you the question thought the order of columns was important, and wanted to see if you agreed. Or maybe they were just asking the question to see whether you thought it was important (as a test of your understanding of the database).
When I started out in Oracle I was told that it was good practice to have the mandatory columns first and then the optional columns. But if you do some research you find this: the impact of column ordering on space management is: empty nullable columns at the end of the table take up zero bytes whereas empty nullable columns at the middle of the table take up one byte each. I think if that saving really is important to you you need to spring for an additional hard drive.
Besides, even if you do organise your columns as you suggest, what happens when you add an eleventh NOT NULL column to your table? It gets tacked on to the end of your table. Your whole neat organisation is blown.
What does still matter is the positioning of large VARCHAR2 columns: they should be the last columns on your table in case they create chaining. Then any query that doesn't need the large columns can be satisfied without reading the chained block, something that can't be guaranteed if you've got columns after a VARCHAR2(4000) column. This doesn't apply to CLOBs, etc. which are stored separately anyway.
Cheers, APC -
Error while creating table with clusters
Hi
I tried the following
CREATE CLUSTER emp_dept (deptno NUMBER(3))Cluster is created
Then i tried to create the table having the above cluster but giving the errors:
create table emp10 (ename char(5),deptno number(2) )cluster emp_dept(deptno);The error is:
ORA-01753 column definition incompatible with clustered column definitionCould you please help me in thisYour cluster is based on a NUMBER(3) data type while the emp10 table has a deptno column with a data type of NUMBER(2).
-
Error ORA-01426: numeric overflow when Creating table with double data type
Hi,
I am using ODP.NET to create a table with data from SQL to Oracle. The problem is with double data type fields that is equivalent to FLOAT(49) in Oracle. My syntax is:
CREATE TABLE SCOTT.ALLTYPES
F1 NUMBER(10),
F10 DATE,
F2 NUMBER(10),
F3 NUMBER(5),
F4 NUMBER(3),
F5 FLOAT(23),
F6 FLOAT(49),
F7 NUMBER (38,5),
F8 NVARCHAR2(500),
F9 NVARCHAR2(500)
Th error is with field F6 but I am not sure what is the correct type equivalent to double in SQL.
I woul appreciate if anyone can help me with this problem.
SunnyDoes this simple test work for you?
In database:
create table float_test
f1 float(49)
);C# code:
using System;
using System.Data;
using System.Text;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
namespace FloatTest
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
// connect to local db using o/s authenticated account
OracleConnection con = new OracleConnection("User Id=/");
con.Open();
// will hold the value to insert
StringBuilder sbValue = new StringBuilder();
// create a string of 49 number 9's
for (int i = 0; i < 49; i++)
sbValue.Append("9");
// command object to perform the insert
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "insert into float_test values (:1)";
// bind variable for the value to be inserted
OracleParameter p_value = new OracleParameter();
p_value.OracleDbType = OracleDbType.Double;
p_value.Value = Convert.ToDouble(sbValue.ToString());
// add parameter to collection
cmd.Parameters.Add(p_value);
// execute the insert operation
cmd.ExecuteNonQuery();
// clean up
p_value.Dispose();
cmd.Dispose();
con.Dispose();
}SQL*Plus after executing above code:
SQL> select * from float_test;
F1
1.0000E+49
1 row selected.- Mark -
Create table with name already existed
Hello,
I am trying to create a table which has the same table name that already exists in a different schema. The table already exist in another user's schema but why can't I create the same table in my own schema with the same name? Thank you.Check this out.
SQL> create user testuser1 identified by testuser1 default tablespace user01;
User created.
SQL> create user testuser2 identified by testuser2 default tablespace user01;
User created.
SQL> grant create session, create table, create public synonym,
2 unlimited tablespace to testuser1;
Grant succeeded.
SQL> grant create session, create table, create public synonym,
2 unlimited tablespace to testuser2;
Grant succeeded.
SQL> connect testuser1/testuser1
Connected.
SQL> create table mytable(col1 number);
Table created.
SQL> create public synonym mytable for testuser1.mytable;
Synonym created.
SQL> grant select on mytable to public;
Grant succeeded.
SQL> connect testuser2/testuser2
Connected.
SQL> create table mytable(col1 number);
Table created.
SQL> drop table mytable;
Table dropped.
SQL> desc mytable
Name Null? Type
COL1 NUMBER
SQL> desc testuser1.mytable
Name Null? Type
COL1 NUMBER
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.3.0 - Production
Maybe you are looking for
-
Computer restarts when ipod is plugged in
Hey! I just bought new 30g video ipod but now when i plug it in to my PC, blue screen appears and PC crashes. I have tried to reinstall all ipod software, format my pc and tried different USB ports and none of these worked. Here's some blue screen me
-
My interest for this server it would be to have the same function as MobileMe but without it. Best regards. Camille
-
How to send the XML format SOAP request to retrieve the Opportunity
Hello, Can any body suggest me how to send the SOAP request to CRM OnDemand in the format of XML to retrieve the Opportunity ?. Thanks, --bdr_09
-
HT204655 Can you use the new photos library for iPhoto to save space
I want to use the same library for photos and iPhoto because that way it will use a fraction of the space. Is that possible.
-
Install of Citadel 5 database engine
Hello, I have just purchased DIAdem Advanced and wish to connect to a Citadel 5 database (developed by a 3rd party) on our LAN to view and analyse data. When I tried configuring a new data store in the Navigator section of DIAdem, I got an error mess