Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need to run SQL Query in background (19c)

JhilMay 27 2024 — edited May 27 2024

Dear Experts,

We want to alter the table with huge number of existing records.

Looking for best approach to run in background.

select count(*) from HRMS2_EMP_ATTENDANCE_REGISTER ;
101855043  

>>

Using the nohup option, we wish to execute the SQL below in the background. The following query is not shown at the database level when I attempt to track long-running queries. "ALTER TABLE" is not operating in SQL, is what I intended to mention. What went wrong, I do not know. We need assistance, please!

>>

[oracle@hrms2-ora-pt01 ~]$ cat alter_query.sql
set echo on
ALTER TABLE HRMS2PLUS.HRMS2_EMP_ATTENDANCE_REGISTER
ADD (ID  NUMBER(10) DEFAULT "HRMS2PLUS"."MY_SEQ601"."NEXTVAL");

>>

[oracle@hrms2-ora-pt01 ~]$ cat run_alter.sh
#!/bin/bash
sqlplus -s username/password@TNS <<EOF
@/home/oracle/alter_query.sql
EXIT
EOF

[oracle@hrms2-ora-pt01 ~]$ nohup ./run_alter.sh > alter_table.log 2>&1 &

[oracle@hrms2-ora-pt01 ~]$ ps -ef | grep nohup
oracle   17993 27106  0 21:11 pts/2    00:00:00 grep --color=auto nohup

>> We have necessary privileges for these 2 files.

-rwxrwxrwx 1 oracle oinstall        101 May 27 19:21 run_alter.sh
-rwxrwxrwx 1 oracle oinstall        129 May 27 19:22 alter_query.sql
-rw-r--r-- 1 oracle oinstall         22 May 27 19:23 alter_table.log

Thanks

Comments
Post Details
Added on May 27 2024
6 comments
788 views