This action might not be possible to undo. Are you sure you want to continue?
txt select xxxxxxx from tab1; spool off
Topics What is SQL and where does it come from? What are the difference between DDL, DML and DCL commands? How does one escape characters when building SQL queries? How does one eliminate duplicate rows from a table? How does one generate primary key values for a table? How does one get the time difference between two date columns? How does one add a day/hour/minute/second to a date value? How does one count different data values in a column? How does one count/sum RANGES of data values in a column? Can one retrieve only the Nth row from a table? Can one retrieve only rows X to Y from a table? How does one select EVERY Nth row from a table? How does one select the TOP N rows from a table? How does one code a tree-structured query? How does one code a matrix report in SQL? How does one implement IF-THEN-ELSE in a select statement? How can one dump/ examine the exact content of a database column? Can one drop a column from a table? Can one rename a column in a table? How can I change my Oracle password? How does one find the next value of a sequence? Workaround for snapshots on tables with LONG columns Where can one get more info about SQL?
What are the difference between DDL, DML and DCL commands? DDL is Data Definition Language statements. Some examples: • • • • • • • CREATE - to create objects in the database ALTER - alters the structure of the database DROP - delete objects from the database TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed COMMENT - add comments to the data dictionary GRANT - gives user's access privileges to database REVOKE - withdraw access privileges given with the GRANT command
DML is Data Manipulation Language statements. Some examples: • • SELECT - retrieve data from the a database INSERT - insert data into a table
• • • • •
UPDATE - updates existing data within a table DELETE - deletes all records from a table, the space for the records remain CALL - call a PL/SQL or Java subprogram EXPLAIN PLAN - explain access path to data LOCK TABLE - control concurrency
DCL is Data Control Language statements. Some examples: • • • • COMMIT - save work done SAVEPOINT - identify a point in a transaction to which you can later roll back ROLLBACK - restore database to original since the last COMMIT SET TRANSACTION - Change transaction options like what rollback segment to use
Back to top of file How does one escape special characters when building SQL queries? The LIKE keyword allows for string searches. The '_' wild card character is used to match exactly one character, '%' is used to match zero or more occurrences of any characters. These characters can be escaped in SQL. Example: SELECT name FROM emp WHERE id LIKE '%\_%' ESCAPE '\'; Use two quotes for every one displayed. Example: SELECT 'Franks''s Oracle site' FROM DUAL; SELECT 'A ''quoted'' word.' FROM DUAL; SELECT 'A ''''double quoted'''' word.' FROM DUAL; Back to top of file How does one eliminate duplicates rows from a table? Choose one of the following queries to identify or remove duplicate rows from a table leaving only unique records in the table: Method 1: SQL> DELETE FROM table_name A WHERE ROWID > ( 2 3 SELECT min(rowid) FROM table_name B WHERE A.key_values = B.key_values);
key_value2 and t2.key_value2 = t1. Finally. Note 2: If you are comparing NOT-NULL columns.key_value1 = t1.. triggers.Remember to recreate all indexes.. etc on table. Method 3: (thanks to Dennis Gurnick) SQL> delete from my_table t1 SQL> where exists (select 'x' from my_table t2 SQL> SQL> SQL> where t2. create a unique index on this column. SQL> -. This column can now be populated with unique values: SQL> UPDATE table_name SET seqno = ROWNUM. constraints. SQL> drop table_name1.rowid). Note: One can eliminate N^2 unnecessary operations by creating an index on the joined fields in the inner loop (no need to loop through the entire table on each pass by a record).NEXTVAL. or use a sequences generator: SQL> CREATE SEQUENCE sequence_name START WITH 1 INCREMENT BY 1. SQL> UPDATE table_name SET seqno = sequence_name. use the NVL function. This should not be a problem as all key columns should be NOT NULL by definition.SQL> create table table_name2 as select distinct * from table_name1. Remember that NULL is not equal to NULL.rowid > t1.key_value1 and t2. Back to top of file How does one generate primary key values for a table? Create your table with a NOT NULL column (say SEQNO). This will speed-up the deletion process. SQL> rename table_name2 to table_name1. Back to top of file How does one get the time difference between two date columns? Look at this example query: .
Use fractions to add hours. If you don't want to go through the floor and ceiling math. It will thus never return a value bigger than 23:59:59.-------------------.. Note that this query only uses the time portion of the date and ignores the date itself.-------------------- . sysdate + 1/86400 from dual. sysdate +1/1440.. 'HH24:MI:SS') time_difference from .. Back to top of file How does one add a day/hour/minute/second to a date value? The SYSDATE pseudo-column shows the current system date and time. sysdate+1/24. try this method (contributed by Erik Wile): select to_char(to_date('00:00:00'.select floor(((date1-date2)*24*60*60)/3600) || ' HOURS ' || floor((((date1-date2)*24*60*60) floor(((date1-date2)*24*60*60)/3600)*3600)/60) || ' MINUTES ' || round((((date1-date2)*24*60*60) floor(((date1-date2)*24*60*60)/3600)*3600 (floor((((date1-date2)*24*60*60) floor(((date1-date2)*24*60*60)/3600)*3600)/60)*60))) || ' SECS ' time_difference from . Look at these examples: SQL> select sysdate.. SYSDATE SYSDATE+1/86400 SYSDATE+1/24 SYSDATE+1/1440 -------------------. minutes or seconds to the date.date2). Adding 1 to SYSDATE will advance the date by 1 day.'HH24:MI:SS') + (date1 .-------------------.
03-Jul-2002 08:32:12 03-Jul-2002 09:32:12 03-Jul-2002 08:33:12 03-Jul2002 08:32:13 The following format is frequently used with Oracle Replication: select sysdate NOW.''WEDNESDAY'').m Back to top of file How does one count different data values in a column? .''MONDAY'' ). TRUNC(LEAST(NEXT_DAY(sysdate.NEXT_DAY(sysd Wednesday or Friday ate.-1))) + 1 The next Monday. NOW NOW_PLUS_30_SECS -------------------. sysdate+30/(24*60*60) NOW_PLUS_30_SECS from dual.-------------------03-JUL-2002 16:47:23 03-JUL-2002 16:47:53 Here are a couple of examples: Description Now Tomorow/ next day Seven days from now One hour from now Three hours from now An half hour from now SYSDATE SYSDATE + 1 SYSDATE + 7 SYSDATE + 1/24 SYSDATE + 3/24 SYSDATE + 1/48 Date Expression 10 minutes from now SYSDATE + 10/1440 30 seconds from now SYSDATE + 30/86400 Tomorrow at 12 midnight Tomorrow at 8 AM Next Monday at 12:00 noon First day of next month at 12 midnight First day of the current month TRUNC(SYSDATE + 1) TRUNC(SYSDATE + 1) + 8/24 NEXT_DAY(TRUNC(SYSDATE). NEXT_DAY(sysdate.''FRIDAY'' ))) + (9/24) at 9 a. 'MONDAY') + 12/24 TRUNC(LAST_DAY(SYSDATE ) + 1) TRUNC(LAST_DAY(ADD_MONTHS(SYSDATE.
0. 0)) "Range 30-59".'M'. least(f1. 0)) "Range 60-100". 29). decode( trunc(f2/1000.31) "Tax rate" from my_table. 1. z). 1. select dept. 0).1)) TOTAL from my_emp_table group by dept. 0.'F'. count(*) from my_table group by my_table_column.. For equal size ranges it might be easier to calculate it with DECODE(TRUNC(value/range). least(f1.2. . 0.0)) MALE.59). 0. least(f1. 1. select ename "Name". sum(decode(greatest(f1. 0).. sum( decode(sex.100).. A more sophisticated example. count(decode(sex. sal "Salary". sum(decode(greatest(f1. 1. y) = LEAST(x. 59). rate_0.1.30).'F'. 0)) "Range 00-29" from my_table group by f2. rate_1.1.1. 3.'M'. Back to top of file How does one count/sum RANGES of data values in a column? A value x will be between values y and z if GREATEST(x. sum(decode(greatest(f1. Eg. Look at this example: select f2.Use this simple query to count the number of data values in a column: select my_table_column. 0.0)) FEMALE. 1. Back to top of file .0. 0..1.). sum( decode(sex. 2.
empno HAVING rownum = 4. SELECT rownum. Shaik Khaleel provided this solution: SELECT * FROM ( SELECT ENAME..empno FROM scott. then we select the required one. SELECT * FROM emp WHERE rownum=1 AND rowid NOT IN (SELECT rowid FROM emp WHERE rownum < 10). Note: In this first query we select one more than the required row number.emp a GROUP BY rownum.ROWNUM RN FROM EMP WHERE ROWNUM < 101 ) WHERE RN = 100.rowid).Can one retrieve only the Nth row from a table? Rupak Mohan provided this solution to select the Nth row from a table: SELECT * FROM t1 a WHERE n = (SELECT COUNT(rowid) FROM t1 b WHERE a. Alternatively..rowid >= b. . Ravi Pachalla provided these solutions: SELECT f1 FROM t1 WHERE rowid = ( SELECT rowid FROM t1 WHERE rownum <= 10 MINUS SELECT rowid FROM t1 WHERE rownum < 10). Its far better than using a MINUS operation.
Back to top of file How does one select EVERY Nth row from a table? One can easily select all even. f1 FROM t1 GROUP BY rownum.ROWNUM RN FROM EMP WHERE ROWNUM < 101 ) WHERE RN between 91 and 100 . this query is quite fun and may even help in the odd situation. Another solution is to use the MINUS operation. to display rows 5 to 7.Please note. However. this query is quite fun and may even help in the odd situation. there is no explicit row order in a relational database. f1 HAVING rownum BETWEEN 2 AND 4. y=100. Back to top of file Can one retrieve only rows X to Y from a table? Shaik Khaleel provided this solution to the problem: SELECT * FROM ( SELECT ENAME. there is no explicit row order in a relational database. However. construct a query like this: SELECT * FROM tableX WHERE rowid in ( SELECT rowid FROM tableX WHERE rownum <= 7 MINUS SELECT rowid FROM tableX WHERE rownum < 5). Please note. odd. Note: the 101 is just one greater than the maximum row of the required rows (means x= 90. or Nth rows from a table using SQL queries like this: . Ravi Pachalla provided this solution: SELECT rownum. For example. so the inner values is y+1).
4) = 0. Method 2: Use dynamic views (available from Oracle7.provided by Ravi Pachalla SELECT rownum. f1 HAVING MOD(rownum. Use this workaround with prior releases: SELECT * FROM my_table a WHERE 10 >= (SELECT COUNT(DISTINCT maxcol) . these queries are quite fun and may even help in the odd situation. Method 3: Using GROUP BY and HAVING . However. empno. Look at this example: SELECT * FROM (SELECT * FROM my_table ORDER BY col_name_1 DESC) WHERE ROWNUM < 10. there is no explicit row order in a relational database.n) = 0 OR rownum = 2-n Please note. MOD(ROWNUM.ROWNUM.2): SELECT * FROM ( SELECT rownum rn.Method 1: Using a subquery SELECT * FROM emp WHERE (ROWID.0) IN (SELECT ROWID. Back to top of file How does one select the TOP N rows from a table? Form Oracle8i one can have an inner-query with an ORDER BY clause.4) FROM emp). ename FROM emp ) temp WHERE MOD(temp. f1 FROM t1 GROUP BY rownum.
LEVEL * 2) || ENAME . for each of the records open a cursor to look for child nodes. Look at this example: select lpad(' '. open the driving cursor with the "connect by prior" statement. The LEVEL pseudo-column is an indication of how deep in the tree one is. One uses the "start with" clause to specify the start of the tree. One disadvantage of having a "connect by prior" clause is that you cannot perform a join to other tables. inserting the results into a temporary table for later retrieval... Trying to do this programmatically is difficult as one has to do the top level query first. then. One can produce an indented report by using the level number to substring or lpad() a series of spaces.. Also. Back to top of file How does one code a matrix report in SQL? . MGR from EMP connect by prior EMPNO = MGR start with MGR is NULL. More than one record can match the starting condition. This table is perfect for tesing and demonstrating tree-structured queries as the MGR column contains the employee number of the "current" employee's boss.maxcol) ORDER BY maxcol DESC. EMPNO.. Oracle can handle queries with a depth of up to 255 levels. The "connect by prior" clause is rarely implemented in the other database offerings. The SCOTT/TIGER database schema contains a table EMP with a self-referencing relation (EMPNO and MGR columns). Back to top of file How does one code a tree-structured query? Tree-structured queries are definitely non-relational (enough to kill Codd and make him roll in his grave)..maxcol >= a. One way of working around this is to use PL/SQL.. ENAME. and the select matching records from other tables on a row-by-row basis.FROM my_table b WHERE b. and concatenate that to the string. Look at this example: select LEVEL.. this feature is not often found in other database offerings.
sum(decode(deptno. . 'Female'. a-b. 1300 2450 5000 5600 6000 1900 2975 950 2850 select a.20.40.---------. sum(decode(deptno.30. JOB DEPT10 DEPT20 DEPT30 DEPT40 --------.sal)) DEPT40 FROM scott. b.---------ANALYST CLERK MANAGER PRESIDENT SALESMAN Back to top of file How does one implement IF-THEN-ELSE in a select statement? The Oracle decode function acts like a procedural statement inside an SQL statement to return different values or columns based on the values of other columns in the select statement.Look at this example query with sample output: SELECT * FROM (SELECT job. 'F'. 'a > b'. 'a = b'.emp GROUP BY job) ORDER BY 1. sum(decode(deptno.sal)) DEPT20.---------. 'Male'. decode( abs(a-b). 0.10.sal)) DEPT30. sum(decode(deptno.sal)) DEPT10. Some examples: select decode(sex. 'M'.---------. 'Unknown') from employees.
decode(A.66. select decode( GREATEST(A. 'A GREATER THAN B').. It is one of the good things about Oracle.. This tells us that this column is blankpadded.. but use it sparingly if portability is required. and the last byte in the column is 32. B.67. 'A is greater OR EQUAL than B'. Note: The decode function is not ANSI SQL and is rarely implemented in other RDBMS offerings. A. 'B is greater than A'). select decode( GREATEST(A. DUMP(COL1) ------------------------------------Typ=96 Len=4: 65. which is the ASCII code for a space. indicating CHAR. Back to top of file How can one dump/ examine the exact content of a database column? SELECT DUMP(col1) FROM tab1 WHERE cond1 = val1.B).32 For this example the type is 96. 'A NOT GREATER THAN B'. CASE WHEN sal>1000 THEN 'Over paid' ELSE 'Under paid' END FROM emp. From Oracle 8i one can also use CASE statements in SQL.'a < b') from tableX. A.B).. Back to top of file Can one drop a column from a table? . Look at this example: SELECT ename. 'A NOT GREATER THAN B').
SQL> create view t1 as select <specific columns> from t1_base. create table t2 <column list with new name> as select * from t1.. Other workarounds: 1.From Oracle8i one can DROP a column from a table. -.. command.Use a view with correct column names. SQL> rename t1 to t1_base. drop table t1. rename t2 to t1. 2. Look at this sample script. demonstrating the ALTER TABLE table_name DROP COLUMN column_name.Add a column with a new name and drop an old column.. create view t1 <column list with new name> as select * from t1_base.. rename t1 to t1_base. alter table t1 add ( newcolame datatype ). 2. Other workarounds: 1..Recreate the table with correct column names. -. SQL> create table t2 as select <specific columns> from t1.. SQL> drop table t1. -. SQL> rename t2 to t1. . 3. Look at this example: ALTER TABLE tablename RENAME COLUMN oldcolumn TO newcolumn. update t1 set newcolname=oldcolname. SQL> update t1 set column_to_drop = NULL. Back to top of file Can one rename a column in a table? From Oracle9i one can RENAME a column from a table.
. or any other operation that would cause gaps in sequence values. Contents of this Page Can I Update From Another Table ? Can I Remove Duplicate Rows ? What is ROWID good for ? .. you will see the correct high water mark value that would be returned for the next NEXTVALL call. perform an "ALTER SEQUENCE . - Note: If you run Oracle8. Afterwards.. Back to top of file How does one find the next value of a sequence? Perform an "ALTER SEQUENCE . If you then select from the USER_SEQUENCES dictionary view. NOCACHE" to unload the unused cached sequence numbers from the Oracle library cache. CACHE" to restore caching. type "password user_name". Back to top of file How can I change my Oracle password? Issue the following SQL command: ALTER USER <username> IDENTIFIED BY <new_password> / From Oracle8 you can just type "password" from SQL*Plus. no cached numbers will be lost.alter table t1 drop column oldcolname.. or if you need to change another user's password. Back to top of file Workaround for snapshots on tables with LONG columns You can use the SQL*Plus COPY command instead of snapshots if you need to copy LONG and LONG RAW variables from one location to another. IMAGE FROM IMAGES. as it can be replicated. This way. Eg: COPY TO SCOTT/TIGER@REMOTE CREATE IMAGE_TABLE USING SELECT IMAGE_NO. You can use the above technique to prevent sequence number loss before a SHUTDOWN ABORT. convert your LONGs to LOBs.
if we had a table DEPT_SUMMARY. using the ROWID field. What is ROWNUM good for ? Views Questions on views have moved to another page. we could update the number of employees field as follows: update DEPT_SUMMARY s set NUM_EMPS = ( select count(1) from EMP E where E. columns. There are many variations on this theme. etc are there ? How can I rename a column ? Is there a formatter for SQL or PL/SQL ? How come records for the date I want are missing ? How can I interpret a two digit year after 2000 ? What is a cluster ? How do I control which rollback segment I use ? How do order a union ? Who are SCOTT. delete from EMP E where not E. SYSTEM and SYS ? How do I avoid blowing rollback segments ? How can I restore passwords ? Not Formatted Yet Can I Update From Another Table ? Yes.DEPTNO ). but the logic is to delete all but one record for each key value. For example.DEPTNO = S. The ROWID is guaranteed unique.ROWID = ( . Can I implement Tree Structured Queries ? How can I get information on the row based on group information ? How can I get a name for a temporary table that will not clash ? How can I discover what tables. Back to Top of File Can I remove duplicate rows ? Yes.
. Oracle can handle queries with a depth up to 255. You use the start with clause to specify the start of the tree(s). soon you blow the cursor limit for your installation. More than one record can match the starting condition. The MGR column contains the employee number of the "current" employee's boss. and the select matching records from other tables on a row-by-row basis.. This is definitely non-relational (enough to kill Codd and then make him roll in his grave) and is a feature I have not seen in the competition... The way around this is to use PL/SQL.. The definitive example is in the example SCOTT/TIGER database....select min(F. One disadvantage of a "connect by prior" is that you cannot perform a join to other tables. open the driving cursor with the "connect by prior" statement. select LEVEL. You have available an extra pseudo-column..ROWID) from EMP F where F. select lpad(' '.EMP_ID = E.EMP_ID )... Even trying to doing this programmatically in embedded SQL is difficult as you have to do the top level query. inserting the results into a temporary table for later retrieval. for each of these. EMPNO.. You can get an "indented" report by using the level number to substring or lpad a series of spaces and concatenate that to the string. ENAME.. I have not managed to see anything else like the "connect by prior" in the other vendor offerings and I like trees. LEVEL * 2) || ENAME . for each of them open a cursor to look for lower level rows. that says how deep in the tree you are. MGR from EMP connect by prior EMPNO = MGR start with MGR is NULL. LEVEL. Still. . when looking at the EMP table (EMPNO and MGR columns). Back to Top of File Can I implement Tree Structured Queries ? Yes! This is commonly asked by those migrating from non-RDBMS apps.
and use the number to help you build the temporary table name.ENAME.DEPTNO.SAL from EMP e where e.SAL in ( select max (e2.SAL) from EMP e2 where e2. You could get similar info on employees with the highest salary in their departments as follows select e. Back to Top of File How can I get information on the row based on group information ? Imagine we have the EMP table and want details on the employee who has the highest salary.DEPTNO ). e.DEPTNO = e. select e. e. e. Note that SQL-92 is developing specific constructs for using temporary tables. Back to Top of File How can I get a name for a temporary table that will not clash ? Use a sequence. Back to Top of File . e.SAL from EMP e where e.EMPNO.Note that you can't trick Oracle by using CONNECT BY PRIOR on a view that does the join.ENAME.SAL = ( select max (e2. You need to use a subquery.SAL) from EMP e2 ).
but I do not now if they have unbundled it. I have recently heard that Kumaran Systems (see Vendor list) have a Forms PL/SQL and SQL formatter.sql to do this. Note that you CANNOT use cb and indent with Pro*C as both these programs will screw up the embedded SQL code. If you are a DBA you should also create private DBA synonyms by running $ORACLE_HOME/rdbms/admin/dba_syn. maybe someone could base a reformatter based on the grammar. As far as I know there is no PD formatter for SQL available. Back to Top of File Is there a formatter for SQL or PL/SQL ? There are a number of "beautifiers" for various program languages.How can I discover what tables. the first two to look at are DICT and DICT_COLUMNS which act as a directory of the other dictionary views. In V6. columns. Do backup the database first unless you feel brave. The cb and indent programs for the C language spring to mind (although they have slightly different conventions). (I have successfully done it in V4 thru V7). It can be done carefully by the DBA playing around with internal SYS dictionary tables and bouncing the database. etc are there ? Oracle maintains a live set of views that you can query to tell you what you have available. If you can't figure out how to use it from the source you definitely should not run it.sql in your account. It is a good idea to be familiar with these. Back to Top of File . Not all of these views are accessible by all users. but this is not supported. I've written a quick and dirty script rncol. You can use a similar dirty trick for changing ownership of tables if storage space is limited. Back to Top of File How can I rename a column ? There is no way a column can be renamed using normal SQL. Given that there are PD general SQL parsers and that the SQL standards are drafted in something close to BNF.
OBJ$) and are dummied up by the RDBMS kernel software in much the same way that UNIX System V. Back to Top of File What are these V$ tables? There are a number of tables/views beginning with V$ that hold gory details for performance monitoring.4 dummies up the files in the /proc or /dev/proc directories.How come records for the date I want are missing ? You are trying to retrieve data based on something like: SELECT fld1. Back to Top of File How can I interpret a two digit year after 2000 ? When converting to dates from characters when you only have two characters for the year. 'HH24:... which can be a bad move regarding SQL performance. or you can say WHERE date_field >= '18-jun-60' AND date_field < '19-jun-60' An alternative could be something like WHERE date_field between '18-jun-1960' AND to_date('23:59:59 18-jun-60'..YY') . If you have any code depending on these (and the widely used tools supplied by Oracle but unsupported are in this category) then you need to verify that everything works each time you upgrade your database. all bets are off.. .. You can either use to_char and to_date functions. the picture format "RR" will be interpreted as the year based on a guess that that date is between 1950 and 2049. fld2 FROM tbl WHERE date_field = '18-jun-60' You *know* there are records for that day . And when a major revision changes.but none of them are coming back to you. There are usually no real underlying tables (unlike SYS. What has happened is that your records are not set to midnight (which is the default value if time of day not specified). These are not guaranteed to be stable from minor release to minor release and are for DBAs only.
. for n in 1. begin open c1.10 loop fetch c1 into :tenthsal.ordered_column. cursor c1 is select SAL from EMP order BY SAL desc. I do not believe that straight SQL is the way to go for such problems when you have PL/SQL available.other_stuff from table_name a where 10 > ( select count(1) from table_name b where b.ordered_column < a. a.com select a. My approach is to use PL/SQL instead (in SQL*Plus): variable tenthsal number declare n number.. One elegant SQL-only approach (although it will be a bitch on a large table) was suggested by Stowe@aol.Back to Top of File How do I get a top ten ? This question often gets the response WHERE ROWNUM <= 10 but this will not work (except accidentally) because the ROWNUM pseudocolumn is generated before the ORDER or WHERE clauses come into effect.ordered_columnl.ordered_column ) order by a.
you may need to control the rollback segment used as the default rollback segment may be too small for the required transaction. using both EMP and DEPT tables: . The statement is as follows: SET TRANSACTION USE ROLLBACK SEGMENT segment_name. if all you are doing are SELECTS. unaffected by others. Both these statements must be the first statement of the transaction.end loop. Back to Top of File How do I order a union ? (Governments around the world have been trying to figure this one out). On a related note. close c1. end: / select * from EMP where SAL <= :tenthsal order by SAL desc. it is worth telling the database of this using the following: SET TRANSACTION READ ONLY. etc. Needs V7. Say we are getting a list of names and codes and want it ordered by the name. Late news: index descending hint to SQL works if you use a dummy restriction to force use of the index. or you may want to ensure that your transaction runs in a special rollback segment. Use the column number. Back to Top of File How do control which rollback segment I use ? In SQL.
Back to Top of File How can I avoid blowing rollback segments ? The simple answer is make sure you have them big enough and keep your transactions small. ENAME from EMP order by 2. but that is being a smartarse. The solution I have used was to have one process select ROWID from the appropriate rows and pump these (via standard I/O) to another process that looped around reading ROWIDs from standard input. This is OK except for where you are doing your work in a single statement rather than using PL/SQL and a loop construct. because usually the cursor will close. You cannot have a number of updates of a few records each because the keys may change . Another common user/password is PLSQL/SUPERSECRET used for PL/SQL demo stuff. updating the appropriate record and committing every 10 records or so. Imagine you have a HUGE table and need to update it. Back to Top of File . but not if you are using MODE=ANSI. You cannot open a cursor and commit every n records.select DEPTNO. Back to Top of File Who are SCOTT. If you are writing in Pro*C and use MODE=ORACLE. SYSTEM and SYS ? These three users are common in many databases. More recent versions of Oracle have an option for the session that you can set that commits every so many DML statements. The number of locks and size of rollback segments required was minimal. DNAME from DEPT union select EMPNO. See the glossary entries under SCOTT. You cannot update it in one go because your rollback segments are too small. possibly updating the key. there are ways around it too. This was very easy to program and also was quite fast in execution. SCOTT and SYS.causing you to visit records more than once.
--------------.1. grant connect to SCOTT identified by passwords GOBBLEDYGOOK.1.--------------NLSRTL 3.0 Production also.3.3.substr(status. To restore the password to what it was use the following syntax (which I think is undocumented).7.7.15) product.0 Production Oracle8i Enterp 8.4. substr(i.1. so this is really a DBA question.How can I restore passwords ? OK.4) "Version" . First.APPLICATION_NAME. BANNER ---------------------------------------------------------------Oracle8i Enterprise Edition Release 8. However you can use this if you have saved it somewhere else.7. Say you want to impersonate a user in a batch run overnight.3.1. First stash the gobbledygook password away somewhere.1.1.7. It looks like gobbledygook because it is an encrypted password. Note especially the S on the end of PASSWORDS.3.1.PRODUCT_VERSION. but it is worth putting in here because it involves SQL regardless of interface. look at the PASSWORD column in DBA_USERS.0.Production Question: What Applications/Versions/Patch Levels are loaded on my machine ? this query gives more details than the one below select substr(a.60) "Application Name" .15) status from product_component_version PRODUCT VERSION STATUS --------------.15) version.1. grant connect to the user identified by some password you know and then run your batches using the new known password. SQL> select * from v$version where banner like 'Oracle%'.0 .0 Production TNS for 32-bit 8.substr(version. Question: What versions are loaded on my machine ? SQL> select substr(product.1.1.0 Production PL/SQL 8.
'201'.segment3.PATCH_LEVEL "Patch Level" .SHORT_NAME.'200'.'185') order by a.APPLICATION_ID = a.not all applications update the next field correctly -.5) Auth.code_combination_id.'260'.FND_APPLICATION_ALL_VIEW a where i. substr(gl.LAST_UPDATE_DATE "Last Update" from APPS.5) RC.5) ccid.'140'. CURRENCY_CODE.and i.these are the applications that concern me most -.FND_PRODUCT_INSTALLATIONS i .count(gl_date) from ra_cust_trx_line_gl_dist_All where account_class = 'REV' group by gl_date Question: What is my current GL SET OF BOOKS select SET_OF_BOOKS_ID. substr(gl. NAME. APPS.APPLICATION_ID in ('0'. substr(gl.1. patch_type.PATCH_LEVEL like '11i%' -. ACCOUNTED_PERIOD_TYPE.1. CHART_OF_ACCOUNTS_ID. .'222'.8) Account.APPLICATION_ID "Application ID" . i. applied_patch_id. PERIOD_SET_NAME.1.APPLICATION_NAME Question: What patches are loaded on my machine ? select patch_name..5) Func. i.segment5. rapid_installed_flag.and i.'101'.gl_code_combinations gl order by code_combination_id Question: How many transactions exist by GL DATE (period) ? select gl_date.segment1. maint_pack_level from ad_applied_patches where patch_name like '%' order by 1 How do I obtain CCID / Chart of Account data for General Ledger select substr(gl.'275'. substr(gl.segment2.segment4. i.1.1.APPLICATION_ID -. substr(gl.1.5) Job FROM gl.
1. substr(DESCRIPTION.random from dual.0.'TERMINAL') from dual.0 Question: What machine or instance am I using ?? SQL> Select name from v$database.DB_VERSION(:VERSION.0.4.'TERMINAL') -------------------------------------------------------------AR0669 Question: How can I retrieve a random number ? SQL> select dbms_random.30) description from gl_sets_of_books Question: What DB version is on my machine ? SQL> VARIABLE VERSION VARCHAR2(50) SQL> VARIABLE COMPATIBILITY VARCHAR2(50) SQL> EXEC DBMS_UTILITY. SYS_CONTEXT('USERENV'. SQL> PRINT VERSION VERSION ---------------------------------------8.0 SQL> PRINT COMPATIBILITY COMPATIBILITY ---------------------------------------8. INSTANCE --------------------------------------------------------------------ARGP This variation will give you the machine name you are running on: SQL> Select sys_context('USERENV'.'DB_NAME') AS instance from dual. NAME --------ARGP also you can use this: SQL> select sys_context('USERENV'.LATEST_OPENED_PERIOD_NAME.:COMPATIBILITY) PL/SQL procedure successfully completed. RANDOM .0.
Useful DATE output SQL This format is yymmdd = year month day | hh24mi = 24 hour clock and minutes select to_char(sysdate.---------495129087 Question: What patches are loaded on our machine ? SQL> select * from AD_APPLIED_PATCHES Question: Am I setup for Multi-Org ? select multi_org_flag from fnd_product_groups.'yymmddhh24mi') from dual TO_CHAR(SY ---------0409141005 select to_char(sysdate.'hh24:mi:ss') from dual TO_CHAR( -------10:11:14 .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.