About ORACLE timed to create a database table (reproduced)

Step 1: Create a creation of the stored procedure execution 
problems to be solved in this first step is to build the table name. In Oracle format, then the output time may be treated with to_char function, for example: 
the SQL> SELECT to_char (SYSDATE, 'YYYY / mm / dd HH24: mi The: SS') from Dual; 
the TO_CHAR (SYSDATE, 'YYYY / the MM / DDHH2 
- ----------------------------- 
2009/02/14 17:22:41 
more SQL format output time, to get us format required to directly modify SQL 
SQL> SELECT TO_CHAR (SYSDATE, 'YYYYMMDD') from Dual; 
the TO_CHAR (SYSDATE, 'YYYYMMDD') 
------------------ --------- 
20,090,214 
after we get the time format string prefix and the time table can be joined together to form the complete name of the table name. 
  it should be noted that the link requires two strings in Oracle ' || 'symbol, and used directly in the Sql Server in the' + 'sign on it, because I've been programming before Sql Server, Oracle's SQL for a long time did not write so spent a lot of effort to find the problem. complete the Sql is the SQL> SELECT 'tbl_programme_' || TO_CHAR (SYSDATE, 'YYYYMMDD') from Dual; 'TBL_PROGRAMME_' || the TO_CHAR (SYSD ------------------------------ Execute immediate 'Create Table' || || tabname 'TABLESPACE P2P AS SELECT * WHERE from tbl_programme =. 1. 1!'; tbl_programme_20090214 next step is to create a code table, because the new table needs tbl_programme consistent, so direct CTAS to create a table that is ideally suited to the code is as follows: the Create the Table TableName AS the SELECT * from tbl_programme If you need to specify a TableSpace then the SQL make the appropriate changes: the create the Table TableName TABLESPACE P2P AS the SELECT * from tbl_programme so the entire SQL to create stored procedures is the create or the replace procedure sp_createtab_tbl_programme AUTHID CURRENT_USER AS tabname VARCHAR (200); the begin the SELECT 'TBL_PROGRAMME_' || the TO_CHAR (sysdate, 'YYYYMMDD ') INTO tabname from Dual; ! --create the Table tabname from tbl_programme the wHERE AS the SELECT * 1 = 1; the commit; End; / there is also need to look at two ways in which Oracle If you want to assign values to variables, then: (1 ) using the: = assignment (2) select 'xjkxj' into the variable name from tabname After addition, the definition of the variables stored in the course of time is generally placed as / is begin earlier.
  Generally can not be used directly create table in a stored procedure, truncate table which is similar to the statement, if you want to use these statements must excute immediate + sql statement to be executed to achieve. Note that the above statement with the red flag: Authid Current_User This statement is more important, if we do not add this statement to create a stored procedure performed when the stored procedure will not succeed, because the default is not to stored procedures, etc. Create table privilege even if the current user has DBA privileges does not work, if the operation creates a table there is a stored procedure, you can have two ways to solve this problem.
   (1) gives the user display Create table of permissions, grant create table to user. (2) using the stored identification Authid Current_User process permissions of the current user. Step 2: Create JOB create JOB relatively simple, the following code is to create JOB every night 1 electrical job start time, perform sp_createtab_tbl_programme stored procedure.
   Number The testjobid the VARIABLE; the commit; End; the begin sys. dbms_job. submit (: testjobid, 'sp_createtab_tbl_programme;', the trunc (SYSDATE +. 1) +. 1/24, 'the trunc (SYSDATE +. 1) +1/24'); / It should be noted that the job must first define the variable submit preceding method, further, the second parameter is the name of the method submit a stored procedure, added after remember ":" No, at a time next_date type variable rather than a string, you need to be careful not to regard it as a string, this argument does not require quotation marks.
  The last parameter interval is a string type, remember to add quotation marks. The most common error shown below: ORA-01008: All the Variables not bound variable is not defined meaning. Certain definitions in mind when using the variable jobid submit method.

Guess you like

Origin www.cnblogs.com/yfssss/p/11571536.html