Use shell script to execute sql statement:
sqlplus classpath system environment variable pre-configuration, Oracle tnsnames.ora configuration
1. Configure the sql server environment: tnsnames.ora: (../product/version/Client/network/admin)
In the tnsname.ora file, configure the server mapping:
ENV_DESTINATION =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = port))
)
(CONNECT_DATA =
(SERVICE_NAME = server)
)
)
1.sqlplus command: execute sql file
example:
sqlplus user/pwd@ENV_DESTINATION @%1\test.sql
@parameter
%1 first command line argument
This command executes the sql statement in test.sql
2.copy command: Migration inserts the result of sql query into the current database as a data source
COPY FROM user/pwd@ENV_SOURCE INSERT schema1.table1 USING SELECT * FROM schema2.table2;
3. spool command: export the exported data to C:\test.txt in the specified directory, field segmentation rule '<EOFD>'
spool C:\test.txt
select TRIM(ID)||'<EOFD>'|| TRIM(ACTION_TYPE)
FROM schema.tablename;
4.sqlldr command: read the data exported in 3 as the data source, and execute according to the same field segmentation rule '<EOFD>'
4.1 Predefined rules test.ctl file :
load data
infile 'C:\test.txt '
INSERT
INTO TABLE schem2.tablename2
FIELDS TERMINATED BY '<EOFD>'
trailing nullcols
(ID,NAME char(1000))
4.2 sqlldr command: execute the test.ctl file :
sqlldr user/pwd@ENV_DESTINATION control=%1\test.ctl log=%1\log1.log bad=%1\bad1.log rows=500 parallel=true
Another: sql comment symbol: -- bat comment symbol rem