I'm trying to create a table with an index using a Bash script in the Unix environment. The individual SQL queries are running correctly. The issue is that the index of the table cannot be created.
As shown:
sqlplus -s $CONNECTION << EOF
set pages 0 feed off time off timing off
CREATE TABLE $TABLENAME
( "FILENAME" VARCHAR2(50 BYTE),
"USAGE" VARCHAR2(1000 BYTE)
)
TABLESPACE "DB_TABLES" ;
CREATE INDEX $TABLENAME_IDX1 ON $TABLENAME ("USAGE")
TABLESPACE "DB_TABLES" ;
exit;
EOF
The table will be created without the index.
Added: tried splitting the queries; added '/' behind each; when queries are run in SQL-Developer, it is fine.
Could your problem be that you don't have a variable $TABLENAME_IDX1
but you were hoping to use the table name concatenated with _IDX1
? If so, the solution is:
CREATE INDEX ${TABLENAME}_IDX1 ON $TABLENAME ("USAGE")
TABLESPACE "DB_TABLES";
The other part of the solution is to run the script with bash -x yourscript.sh
to see exactly what is executed. You would probably have spotted this problem if you had done that.
If this is not the correct diagnosis, you should most certainly run your script with bash -x
to see what is executed. You might want to show that output, along with the error message(s), in the question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.