How can I create backup script for selected tables in Oracle?
How can I create backup script for selected tables in Oracle?
31617-Jul-2023
Updated on 18-Jul-2023
Home / DeveloperSection / Forums / How can I create backup script for selected tables in Oracle?
How can I create backup script for selected tables in Oracle?
Aryan Kumar
18-Jul-2023Sure, here is how you can create a backup script for selected tables in Oracle:
SQL
This script will create a backup for the tables
table1
,table2
, andtable3
. The backup tables will be namedBAK_table1
,BAK_table2
, andBAK_table3
.To run the script, you would save it as a text file and then execute it from SQLPlus. For example, if you saved the script as
backup_script.sql
, you would run it by typing the following command into SQLPlus:SQL
This would create the backup tables for the specified tables.
Here is an explanation of the code in the script:
SET SERVEROUTPUT ON
statement tells Oracle to display output from the script.DECLARE
statement declares a variable namedv_table_name
to hold the name of the current table.FOR
loop iterates through the list of tables and creates a backup for each one.dbms_output.put_line()
procedure displays a message to the console.EXECUTE IMMEDIATE
statement executes the specified SQL statement.END
statement marks the end of theFOR
loop.