How to SELECT * into a SQL table incremntally by date?

I have a SQL Server table called "tblProducts".
Sometimes I backup this table by making a copy of it with this simple query:
SELECT *
INTO [test01].[dbo].[tblProducts_20141206]
FROM [test01].[dbo].[tblProducts]
Every time when making a backup, the date is included in the table name.
I would like to create a SQL Job that runs this kind of query once every week.
Is it possible to maybe in a stored procedure or declaring a variable to achieve this that allows the backed-up table name to be named like [tblProducts_todaysDate]?
Thanks.

hi ,dchencm
i just want to point out the some bad effect of this pratice
first point is
when your db has be corrupt,your backup out of work
i think you should backup your table to other db ensure that when your db has be corrupt you still have real backup
just like
SELECT *
INTO [test01_backup].[dbo].[tblProducts_20141206]
FROM [test01].[dbo].[tblProducts]
another point is your pratice is total amount of backup not  incremental backup
when your table  become bigger and bigger ,and then the number of record reach several million or several ten million or several hundred million, you must import all  data the table have
so, this is not a good idea
i just suggest  apply replication or logshipping etc to copy the diff data the table proceded is the better
 the steps of detail  as following
step 1
USE [test01]
GO
/****** 对象: StoredProcedure [dbo].[sp_ImportBackupData] 脚本日期: 12/25/2010 16:47:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_importbackupdata]
AS
BEGIN
BEGIN
DECLARE @date DATETIME ,
@sql VARCHAR(1000)
SET @date = GETDATE()
SET @sql = 'SELECT * INTO [test01].[dbo].[tblProducts_'
+ CONVERT(VARCHAR(8), @date, 112)
+ '] FROM [test01].[dbo].[tblProducts]'
EXEC (@Sql)
END
END
step 2
USE [msdb]
GO
/****** 对象: Job [import data] 脚本日期: 02/22/2011 09:22:44 ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** 对象: JobCategory [Database Engine Tuning Advisor] 脚本日期: 02/22/2011 09:22:44 ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Engine Tuning Advisor' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Engine Tuning Advisor'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'sp_importbackupdata',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'sp_importbackupdata',
@category_name=N'Database Engine Tuning Advisor',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** 对象: Step [import data] 脚本日期: 02/22/2011 09:22:44 ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'import data',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'exec sp_importbackupdata',
@database_name=N'sss',
@flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'import frequency',
@enabled=1,
@freq_type=8,
@freq_interval=2,
@freq_subday_type=1,
@freq_recurrence_factor=1,
@active_start_time=20000
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
the schedule time is 2 am  in the midnight  every monday 
Certainly, you can edit it for yourself

Similar Messages

  • Select in PL/SQL tables ?

    Hi,
    I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
    in SQL query when i used UNION ALL or DISTINCT Operators.
    The second Question is How can show(Retrieve query) only one element in SQL
    SUCH AS
    SELECT ID from PL/SQL Table Name;
    Create or replace PACKAGE Test1 IS
    type REC_DB is RECORD
    (id number(9), name varchar2(50));
    type TB_DATA IS table of REC_DB;
    function get_coll return TB_DATA pipelined;
    temp_TB_DATA TB_DATA := TB_DATA();
    type CV_TEST is REF CURSOR return REC_DB ;
    end;
    Package created.
    Create or replace PACKAGE body TEST1 IS
    function get_coll return TB_DATA pipelined
    is
    begin
    for i in 1..temp_TB_DATA.count loop
    pipe row(temp_TB_DATA (i));
    end loop;
    return;
    end;
    end;
    Package body created.
    declare
    temp_cv TEST1.CV_TEST ;
    rc TEST1.REC_DB ;
    a number(9);
    begin
    TEST1.temp_TB_DATA.delete;
    TEST1.temp_TB_DATA.extend;
    TEST1.temp_TB_DATA(1).id:=1;
    TEST1.temp_TB_DATA(1).name:='SITI';
    TEST1.temp_TB_DATA(1).id:=2;
    TEST1.temp_TB_DATA(1).name:='OMAR';
    TEST1.temp_TB_DATA(1).id:=3;
    TEST1.temp_TB_DATA(1).name:='ALI';
    TEST1.temp_TB_DATA(1).id:=4;
    TEST1.temp_TB_DATA(1).name:='DAID';
    TEST1.temp_TB_DATA(1).id:=1;
    TEST1.temp_TB_DATA(1).name:='SITI';
    TEST1.temp_TB_DATA(1).id:=2;
    TEST1.temp_TB_DATA(1).name:='OMAR';
    -- erroring out
    open temp_cv for select * from table(TEST1.get_coll);
    fetch temp_cv into rc;
    dbms_output.put_line('Deptno is ' || rc.id);
    dbms_output.put_line('ename is ' || rc.name);
    end;
    regards

    Ayham wrote:
    I have create PL/SQL Table , i want to know how can i remove the redundancy of data as
    in SQL query when i used UNION ALL or DISTINCT Operators.Repeat. There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table". There is no such thing as a PL/SQL "table".
    The data structure is called an array. A table in Oracle has a very specific meaning. It is a hash or index table. Can be partitioned. Clustered. Indexed. Etc.
    A PL/SQL array is NOTHING at all like a table.
    The second Question is How can show(Retrieve query) only one element in SQL
    SUCH AS
    SELECT ID from PL/SQL Table Name;And this is almost always WRONG. As you are sending (a potentially large) array that resides in PL/SQL memory as a bind variable to the SQL engine, in order for the array's contents to be processed. Why?
    Why not simply use a (proper SQL) table and not array? A table that can be indexed. That was made for running SQL against? That can take billions of rows without exhausting server memory.
    If you are using SQL against a PL/SQL array, you are basically saying "+I have made the wrong choice for processing this data+". Yes, there are exceptions to this. But exceptions are just that - exceptions.
    So why are you using a PL/SQL array? Why do you need to use SQL against it and duplicate the array's contents as bind values? Why does SET operations in PL/SQL not suffice?

  • Select * into Table1 from Table not working

    Hi,
    How to copy data from one table to other new table using select * into statement.
    I am getting missing keyword error when I use the statement
    select * into Table1 from Table
    Thanks a lot in advance.
    Regards,
    Praveen

    the syntax is
    INSERT INTO table1 SELECT * FROM table2;

  • Can you SELECT INTO a temporary table?

    I was wondering if you can do this and what the syntax would be. I tried to SELECT INTO GLOBAL TEMPORARY TABLE and it didn't work.

    If you are looking to Create a GTT, load data into it and then be able to select from the GTT after createion, you'll need to remember to preserve the rows after a commit e.g.:
    create global temporary table gtemp on commit preserve rows as select * from tab;
    However, your question is a bit on the vague side as to EXACTLY what you are wanting to do.
    As an addendum
    It didn't work is a completely useless statement without telling us how you know it didn't work
    Message was edited by:
    JS1

  • How to join two pl/sql tables .,.,,Urgent pls help

    Hi,
    Please tell me how to join to pl/sql tables with example
    thanks
    asp

    If your main intention is to get the common records/or getting whole records from the 2 different pl/sql arrays then , pls check this piece of code & explanation
    The SQL language has long offered the ability to apply set operations (UNION, INTERSECT, and MINUS) to the result sets of queries. In Oracle Database 10g, you can now use those same high-level, very powerful operators against nested tables (and only nested tables) in your PL/SQL programs and on nested tables declared as columns inside relational tables.
    Let's take a look at some of the syntax needed to do this, starting with UNION.
    First, I create a schema-level nested table type:
    CREATE OR REPLACE TYPE strings_nt
    IS TABLE OF VARCHAR2(100);
    Then I define a package and within it create and populate two nested tables of this type, each containing some of my father's and my favorite things:
    CREATE OR REPLACE PACKAGE favorites_pkg
    IS
    my_favorites strings_nt
    := strings_nt ('CHOCOLATE'
    , 'BRUSSEL SPROUTS'
    , 'SPIDER ROLL'
    dad_favorites strings_nt
    := strings_nt ('PICKLED HERRING
    , 'POTATOES'
    , 'PASTRAMI'
    , 'CHOCOLATE'
    PROCEDURE show_favorites (
    title_in IN VARCHAR2
    , favs_in IN strings_nt
    END;
    In this package, I also include a procedure to show the contents of a strings_nt nested table. This will come in very handy shortly.
    By defining these collections in a package, outside any program, they persist (they maintain their state and values) for the duration of my session or until I change or delete them. This means that I can now write programs outside the package to manipulate the contents of those collections.
    Note that this package has been simplified for the purposes of presenting collection functionality. In a production application, you should always take care to "hide" your package data, as with these collections, in the package body, and then provide procedures and functions to manage the data.
    Suppose, for example, that I would like to combine these two collections into a single collection of our favorites. Prior to Oracle Database 10g, I would have to write a loop that transfers the contents of one collection to another. Now, I can rely on the MULTISET UNION operator, as shown below:
    DECLARE
    our_favorites
    strings_nt := strings_nt ();
    BEGIN
    our_favorites :=
    favorites_pkg.my_favorites
    MULTISET UNION ---- Use INTERSECT , if you want to know common records
    favorites_pkg.dad_favorites;
    favorites_pkg.show_favorites (
    'ME then DAD', our_favorites);
    END;
    The output from this script is:
    ME then DAD
    1 = CHOCOLATE
    2 = BRUSSEL SPROUTS
    3 = SPIDER ROLL
    4 = PICKLED HERRING
    5 = POTATOES
    6 = PASTRAMI
    7 = CHOCOLATE
    ------------------------------

  • Select into from 2 tables

    Thanks in advance
    Is it possible do a SELECT INTO from 2 tables, that is (like in Informix)
    declare
    rg_table1    table1%ROWTYPE;
    rg_table2    table2%ROWTYPE;
    BEGIN
                 SELECT A.*, B.* INTO  rg_table1 , rg_table2                           
                       FROM table1 a, table2 B
                            WHERE ....

    no, I don't think so....
    SQL> declare
      2     t1 t%rowtype;
      3     s1 s%rowtype;
      4  begin
      5     select t.*
      6          , s.*
      7       into t1
      8          , s1
      9    from t, s
    10    where rownum = 1;
    11  end;
    12  /
       select t.*
    ERROR at line 5:
    ORA-06550: line 5, column 4:
    PLS-00494: coercion into multiple record targets not supported
    ORA-06550: line 9, column 3:
    PL/SQL: ORA-00904: : invalid identifier
    ORA-06550: line 5, column 4:
    PL/SQL: SQL Statement ignored

  • How can I read a file with ASCII Special Character into a SQL table using SSIS 2008?

    I've tried everything to read this file and am getting no where.   Help how can I read this file and load a SQL table?
    RS - AscII - 30  (Record Separator)
    GS - AscII - 29 (Group Separator)
    Thank you for your assistance - Covi
    Mark Covian

    We can use script component as source/transformation to read the text file and assign the contains to a string. Split the string by chr(30)  i.e RS and finally stored into an array or write to the output buffer of the script component.
    For example on how to use script component refer this link
    http://social.technet.microsoft.com/Forums/en-US/6ff2007d-d246-4107-b77c-624781baab38/how-to-use-substring-in-derived-column-in-ssis?forum=sqlintegrationservices
    Regards, RSingh

  • How to loop through Multiple Excel sheets and load them into a SQL Table?

    Hi ,
    I am having 1 excel sheet with 3 worksheet.
    I have configured using For each loop container and ADO.net rowset enumerator.
    Every thing is fine, but after running my package I am getting below error
    [Excel Source [1]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009.  There may
    be error messages posted before this with more information on why the AcquireConnection method call failed.
    Warning: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED.  The Execution method succeeded, but the number of errors raised (5) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified
    in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
    [Connection manager "Excel Connection Manager"] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
    An OLE DB record is available.  Source: "Microsoft Access Database Engine"  Hresult: 0x80004005  Description: "The Microsoft Access database engine cannot open or write to the file ''. It is already opened exclusively by
    another user, or you need permission to view and write its data.".
    Pleas suggest me the correct way of solving above issues.
    Thanks in advance :)
    regards,
    Vipin jha
    Thankx & regards, Vipin jha MCP

    Hi ,
    Please refer the below link for Looping multiple worksheet in a single SQL Table.
    http://www.singhvikash.in/2012/11/ssis-how-to-loop-through-multiple-excel.html
    Note:-If you using excel 2010 then you have to use EXCEL 12.0 .
    Above link explaining  step by step of Looping multiple worksheet in a single SQL Table.
    regards,
    Vipin jha
    Thankx & regards, Vipin jha MCP

  • JSP + MYSQL question: input form value into a SQL table

    Hello,
    I am writing some JSP code to read input information from a input form to write this information into a SQL field.
    My problems are:
    - how can i pass the input form information to other jsp file ? (like Getproperty of something like this)
    - how can i move the content of any input information into a variable ? I mean something like this:
    String a1;
    username.value.of.the.input.field.in.forum_jsp = a1.in.addmessage_jsp;and then:
    int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " +  " usercode, " + " messagedate,  " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");------
    The SQL table looks like this:
    stmt.executeUpdate("CREATE TABLE forummessages (messagecode int AUTO_INCREMENT PRIMARY KEY, usercode int, messagedate date, message char(255) not null)");My codes are:
    forum.jsp - this one should pass the input information to addmessage.jsp
    <%@ page contentType="text/html; charset=iso-8859-2" %>
    <%@ page import="java.sql.*" %>
    <%
    Connection con = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String url =  "jdbc:mysql://localhost:3306/mysql";
      con =  DriverManager.getConnection(url,"root", "");
      stmt = con.createStatement();
      String sql = "SELECT * FROM forummessages,users,bmwecode WHERE (forummessages.usercode=users.usercode) AND (users.bmwcode=bmwecode.bmwcode)";
      ResultSet rs = stmt.executeQuery(sql);
    %>
    <html>
    <head>
    <title>JSP + MYSQL Teszt</title>
    </head>
    <body>
    <a href="forum.jsp">Forum / Uj hozzaszolas</a>
    <a href="userlist.jsp">Felhasznalok kilistazasa</a>
    <a href="adduser.jsp">Felhasznalo hozzadasa</a>
    <a href="deletemessage.jsp">Hozzaszolas torlese</a>
    <br><br>
    <form action="addmessage.jsp" method=post">
    Felhasznalo:
    <input type="text" name="username">
    <br><br>
    Hozzaszolas:
    <input type="text" name="message">
    <br><br>
    <input type="submit" value="Uj hozzaszolas">
    <br><br>
    <table border="0">
    <tr>
    <th>messagecode</th>
    <th>user</th>
    <th>car type</th>
    <th>message</th>
    </tr>
    <%
      while(rs.next()){
    %>
    <tr>
    <td><%=rs.getInt("messagecode") %></td>
    <td><%=rs.getString("username") %></td>
    <td><%=rs.getString("bmwtype") %></td>
    <td><%=rs.getString("message") %></td>
    </tr>
    <%
      } // end while
    %>
    </table>
    </body>
    </html>
    <%
    } catch (Exception e) {
      out.println("<font color=red><h3>Error:</h3></font>" + e);
      e.printStackTrace();
    } finally {
      try {
        if (stmt!=null) {
          stmt.close();
        if (con!=null) {
          con.close();
      } catch (Exception e) {
        e.printStackTrace();
    %> ----
    addmessage.jsp
    <%@ page contentType="text/html; charset=iso-8859-2" %>
    <%@ page import="java.sql.*" %>
    <%
    Connection con = null;
    Statement stmt = null;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      String url =  "jdbc:mysql://localhost:3306/mysql";
      con =  DriverManager.getConnection(url,"root", "");
      stmt = con.createStatement();
    int rowsAffected = stmt.executeUpdate("INSERT INTO forummessages (messagecode, " +  " usercode, " + " messagedate,  " + " message) VALUES(6,3,06/07/2007,'" + a1 + "')");
    } catch (Exception e) {
      out.println("<font color=red><h3>Hiba:</h3></font>" + e);
      e.printStackTrace();
    } finally {
      try {
        if (stmt!=null) {
          stmt.close();
        if (con!=null) {
          con.close();
      } catch (Exception e) {
        e.printStackTrace();
    %>
    <a href="forum.jsp">Forum / Uj hozzaszolas</a>
    <a href="userlist.jsp">Felhasznalok kilistazasa</a>
    <a href="adduser.jsp">Felhasznalo hozzadasa</a>
    <a href="deletemessage.jsp">Hozzaszolas torlese</a>
    <br><br>---
    Thank you for your help in advance.

    SELECT DISTINCT
    hou.name
    ,poh.segment1 po_num
    ,pol.line_num po_line_num
    ,poh.currency_code
    --,trunc(poh.creation_date) po_creation_date
    ,pol.cancel_flag
    ,msi.segment1 item_num
    ,pol.unit_price
    ,round(cost.item_cost,5)
    ,round((&p_rate * pol.unit_price),5) "CONVERSION"
    ,(cost.item_cost - round((&p_rate * pol.unit_price),5)) difference
    ,pov.vendor_name
    FROM
    po.po_headers_all poh
    ,po.po_lines_all pol
    ,po.po_vendors pov
    ,hr.hr_all_organization_units hou
    ,inv.mtl_system_items_b msi
    ,bom.cst_item_costs cost
    WHERE
    poh.po_header_id = pol.po_header_id
    and pov.vendor_id = poh.vendor_id
    and poh.org_id = hou.organization_id
    and hou.organization_id = :p_operating_unit
    and poh.currency_code = :p_currency
    and poh.creation_date between :po_creation_date_from and :po_creation_date_to
    and poh.type_lookup_code = 'BLANKET'
    and msi.inventory_item_id = pol.item_id
    and cost.INVENTORY_ITEM_ID = pol.ITEM_ID
    --and (cost.item_cost - pol.unit_price) <> 0
    and (cost.item_cost - round((&p_rate * pol.unit_price),5)) <> 0
    and cost.organization_id = 1
    and msi.organization_id = 1
    and cost.cost_type_id = 3 --- Pending cost type
    and nvl(upper (pol.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
    and nvl(upper (poh.closed_code),'OPEN') not in('CANCELLED', 'CLOSED', 'FINALLY CLOSED', 'REJECTED')
    and nvl(pol.cancel_flag, 'N') = 'N'
    and &p_rate user parameter
    I want this p_rate to be passed as a user parameter.

  • How to type cast PL/SQL table to REF cursor?

    any one knows how to CAST PL/SQl table to Ref cursor?
    eg
    procedure some_name(r_out out sys_refcurosr)
    IS
    type t is table of tab%ROWTYPE;
    my_type t;
    begin
    select * bulk collect into my_type from tab;
    r_out := my_type; -- need help here..
    end;
    it's 10g

    ref cursor is pointer to result set. You can not cast to PL/SQL table.
    1 create or replace procedure some_name(r_out out sys_refcursor)
    2 IS
    3 begin
    4 OPEN r_out for select * from emp;
    5* end;
    SQL> /
    Procedure created.
    SQL> var mycursor refcursor;
    SQL> exec some_name(:mycursor);
    PL/SQL procedure successfully completed.
    SQL> set linesize 2000
    SQL> print :mycursor;
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7369 SMITH CLERK 7902 12/17/80 00:00:00 800 20
    7499 ALLEN SALESMAN 7698 02/20/81 00:00:00 1600 300 30
    7521 WARD SALESMAN 7698 02/22/81 00:00:00 1250 500 30
    7566 JONES MANAGER 7839 04/02/81 00:00:00 2975 20
    7654 MARTIN SALESMAN 7698 09/28/81 00:00:00 1250 1400 30
    7698 BLAKE MANAGER 7839 05/01/81 00:00:00 2850 30
    7782 CLARK MANAGER 7839 06/09/81 00:00:00 2450 10
    7788 SCOTT ANALYST 7566 04/19/87 00:00:00 3000 20
    7839 KING PRESIDENT 11/17/81 00:00:00 5000 10
    7844 TURNER SALESMAN 7698 09/08/81 00:00:00 1500 0 30
    7876 ADAMS CLERK 7788 05/23/87 00:00:00 1100 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7900 JAMES CLERK 7698 12/03/81 00:00:00 950 30
    7902 FORD ANALYST 7566 12/03/81 00:00:00 3000 20
    7934 MILLER CLERK 7782 01/23/82 00:00:00 1300 10
    14 rows selected.

  • Dynamically fetaching data into PL/SQL tables help

    Hi,
    I am develioping a PL/SQL procedure in which I am creatig 24 PL/SQL tables of the same type.
    But while inserting data in them I need to use the table names dynamically i.e., the Execute immediate used to put the data into the tables would remain same just I need that for each and every run of for loop for that Execute immediate statement, it should use different table name.
    Please see sample code below:
    col_name varchar2(20);
    Type RA_TABLE is table of CALL_DETAIL_EXCEPTION.IC_CIRCT_GR_CD%TYPE
    index by binary_integer;
    MY_RA1 RA_TABLE;
    MY_RA2 RA_TABLE;
    MY_RA3 RA_TABLE;
    MY_RA4 RA_TABLE;
    BEGIN
    for idx in 1..cnt_interval Loop
    Col_name := 'MY_RA'||idx;
    query1:='select Trunk_info bulk collect INTO MY_RA'|| idx ||' from dbl.vw_cgi v where not exists (select 1 from dbl.varun f
    where f.ic_circt_gr_cd= v.TRUNK_INFO and f.call_gmt_dnect_dt_time between
    to_date('''||stime||''',''yyyymmddhh24miss'') and to_date('''||etime||''',''yyyymmddhh24miss''))';
    Now when I execute this code, it gives me an error for query1 saying that it is unimplemented feature in Oracle.
    It is not able to pick up that dynamic table name.
    Please help!

    user9315951 wrote:
    I am develioping a PL/SQL procedure in which I am creatig 24 PL/SQL tables of the same type.All wrong. This is NOT how one treats data in PL/SQL.
    There is NO such concept as PL/SQL "+tables+". You are in fact defining associative arrays and not using these as associative arrays, but as normal arrays. Your code can consume vast amounts of server memory as private process memory. Your code CAN crash the Oracle database server (yes, I have seen this multiple times - even in production).
    Your code is flawed. Your approach is flawed.
    I suggest that you take several steps back, gain some understanding of fundamental Oracle concepts, about what does scale and perform in PL/SQL and SQL, and then apply these concepts and principles.

  • How to sort index_by pl/sql tables data in Oracle 9i Release 9.2.0.1.0 ?

    Hi all,
    I have populated an index_by binary_integer pl/sql table :
    declare
    type rec_ty is record(ligne number,code_enreg number(2),code_enreg_ordered number(2));
         type tab_ty is table of rec_ty index by binary_integer;
         vtab tab_ty;
         i pls_integer := 1;
    begin
    for venreg in(select * from fichier_tempo where num > 0 order by num) loop
              vtab(i).ligne := venreg.num;
              vtab(i).code_enreg := to_number(substr(venreg.texte,7,2));
              i := i + 1;
         end loop;
    end;
    Now I want to sort the code_enreg data of vtab into its code_enreg_ordered field. I must do that because I must verify that each code_enreg data entered are ordered. So if code_enreg is not equal to code_enreg_ordered at a specified index of vtab then I must take a decision in my program code ; I must code something when this disorder happens.
    How to do that ?
    Thank you very much indeed.

    Thank you Jeneesh , it works with a few modifications about the assignement of the pl/sql tables.
    Fantasy > Your blog talks about sorting the pl/sql table through the key. But I want to sort it through the field data. And my field data contains duplicated data. So you did not really reply to my need. Thank you anymore.

  • Importing 30 tables into one SQL Table (Help Required)

    Dear Experts,
    I am new in SQL server, actually i need to gather 30 different excel file in one sql server table and i have imported all excel file in different databases, all tables have 186 different columns and datatypes. I couldnt change data type while conversion.
    Now all columns have different data type which are occupying extra space in my database.
    Now the problem is that i need to convert all databases into one database or table. Although i have created a table but i dont have idea how to import all table into one table  and defining datatype in new table while importing the old tables.
    Please help me in this matter or if any body has skype or any other chatting id please do let me know so that i may explain it better.
    Thanking you in advance.
    Best Regards,
    SQL_beginner

    There are several things you can try.  If you have SSIS, take a look at this.
    http://www.singhvikash.in/2013/06/ssis-how-to-load-multiple-excel-files.html
    https://www.simple-talk.com/sql/ssis/importing-excel-data-into-sql-server-via-ssis-questions-you-were-too-shy-to-ask/
    Also, if your files have virtually the same name, like files with dates in the name, you can loop through files in your folder, and increment the loop with each run through.
    DECLARE @intFlag
    INT
    SET @intFlag
    = 1
    WHILE (@intFlag
    <=30)
    BEGIN
    PRINT @intFlag
    declare @fullpath1
    varchar(1000)
    select @fullpath1
    = '''\\path to your files\'
    + convert(varchar,
    getdate()- @intFlag
    , 112)
    + '_your-text-file-name.txt'''
    declare @cmd1
    nvarchar(1000)
    select @cmd1
    = 'bulk insert [dbo].[your-table-name] from '
    + @fullpath1 +
    ' with (FIELDTERMINATOR = ''\t'', FIRSTROW = 2, ROWTERMINATOR=''0x0a'')'
    exec (@cmd1)
    SET @intFlag
    = @intFlag + 1
    END
    GO
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

  • How to insert into two differents tables at the same time

    Hi
    I'm newer using JDev, (version 3.1.1.2 cause the OAS seems to support just the JSP 1.0)
    and I want to insert into two differents tables at the same time using one view.
    How can I do that ?
    TIA
    Edgar

    Oracle 8i supports 'INSTEAD OF' triggers on object views so you could use a process similar to the following:
    1. Create an object view that joins your two tables. 'CREATE OR REPLACE VIEW test AS SELECT d.deptno, d.deptname, e.empname FROM DEPT d, EMP E'.
    2. Create an INSTEAD OF trigger on the view.
    3. Put code in the trigger that looks at the :NEW values being processed and determines which columns should be used to INSERT or UPDATE for each table. Crude pseudo-code might be:
    IF :NEW.deptno NOT IN (SELECT deptno FROM DEPT) THEN
    INSERT INTO dept VALUES(:NEW.deptno, :NEW.deptname);
    INSERT INTO emp VALUES (:NEW.deptno, :NEW.empname);
    ELSE
    IF :NEW.deptname IS NOT NULL THEN
    UPDATE dept SET deptname = :NEW.deptname
    WHERE deptno = :NEW.deptno;
    END IF;
    IF :NEW.empname IS NOT NULL THEN
    UPDATE emp SET empname = :NEW.empname
    WHERE deptno = :NEW.deptno;
    Try something along those lines.
    null

  • Help: Error on SELECT INTO TABLE2 FROM TABLE AS E1 JOIN...

    Can anyone help? I am getting an error in my sql statement below:
    SELECT E1.COL1, E1.COL2, E2.COL3, E1.COL4
    INTO TABLE2
    FROM TABLE AS E1
    JOIN TABLE AS E2 ON
    (E1.COL1 = '10000' AND E2.COL1 = '20000') OR
    (E1.COL1 = '20000' AND E2.COL1 = '10000')
    WHERE
    E1.COL3 = E2.COL3 AND E1.COL4 = '11000' AND E1.COL3 < '2011/04/01'
    The script works fine on SQL Server (2008) but I am unable to run it in Oracle.
    I am using Oracle SQL Developer v1.5.4 Build MAIN-5940.
    Thanks in advance for anyone who can help.

    Tubby wrote:
    850777 wrote:
    Thanks for the immediate reply Tubby. I will try removing the AS for aliasing.
    I still have one more problem though (about removing the line INTO TABLE2) because
    I am actually using it to store the SELECTed data into the new TABLE2. Is there a workaround for this? ThanksWhat are you trying to do here? View the data produced by the query, or create a pl/sql routine?
    What's the point behind creating a table to store the results in?
    Tubby wrote:850777 wrote:
    Thanks for the immediate reply Tubby. I will try removing the AS for aliasing.
    I still have one more problem though (about removing the line INTO TABLE2) because
    I am actually using it to store the SELECTed data into the new TABLE2. Is there a workaround for this? ThanksWhat are you trying to do here? View the data produced by the query, or create a pl/sql routine?
    What's the point behind creating a table to store the results in?What I am trying to do is copy the data in TABLE to TABLE2 but with the data in E1.COL3 swapped with the one in E2.COL3 based on certain conditions.
    Basically I am just trying to swap the values of a column (COL3) and store it in my new table (TABLE2) together with all the (unswapped) values from all the other columns.
    Ex.
    TABLE
    COL1 COL2 COL3 COL4
    1 1 1 1
    2 2 3 2
    3 3 2 2
    4 4 4 1
    Target result:
    TABLE2
    COL1 COL2 COL3 COL4
    1 1 1 1
    2 2 2 2 <-swapped values
    3 3 3 2 <-in COL3
    4 4 4 1

Maybe you are looking for

  • Lost ability to download PDF documents with upgrade to 4.0

    Before upgrading to 4.0 could go to a website and click on a document, then pick a specific page to download to Adobe Reader 8 and get a clean PDF document. After upgrading could go to the same site, download a document and the site would show that i

  • Passing parameter in query

    Hi, I have one crystal report which retrieves data from Oracle and display report in ASP.NET page. I have below query. Select * From CustomerDetails cust Where cust.Order_date Between ({?From_Order_date} AND {?To_Order_date} ) AND cust.joining_date({

  • Question about folder move

    Dear all, When moving a folder to a place where a folder of the same name already exists, I am being asked whether I want to stop or replace and then the source folder deletes the contents of the destination folder. Is there a way to have the source

  • Waiting for the IPAD WIFI+3G

    I want to buy an IPAD and move to another country, other countries have 3G service companies but not AT & T. 3G works with any other company other than AT & T?

  • Compiling DSS on MacOS 10.3.9 with Xcode 1.5

    Hello, I am trying to compile DSS 5.5 on a XServer G4 with Mac OS Server 10.3.9 and Xcode 1.5. There is a failure in the ./Buildit script when launching the command: xcodebuild -project StreamingServer.xcode -target DSS Moreover, I can not open Strea