sqlplus

How to output oracle sql result into a file in windows?

雨燕双飞 提交于 2019-11-27 11:09:41
问题 I tried select * from users save D:\test.sql create; But SQL plus gives me "no proper ended" How to specify path in oracle sql in windows? 回答1: Use the spool: spool myoutputfile.txt select * from users; spool off; Note that this will create myoutputfile.txt in the directory from which you ran SQL*Plus. If you need to run this from a SQL file (e.g., "tmp.sql") when SQLPlus starts up and output to a file named "output.txt": tmp.sql: select * from users; Command: sqlplus -s username/password@sid

Force index use in Oracle

有些话、适合烂在心里 提交于 2019-11-27 10:47:15
问题 I encountered this question in an interview and had no clue how to answer: There is a table which has a index on a column, and you query: select * from table_name where column_having_index="some value"; The query takes too long, and you find out that the index is not being used. If you think the performance of the query will be better using the index, how could you force the query to use the index? 回答1: You can use optimizer hints select /*+ INDEX(table_name index_name) */ from table etc...

Does SQLDeveloper support executing scripts?

孤街醉人 提交于 2019-11-27 10:33:32
问题 I was trying to follow some instructions today, and it starts with the comment REM In SQLPlus I manually copy in each line and execute it. That's nice, I don't have SQLPlus, I have SQLDeveloper. The lines that were pasted in were of the type: @\\server\dir\dir\dir\commandfile1.txt; COMMIT; ...etc. It didn't like it when I tried that in a SQL window. I opened up and pasted in the commands by hand, and it wasn't happy with that either. (Did I mention that I'm not so good with this application

How can I kill all sessions connecting to my oracle database?

柔情痞子 提交于 2019-11-27 09:51:50
问题 I need to quickly (and forcibly) kill off all external sessions connecting to my oracle database without the supervision of and administrator. I don't want to just lock the database and let the users quit gracefully. How would I script this? 回答1: This answer is heavily influenced by a conversation here: http://www.tek-tips.com/viewthread.cfm?qid=1395151&page=3 ALTER SYSTEM ENABLE RESTRICTED SESSION; begin for x in ( select Sid, Serial#, machine, program from v$session where machine <>

how to loop accepting user input with pl/sql?

霸气de小男生 提交于 2019-11-27 09:22:52
I want to be able to insert a variable number of rows into a table based on user input? eg. Please enter value, enter "done" when no more values: value 1 Please enter value, enter "done" when no more values: value 2 Please enter value, enter "done" when no more values: done 2 Rows inserted successfully. I'm not sure how to store the rows temporarily and I'm not sure how to ask the user multiple times to insert data. Does pl/sql have arrays? Thanks Tony Andrews As others have said, PL/SQL alone is not suitable for this task, you need a UI on top to interact with the end user. However, if you

Convert epoch to date in sqlplus / Oracle

谁都会走 提交于 2019-11-27 08:56:07
I have the following table: SQL> desc recording Name Null? Type -------------------- -------- ------ CAPTUREID NOT NULL NUMBER(9) STARTDATE NOT NULL DATE ENDDATE DATE STATE NUMBER(1) ESTIMATEDENDTIME NUMBER(13) Here's a single line for this table: SQL> select * from recording where CAPTUREID=14760457; CAPTUREID STARTDATE ENDDATE STATE ESTIMATEDENDTIME ---------- ------------------- ------------------- ----- ---------------- 14760457 29/09/2010 08:50:01 29/09/2010 09:52:04 0 1285746720000 I'm pretty sure that this has been asked so many times before, but all the solutions I've found so far didn

Oracle Shutdown error ORA-01033

混江龙づ霸主 提交于 2019-11-27 08:40:46
问题 I had installed Oracle 11g on windows 07,everything was working fine.But today it is giving me an error saaying ORA-01033: ORACLE initialization or shutdown in progress . I followed the steps mentioned in the different communities but unable to solve the error. After connecting as sqlplus sys/sys as sysdba . and executing below statement,i got following error. How to solve this error? SQL> recover database; ORA-00283: recovery session canceled due to errors ORA-01110: data file 9: 'C:\APP

Top n percent top n%

断了今生、忘了曾经 提交于 2019-11-27 08:16:31
问题 I do have the following code. SQL> select * from student_gpa; SSN GPA --------------- ---------- 22222 3 11111 4 55555 3 33333 4 44444 3 I do have this function to get the top two gpa score rows. SQL> select * from (select ssn, gpa from student_gpa order by gpa desc) where rownum <= 2; SSN GPA --------------- ---------- 11111 4 33333 4 My question is what function do I use to get the top n% of the GPA score. For example, Since I have two individuals with a GPA of 4, dense rank would return

Sqlplus login error when using bash variables: SP2-0306: Invalid option

匆匆过客 提交于 2019-11-27 07:57:25
问题 I have a bash script that connects to an oracle 10g database. In a first step it takes some variables from a "config" file with the following command . /path/to/my/configfile.ini In the config file there are some variables: export USRID=myUser export USRID_PASS=myPassword export USR_PASS="$USRID/$USRID_PASS@myDatabase" Then it actually connects through sqlplus using the command: sqlplus -s $usr_pass Terrible Security and Design issues aside (this script has been around for 5 years). This is

Duplicate columns with inner Join

牧云@^-^@ 提交于 2019-11-27 06:52:13
问题 SELECT dealing_record.* ,shares.* ,transaction_type.* FROM shares INNER JOIN shares ON shares.share_ID = dealing_record.share_id INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id; The above SQL code produces the desired output but with a couple of duplicate columns. Also, with incomplete display of the column headers. When I change the linesize 100 the headers shows but data displayed overlaps I have checked through similar questions but