Coil in SQL * Plus with SQL statements
Hi guru,.
Greetings.
I work 10 R2 Solaris oracle
I have the file new.sql having count (*) select statements of 10000 +. I want the result with the sql statement in the coil. How?
New.SQL
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE;
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE_GROUP;
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE_GROUP_TR;
....
....
Coil new.txt
@new.sql
spool off
Spooled results is
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE;
COUNT (*)
----------
199
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE_GROUP;
COUNT (*)
----------
220
SELECT COUNT (*) IN XYZ. CPEP_ARTICLE_GROUP_TR;
COUNT (*)
----------
0
but I'm getting plain County, I need select statement and respective numeration.
How to get it. could you help on this.
Thank you
REDA
Like this.
Select "double ==>" | Count (*) twice;
Tags: Database
Similar Questions
-
Several SQL statements with zero executions in the region of SQL
Hello
one of my databases has a large number of statements in the SQL box with zero executions. Some of them analyzed several times without a single run. Why the database stores these statements and how to avoid or reduce them?
My problem is that the only time or zero time sql statements take the largest part of the area of sql:
-sql statement and only once and without executing sql statements
Select
Count (1) num_sql_total,.
sum (decode (executions, 1, 1, 0)) num_one_use_sql,.
sum (decode (executions, 0, 1, 0)) num_no_use_sql,.
Sum (RUNTIME_MEM) / 1024/1024 mb_used,.
sum (decode (executions, sharable_mem, 1, 0)) / 1024/1024 mb_for_one_use_sql,.
sum (decode (executions, 0, sharable_mem, 0)) / 1024/1024 mb_for_no_use_sql
Of
GV$ sqlarea
where
RUNTIME_MEM > 0;
NUM_SQL_TOTAL NUM_ONE_USE_SQL NUM_NO_USE_SQL MB_USED MB_FOR_ONE_USE_SQL MB_FOR_NO_USE_SQL 23318
8739
8027
1420,95619106293
381,41183757782
530,999855041504
Concerning
Thomas
This is not unusual. Another app could analyze for example hard the most often used SQLs in upstairs app - making benefit of further processing (in theory) of sweet analysis when you use these SQLs.
In fact, I remember reading something to this effect as a performance for some factor or another Oracle document or note?
So unless you have serious questions of shared pool, why bother with these sliders? What would be the problem?
-
Copy SQL statement to another database with the same SQL_ID
Is there a reliable way to copy a sql statement in a database to another preserving the formatting so it ends with the same SQL_ID.
I want to copy a statement of the shared pool to a test database to develop a plan to import sql database in production.
In the past, I just did ' select sql_fulltext from v$ sql "in SQL Developer and pasted the result into a spreadsheet SQL Developer and run it. The statement is now in the pool shared with the correct sql_id.
This does not work for instruction, I am currently in train. It ends with a different id of sql.
I know it's probably a problem of formatting, but the statement is 1000 characters and a manual check will take forever.
You could put in a SQL Tuning Set and transfer it.
-
Need an example of loop with sql statement in shell script values
Hello
I have to present a simultaneous program to each line of the table through script shell (only).
The table has all the parameters required to pass to the concurrent program.
I have trouble in a loop with the lines of sql statement results.
Could someone give me an example of a shell script with a loop with the sql statement values.
appreciate your time and your help.
Thank you
Ganesh
Hello
Here is a guide using 3 parameters:
{
sqlplus-s $OA_USR / $OA_PWD<>
SET THE OFF POSITION;
SET FEEDBACK OFF;
SET LINESIZE 300;
SELECT param1, param2, param3
Of your_param_table;
ENDOFSQL
} | while reading line
do
If ['$line'] # line non-NULL
then
set $line
param1 = "$1."
param2 = "$2."
param3 = "$3."
# Pass parameters to a script, sql more
sqlplus-s $apps_usr / $apps_pwd @SUBMIT_CONC_PROG.sql $param1 $param2 $param3
FI
fact
}
In your SQL * more script you run 3 parameters into variables:
declare
VARCHAR2 (10) param1: = ' & &1';
VARCHAR2 (10) param2: = ' & &2';
param3 varchar2 (10): = ' & &3';
.....
-
SQL statement to filter with the value of State of Session
Hello..
I need to filter a SQL statement with an application retrieved from session state item value. I guess I could do this using a dynamic Action on a Page load event, but I don't know where to go from here. How could I add the filter to a report page existing SQL statement?Reference should / could be exactly like you reference page elements. I use the: variable_name format myself.
If you are satisfied, please mark as answer.
Best wishes,
Howard -
Help with a SQL statement...
Hello...
I have tried to find a way to write a SQL statement and may not seem to produce something that works. What I need is a set of results that returns each month that a given task is in an open State. The only columns that I have in my work table with are TASK_NM, OPEN_DT and CLOSED_DT.
So if I have a line containing the following: TASK_NM = 'task one', OPEN_DT = April 18, 10 ' and CLOSED_DT = 14 October 10 '... I would like to see as a result set that looks like:
TASK_NM YEAR JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV DEC
the task of a 2010 0 0 0 1 1 1 1 1 1 1 0 0
Is it still possible?
Thanks in advance,
David.
Published by: user13027968 on March 10, 2011 14:19
Published by: user13027968 on March 10, 2011 15:13Hello
Welcome to the Forum!
Whenever you have a question. Please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.
For example, the sample data may be:CREATE TABLE table_x ( task_nm VARCHAR2 (10) , open_dt DATE , closed_dt DATE ); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('task a', DATE '2010-04-18', DATE '2010-10-14'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-10-31', DATE '2011-01-01'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2010-12-01', DATE '2011-02-21'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('foo', DATE '2011-04-01', DATE '2011-04-30'); INSERT INTO table_x (task_nm, open_dt, closed_dt) VALUES ('bar', DATE '2010-01-01', DATE '2010-01-01');
From this data, you may want these results:
TASK_NM YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OVT NOV DEC ---------- ----- --- --- --- --- --- --- --- --- --- --- --- --- bar 2010 1 0 0 0 0 0 0 0 0 0 0 0 foo 2010 0 0 0 0 0 0 0 0 0 1 1 1 foo 2011 1 1 0 1 0 0 0 0 0 0 0 0 task a 2010 0 0 0 1 1 1 1 1 1 1 0 0
I'm not sure eactly how you plan to use it. Are there lines that overlap for the name of the task? You always want the same number of columns? What version of Oracle are you using?
I think you want something like this:WITH got_month_cnt AS ( SELECT task_nm , TRUNC (open_dt, 'MONTH') AS first_month , 1 + MONTHS_BETWEEN ( TRUNC (closed_dt, 'MONTH') , TRUNC (open_dt, 'MONTH') ) AS month_cnt FROM table_x -- WHERE ... -- If you want any filtering, put it here ) , cntr AS ( SELECT LEVEL AS n FROM ( SELECT MAX (month_cnt) AS max_month_cnt FROM got_month_cnt ) CONNECT BY LEVEL <= max_month_cnt ) , all_months AS ( SELECT m.task_nm , ADD_MONTHS ( m.first_month , c.n - 1 ) AS open_month FROM got_month_cnt m JOIN cntr c ON c.n <= m.month_cnt ) SELECT task_nm , EXTRACT (YEAR FROM open_month) AS year , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jan' THEN 1 ELSE 0 END) AS jan , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Feb' THEN 1 ELSE 0 END) AS feb , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Mar' THEN 1 ELSE 0 END) AS mar , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Apr' THEN 1 ELSE 0 END) AS apr , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'May' THEN 1 ELSE 0 END) AS may , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jun' THEN 1 ELSE 0 END) AS jun , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Jul' THEN 1 ELSE 0 END) AS jul , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Aug' THEN 1 ELSE 0 END) AS aug , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Sep' THEN 1 ELSE 0 END) AS sep , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Oct' THEN 1 ELSE 0 END) AS ovt , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Nov' THEN 1 ELSE 0 END) AS nov , MAX (CASE WHEN TO_CHAR (open_month, 'Mon') = 'Dec' THEN 1 ELSE 0 END) AS dec FROM all_months GROUP BY task_nm , EXTRACT (YEAR FROM open_month) ORDER BY task_nm , year ;
This will work in Orfacle 9 (and), but from Oracle 11, you could simplify it a little bit by using SELECT... Function PIVOT.
Published by: Frank Kulash, March 10, 2011 16:51
-
Date range of calculation with the SQL statement
I'm sure that there is a way to do this in SQL, but I can't understand it. I can write a PL/SQL script to do it, but prefer to use a SQL statement. My database is the database of Oracle 10.2.0.4.0.
I have a table that contains information such as employee number, service id, and date effective start-up of the person in this Department. There are data in another table I want to update their department number in based on their date of entry in the range. If I could figure out how to correctly select the entry into force, I can do the rest.
I have data such as:
EMP_ID DEPT_NO EFFECTIVE
-------------- ----------------- ---------------------
101 1000 1/15 / 2001
1050 101 5/24 / 2005
101 2010 6/8/2008
101 1000 8/2/2010
I want to write a SELECT statement that returns something like this where the end_date is the eve of the ENTRY into force and the last record didn't an end_date because they are always assigned to this service. In addition, the first record in the column, I won't choose a DEPT_NO because the logic of the entry into force has been added in January 2001, he says if a person started in 1985 they might have zero departments at several times so I won't update all data for this period:
EMP_ID DEPT_NO EFFECTIVE END_DATE
--------------- ---------------- ---------------- ----------------
101 1/14 / 2001
101 1000 1/15 / 2001 5/23/2005
1050 101 5/24 / 2005 6/7/2008
101 2010 6/8/2008-8/1/2010
101 1000 8/2/2010
Here is a script to create the data into a temporary table which can be used to write a SELECT statement. I added two records of employees with different dates.
create the table temp_activity
(emp_id number (12),)
dept_no number (12).
(entry into force);
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(101,1000,to_date('1/15/2001','MM/DD/YYYY'))
/
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(101,1050,to_date('5/24/2005','MM/DD/YYYY'))
/
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(101,2010,to_date('6/8/2008','MM/DD/YYYY'))
/
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(101,1000,to_date('8/2/2010','MM/DD/YYYY'))
/
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(102,1040,to_date('1/15/2001','MM/DD/YYYY'))
/
INSERT INTO temp_activity
(EMP_ID, DEPT_NO, ENTERED INTO FORCE)
VALUES
(102,2000,to_date('6/16/2006','MM/DD/YYYY'))
/
Any help is appreciated. It's probably easy, but I can't get my brain wrapped around it.
Thanks - mikeselect emp_id, dept_no, effective, end_date from ( select emp_id, dept_no, effective, lead(effective) over(partition by emp_id order by effective) - 1 end_date, row_number() over(partition by emp_id order by effective) rn from temp_activity union all select emp_id, null dept_no, null effective, min(effective) - 1 end_date, 0 rn from temp_activity group by emp_id ) order by emp_id, rn / EMP_ID DEPT_NO EFFECTIVE END_DATE ---------- ---------- ---------- ---------- 101 01/14/2001 101 1000 01/15/2001 05/23/2005 101 1050 05/24/2005 06/07/2008 101 2010 06/08/2008 08/01/2010 101 1000 08/02/2010 102 01/14/2001 102 1040 01/15/2001 06/15/2006 102 2000 06/16/2006 8 rows selected. SQL>
SY.
-
Dear Experts,
I need a clarification. Is it possible to use the fn - bea: function execute sql (Oracle Service Bus) to perform an insert operation in a database with the data extracted from the message of the Organization (i.e. $body/Info/username)? If it is possible which is the right syntax?
Any suggestion is appreciated.
Kind regards
Mike
Published by: ITDeveloper on November 19, 2009 2.55
Published by: ITDeveloper on November 19, 2009 3.01Hi Mike,.
Please refer to my post for the same question to the fn - bea: sql performance with 'Insert INTO' the sql statement
Thank you best regards &,.
Vivek
-
With the help of a number variable in a SQL statement
Hello
I am trying to use a variable in a sql statement, and I ran into problems when the variable is a number. The following line of code works if the variable is a string, but not if it is a number.
"SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID = '" + Locals.LocalUnitID + "' ORDER BY DESC START_DATE_TIME.
Is there a difference in the use of single and double quotes and the sign for numbers variables +?
Thank you
Stuart
Jervin is almost correct in the post above.
While it is correct that numbers in SQL are not enclosed in single quotes ('), we still need the entire expression to a string. If Locals.LocalUnitID is stored as a number to TestStand, you will need to cast to a string so that the string concatination works properly.
I believe that the correct form is as follows:
"SELECT PAGE 1 UUT_STATUS OF UNIT_UUT_RESULT WHERE UnitID ="+ Str (Locals.LocalUnitID) + 'ORDER BY DESC START_DATE_TIME'
-
Using the SQL with CFQUERY statement variable
I generate a SQL statement based on user input. I use loops, etc. to create the string of the current statement.
Once the SQL string is created I can display it on the screen and it seems fine.
If I copy the text that appears on the screen and paste it into a CFQUERY, it works very well.
BUT if I try to the variable output directly in the CFQUERY tags set string - it fails... what gives?
Here is the text of the string I am generating in a variable called #insertString #.
INSERT INTO atblProduct (PRODUCTTITLE, RELATEDPRODUCTS, PARTCODENAME, DISPLAY, PRODFAMILYID, DETAILEDDESCRIPTION, overview, APPLICATION type, SPECIALTAB) VALUES (' product ', '1,2,3', ' Code Name', 1, 1, 'Detailed Description', 'Preview', 1, 1)
in the code below, you will see how I try to run this sql using the variable in a CFQUERY tag. Do I need to use a CF function to ensure it is passed verbatim to the SQL engine?
< CFQUERY datasource = "mydb" >
#insertString #.
< / CFQUERY >Try the function PreserveSingleQuotes.
-
copy and paste the sql statement into sql * more
How do you paste the sql statement into sql * more... I tried the following options, get the windows interface for this sequel to the documentation below, but that did not work
http://download.Oracle.com/docs/HTML/A88829_01/ch3.htm
then I tried to create a simple .txt file with my sql statement and tried to run using @name (where name is the name of the file) and it gives me the following error SP2-0310: cannot open the file 'firstscriot.sql '.You name the file name.txt? Then you cannot start with @name, because SQL * PLUS will add the extension .sql
Try instead the @name.txt or name the file name.sql
And check if you have the correct path.
Concerning
Marcus -
Excuting multiple sql statements
Hi to everyone.
I am quite new to Oracle, even though I have a great experience with SQL and MySQL commands. I am facing a problem that I guess it's really Basic.
I got a dump of an Oracle database in a format .sql. I mean that the schema and data are built thanks to a large number of sql statements. In particular the schema is done by many 'create a table... '. «While the data are built through «insert into...» ». My need is to import these databases into a new Oracle Oracle 10 g XE database.
I installed it on a Debian system, and I can properly run a single SQL command both through the web interface http://localhost: 8080/apex and logging as user oracle through the name of sqlplus user/passwd command.
My problem is that the data is spread over approximately 12000 SQL «INSERT INTO...» "so all one by one run might be a bit boring :-)
< u > so I ask if there is a way to tell Oracle to execute multiple SQL statements he read a file (like MySQL for example). < /u >
I'm planning to write a script to do if there is no better way. I know there's no way to dump databases Oracle, but I can change the .sql format since it's the only one I had.in SQL * Plus you can run a SQL file with the start command or the abridged version: @
SQL> start filename.sql or SQL> @filename.sql
-
Game of demand does not pick up the good period open to active fixed from the SQL statement
Hello
We have a demand that could kick off the simultaneous application of the value: Ixr: list of asset by period and Ixr: reserve book report.
ON overall demand, we set the parameter: default period based on a SQL = select period_name from FA_DEPRN_PERIODS where book_type_code = 'PER2011' and period_close_date is null
The query runs with the good period, until we open the new period, the game application will still come closed period.
When I run this script on the database, it gives the correct name of the open period.
Why all the demand does not pick up the open period?
Rock
Hello
When planning, the parameter values that you gave when planning will not change.
For the test, for a simultaneous program, I create a parameter and has given the value 100 tank and default type sql statement and the value as below.
Select to_char (sysdate, 'dd-mon-yyyy hh24:mi:ss') of double
If, at the time of the program, it shows a default value such as the date and time with seconds. Then I planned it for every minute.
When you check in for each race it is seen the first time only, it does not.
so in your case, you must plan its new after change of period.
Hope this will help you...
-
What are these SQL statements?
Hello!
We are our applications running on Windows Server 2003 where it works fine, using Oracle via OCI 12.1.
Now, we have the application installed on Windows Server 2012 and it works very slowly.
When comparing these two environments trace files came a surprise: Oracle generates a lot of SQL statements when run on Windows Server 2012! By operating on Windows2003 it only executes the SQL from the applicaton instructions. These additional SQL statements must be the reason for the slowness, but why Oracle it generates them and how could we get arrested?
An example:
PARSING IN CURSOR #46985062096816 len = 210 dep = 2 uid = 0 oct = cover 3 = 0 tim = hv 1439277877325893 = ad 864012087 = "4db599f28" sqlid = "96g93hntrzjtr."
Select / * + rule * / bucket_cnt, row_cnt, cache_cnt, null_cnt, timestamp #, sample_size, minimum, maximum, distcnt, lowval, hival, density, col #, spare1, spare2, hist_head avgcln $ where obj #=: 1 and intcol #=: 2
END OF STMT
ANALYSIS #46985062096816:c = 1000, e = 456, p = 0, cr = 0, cu = 0, put = 1, r = 0, dep = 2, og = 3, plh = 0, tim = 1439277877325890
EXEC #46985062096816:c = 0, e = 498, p = 0, cr = 0, cu = 0, put = 1, r = 0, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326455
FETCH #46985062096816:c = 0, e = 56, p = 0, cr = 3, cu = 0, set = 0, r = 1, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326533
STAT #46985062096816 id = 1 cnt = 1 pid = 0 obj = op 411 = pos = 1 "TABLE ACCESS BY INDEX ROWID HIST_HEAD$ (cr = 3 pr = 0 pw = time 0 = 55 US)"
"STAT #46985062096816 id = 2 cnt = 1 pid = 1 pos = 1 obj = op 413 ='INDEX RANGE SCAN I_HH_OBJ #_INTCOL # (cr = 2 pr = 0 pw = time 0 = 32 US)"
OUTCOME #46985062096816:c = 0, e = 37, dep = 2, type = 3, tim = 1439277877326601
EXEC #46985062096816:c = 0, e = 23, p = 0, cr = 0, cu = 0, set = 0, r = 0, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326702
FETCH #46985062096816:c = 0, e = 18, p = 0, cr = 3, cu = 0, set = 0, r = 1, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326738
OUTCOME #46985062096816:c = 0, e = 8, dep = 2, type = 3, tim = 1439277877326765
EXEC #46985062096816:c = 0, e = 19, p = 0, cr = 0, cu = 0, set = 0, r = 0, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326837
FETCH #46985062096816:c = 0, e = 21, p = 0, cr = 3, cu = 0, set = 0, r = 1, dep = 2, og = 3, plh = 2239883476, tim = 1439277877326923
OUTCOME #46985062096816:c = 0, e = 10, dep = 2, type = 3, tim = 1439277877326954
Thank you very much in advance!
Best regards
Jaakko Terhonen
Thank you all for the reply! This time, the reason was a problem in network traffic (TCP protocol): a lot of retransmissions for a still unknown reason. If it had nothing to do with Oracle after all.
I cried for help here because as a common application programmer, I wasn't familiar with the Interior details of SQL analysis and after seeing it in the trace, I assumed that these strange SQL statements - which, for some reason, is appeared only in W2012-trace - were the reason for the slowness.
Thank you, I'm a little wiser now - and I hope that many others find this thread before asking the same question!
Best regards
Jaakko Terhonen
-
How can I pass a condition of the table in the sql statement?
For example, in the table in the COND Varchar2 column (200) there is the value ' VAR > 10'.
| COND |
|' VAR > 10' |
where VAR is the name of the table column. I would like to make statement CASE WHEN VAR > 10 AND 0... I tried with as subquery
WHEN BOX (SELECT COND FROM TABLE WHERE...) THEN 0, but it does not work.
Hello
You can do this by using dynamic SQL.
that is to say:
declare v_stm varchar2(4000); v_cond varchar2(100); v_result integer; begin select cond into v_cond from yourtable where a=1; v_stm := 'select case when '||v_cond||' then 0 ...'; -- dynamic sql execute immediate v_stm into v_result; end; /
Remember that, in general, dynamic SQL has a performance degradation that SQL static and should be avoided when possible.
Storage condition or the SQL statements in the tables is not a good practice.
Kind regards.
Alberto
Maybe you are looking for
-
I just downloaded and installed Thunderbird on a new computer Windows 8. I get the message in the title when I press the Get Mail button
-
How to stop a DQAmx read VI?
In the answer to the question 'wait for and relax first edge entering' digital, it was said that I can enter-1 to the DAQmx read to read the string for an indefinite period. (JPG added) If I do that the VI is "stuck" until I receive a signal on the c
-
I am unable to use standyby on my computer; It is not highlighted
When I go to "Turn off computer", I'm not allowed to choose the day BEFORE... Help
-
Got a blinking cursor every time that I reboot. Tried recovery of images minmized which reformats, copies / restores the files on the hard drive, but when he says that the next step is to reboot, and I do, it freezes at startup (HP Logo, single line
-
Drive for bitlocker decryption error
Hello I have a 2 to USB 3.0 external HARD drive Verbatim.It has been encrypted by using bitlocker in win7 64 bit.I wanted to transfer files from a XP computer which means that I had to disable bitlocker XP otherwise would not access the hard disk.And