SELECT COUNT (*) FROM...
HelloI added an oracle db in my project, but I want to have the number of lines in the comics so I decided to use the SELECT Count (*) FROM... command in the BeginIn, but it does not recognize the * so I wrote it in a business auto and nothing.
the problem says:
' * ' should not: S: S an idea?
Thank you
Hello
Try:
numberOfRows as Int
for each element in
SELECT count(*) as cnt
FROM customer
order by name
do
numberOfRows = element.cnt
end
Hope this helps,
Dan
Tags: Fusion Middleware
Similar Questions
-
SELECT count VS table1 (column1) select count (*) from table1
SELECT count VS table1 (column1) select count (*) from table1
Which is faster, or are they equal in the aspect of the effectiveness and the cost of memory?Hello
Reading this thread Øvre Asktom. You do not need to read anything except this, that would be perfectly answer to your question.
http://asktom.Oracle.com/pls/asktom/f?p=100:11:P11_QUESTION_ID:1156159920245
HTH
Aman... -
Select count (1) vs count (*) select
I apologize if this has been requested previously. Can someone tell me what is the difference between
as opposed toselect count(1) from <mytable>
?select count (*) from <mytable>
Thank youSelect count (1) in the table
is faster than
Select count (*) in the table
but as long as it is to write the statement - reason: you don't have to hit the shift key for writing a 1, while you need the SHIFT key to get a * ;-)
-
Another problem of mine, I hope we can clear the air:
I have 4-5 tables with different products, these products have a price. In another table, I have just a column with a value (my money). What I have to do, he chooses one product from each table and the sum of all should not be greater than my money? A randomization but how?
If you need to learn more, say please and I'll post an example, I need help thanksHello
You can create the source of the page as a SQL something like element:
WITH X AS ( SELECT ROWNUM RR, DRINKS.NAME || ' ' || DRINKS.PRICE || ' ' || F1.PRODUCT || ' ' || F1.PRICE || ' ' || F2.PRODUCT || ' ' || F2.PRICE || ' ' || DESERT.PRODUCT || ' ' || DESERT.PRICE OUTPUT FROM MONEY M CROSS JOIN DRINKS CROSS JOIN F1 CROSS JOIN F2 CROSS JOIN DESERT WHERE DRINKS.PRICE + F1.PRICE + F2.PRICE + DESERT.PRICE <= M.MONEY) SELECT X.OUTPUT FROM X WHERE X.RR = TRUNC(DBMS_RANDOM.VALUE(1, (SELECT COUNT(*) FROM X)))
Andy
-
Select DataSet from the pl/sql table
Hi Experts,
I need to create a metric of OEM 12 c extensions. I must create a pl/sql code that can return results to OEM.
The following code works in OEM. But the problem is that I need to create a permanent table for this case.
Could you please tell any other option available to do this without creating additional objects at the database level?
Based on the requirement of the OEM, the end of the script, I have to do something like ' open: 1 to select in the <>' to return the results in a table.
Thank you.
###########################################################################################
DECLARE
TYPE cur_type IS REF CURSOR;
CURSOR c1 IS
SELECT distinct (owner: '.) ' || queue_table) as queue_table FROM dba_queues;
l_cur_string VARCHAR2 (200);
C2 cur_type;
v_queue VARCHAR2 (128);
number of v_ready;
BEGIN
run immediately "remove sys.testing";
FOR v_queue_table IN c1 LOOP
l_cur_string: ='select q_name, count (*) from ' | v_queue_table.queue_table | ' where State = 0 or (State = 1 and sysdate > nvl (delay, enq_time)) q_name group ';
OPEN c2 FOR l_cur_string;
LOOP
C2-FETCH INTO v_queue, v_ready;
OUTPUT WHEN c2% NOTFOUND;
run immediately ' insert into sys.testing values (: v_queue,: v_ready) "using v_queue, v_ready;"
OPEN: 1 for select * from sys.testing;
commit;
END LOOP;
CLOSE C2;
END LOOP;
END;
###################################################################################
In addition, committing inside of cursor loops are false. You should never engage at the end of a business logic operation, NEVER in cursor loops.
Something along these lines (untested) is probably what you want:
var refcursor rc;
declare
SQL varchar2 (32767).
Start
SQL: = q'[select
table_name,
TO_NUMBER)
ExtractValue)
XmlType)
dbms_xmlgen. GetXml ("select count (*) c to ' |") table_name | ((' where State = 0 or (State = 1 and sysdate > nvl (delay, enq_time)) q_name group '))
(("/ LINES/LINES/C ')) County
from (select distinct owner |'.) ' || queue_table as table_name dba_queues)]';
Open: rc for sql.
end;
/
print rc;
-
What is the difference between count (1) selection of the tab and select count (*) tab;
994122 wrote:
Hello
SQL > set timing on
SQL > select count (*) of the emp
2 where deptno = 30;
COUNT (*)
---------------
6
Elapsed time: 00:00:00.01
SQL > select count (1) of the emp
2 * where deptno = 30
SQL > /.
COUNT (1)
-------------
6
Elapsed time: 00:00:00.01
See that both give the same time
Do you really think the 100th's of a second it takes 6 rows from counting will truly representative of the difference it takes actually?
Such a small data set cannot possibly show no difference to these larger units of time (in the calculation of terms where we have millions of instructions per second in lieu)
As the link to the FAQ provided in the response of Anton (first response on this thread) Watch, count (1) and count (*) are essentially the same, except that count (1) actually get re-written by the query re - write the step of the optimization to make it count (*).
Generally 'count (*)' makes more sense language, because it reads like "count" while "count (1)" reads as "count we ', which does not have as much good sense when you actually count all.
-
Get the select count (*) including zero '0 '.
Hi gurus,
I have the problem here, I have this request:
SELECT COUNT (t.column1) AS mycount.
To_char(t.CREATION_DATE,'MONTH') AS themonth
Table 1 t
WHERE the t.creation_date BETWEEN TO_DATE('01/01/2011') AND TO_DATE('09/07/2011') AND t.column1 > 0
GROUP OF TO_CHAR (t.creation_date, 'MONTH')
ORDER BY TO_DATE (TO_CHAR (t.creation_date, 'MONTH'), 'MONTH')
then I get this query result
MYCOUNT. THEMONTH
-------------- ----------------
JANUARY | 3
MARCH | 6
APRIL | 5
CAN | 9
JULY | 2
and I need like this
MYCOUNT. THEMONTH
-------------- ----------------
JANUARY | 3
FEBRUARY | 0
MARCH | 6
APRIL | 5
CAN | 9
JUNE | 0
JULY | 2
what I am doing wrong? or what I can add to the code? Please, I hope you can help with this one.
Best regards
MentorMentor wrote:
Hey and when I don't have a date range and did well id how can I get the result?
SELECT NVL(COUNT(column1),0) mycount, TO_CHAR(TRUNC(creation_date,'MM'),'MONTH') themonth FROM ( SELECT column1, creation_date FROM table1 WHERE column_id IN (2,3,12,67,49,182) AND column1 > 0 UNION ALL SELECT NULL column1, ADD_MONTHS(min_creation_date,LEVEL - 1) creation_date FROM ( SELECT TRUNC(MIN(creation_date),'MM') min_creation_date, TRUNC(MAX(creation_date),'MM') max_creation_date FROM table1 WHERE column_id IN (2,3,12,67,49,182) AND column1 > 0 ) CONNECT BY ADD_MONTHS(min_creation_date,LEVEL - 1) <= LAST_DAY(max_creation_date) ) GROUP BY TRUNC(creation_date,'MM') ORDER BY TRUNC(creation_date,'MM') /
>
and another question, how can I get the two counts of the same column where the condition its diferent?
SELECT NVL(COUNT(CASE column2 WHEN 'JOHN' THEN 1 END),0) count_a, NVL(COUNT(CASE column2 WHEN 'MICHAEL' THEN 1 END),0) count_b, TO_CHAR(TRUNC(creation_date,'MM'),'MONTH') themonth FROM ( SELECT column2, creation_date FROM table1 WHERE column2 IN ('JOHN','MICHAEL') UNION ALL SELECT NULL column2, ADD_MONTHS(min_creation_date,LEVEL - 1) creation_date FROM ( SELECT TRUNC(MIN(creation_date),'MM') min_creation_date, TRUNC(MAX(creation_date),'MM') max_creation_date FROM table1 WHERE column2 IN ('JOHN','MICHAEL') ) CONNECT BY ADD_MONTHS(min_creation_date,LEVEL - 1) <= LAST_DAY(max_creation_date) ) GROUP BY TRUNC(creation_date,'MM') ORDER BY TRUNC(creation_date,'MM') /
SY.
-
My query:
SELECT distinct ap.project_files_location, ddh.file_name, dur.*
Of admin_project ap
INNER JOIN hard dmand_user_report on dur.admin_project_oid = ap.admin_project_oid
INNER JOIN dmand_docsys_hier on ddh.admin_report_oid = dur.admin_report_oid ddh
WHERE ddh.file_name = '_TESTFILE.pdf' and ap.project_files_location = '_Monthly_Reports\\' and dur.admin_user_oid = 983
Product 5 lines. I want to choose the number of rows produced by this query in a variable. How do you do that?
Thank youWell, there are many possible solutions...
The simplest one:
If you already know that the query returns 5 lines then you can:myvar := 5;
You can choose the number in a variable:
select count(*) into myvar from ( SELECT distinct ap.project_files_location, ddh.file_name, dur.* FROM admin_project ap INNER JOIN dmand_user_report dur on dur.admin_project_oid = ap.admin_project_oid INNER JOIN dmand_docsys_hier ddh on ddh.admin_report_oid = dur.admin_report_oid WHERE ddh.file_name = "_TESTFILE.pdf" and ap.project_files_location = "_Monthly_Reports " and dur.admin_user_oid=983 )
You can have a variable from PL/SQL table and bulk get all inside recods. Then you can check the number of records in the table using PL/SQL. COUNTING method:
SELECT distinct ap.project_files_location, ddh.file_name, dur.* BULK COLLECT INTO mytabofrecords FROM admin_project ap INNER JOIN dmand_user_report dur on dur.admin_project_oid = ap.admin_project_oid INNER JOIN dmand_docsys_hier ddh on ddh.admin_report_oid = dur.admin_report_oid WHERE ddh.file_name = "_TESTFILE.pdf" and ap.project_files_location = "_Monthly_Reports " and dur.admin_user_oid=983; myvar := mytabofrecords.COUNT;
You can also use "implicit cursor attribute" SQL ROWCOUNT % as in the example below:
INSERT INTO mynewtable SELECT distinct ap.project_files_location, ddh.file_name, dur.* FROM admin_project ap INNER JOIN dmand_user_report dur on dur.admin_project_oid = ap.admin_project_oid INNER JOIN dmand_docsys_hier ddh on ddh.admin_report_oid = dur.admin_report_oid WHERE ddh.file_name = "_TESTFILE.pdf" and ap.project_files_location = "_Monthly_Reports " and dur.admin_user_oid=983; myvar := SQL%ROWCOUNT;
Need more options?
-
SELECT conditional from 2 tables
Hi all
What it the best way to apply this logic to SELECT when I'll select the folder with the unique ID of t_good REC but exist in other t_change with the same ID REC i ' l must be selected from there.
Something as IF it EXISTS, don't know how it works in Oracle. I see that I can REACH all records in table 2 and check them later, but might be much simpler?
TXIf record with REC-ID exist in t_change Select * from t_change else Select * from t_ups_good
TrentSince we do not know the data structure and you have no examples, we are a little limited to providing you with options. Because we are not sure how or where you do this, we are still limited to offering suggestions. That said, my first thought is to use a Union all.
Select * from t_change where recid = [recid] Union All Select * from t_ups_good where (Select Count(1) From t_change where recid = [recid]) = 0
-
How to select data from a remote database table?
Hi friends,
I think I've seen before a sqlplus program that can select data from a remote database table?
Witnessed: IP, SID, PORT
The following is correct?
(I am connected to a local database)
SELECT COUNT (*) IN THE EMP@IP:SID/PORT;
Thank you very much
Ms. KSalvation;
I think, that you can create dblink wihtout any problem yet, it's a PROD. After your selection, you can drop dblink
Respect of
HELIOS -
Pl/sql script and select count()
Hello!
Is it possible somehow to put the result of (Select Select) count (h.id) in the "utl_file.put_line" (?)
in this script, plsql?
declare
cursor kursori is
SELECT count (h.id), n.state
OF popperson h, popnationality n
WHERE n.state > 3 and (n.state < 246) or n.state > 246
and h.registerstate = 1 and h.id = n.state group n.poppersonid;
Tietue kursori % ROWTYPE;
tiedosto utl_file.file_type;
Start
tiedosto: = utl_file.fopen (' TEST_OUTPUTDIR ',' test.txt ', 'W');
Open kursori;
loop
extract the kursori in tietue;
When the output kursori % NOTFOUND;
() UTL_FILE.put_line
tiedosto, 'Code '. Tietue. State | ' ' || Tietue. ?) ;
end loop;
close kursori;
UTL_FILE.fclose (tiedosto);
end;
/
Thank you! OVdeclare cursor kursori is SELECT count(h.id) cnt, n.state FROM popperson h, popnationality n WHERE n.state > 3 and (n.state < 246 or n.state > 246) and h.registerstate=1 and h.id=n.poppersonid Group by n.state; tietue kursori%ROWTYPE; tiedosto utl_file.file_type; begin tiedosto := utl_file.fopen ('TEST_OUTPUTDIR','test.txt', 'W'); open kursori; loop fetch kursori into tietue; exit when kursori%NOTFOUND; utl_file.put_line ( tiedosto, 'Code ' || tietue.state || ' ' || tietue.cnt); end loop; close kursori; utl_file.fclose(tiedosto); end; /
p.s: not tested.
Concerning
REDA
-
Select count (1) in empty_table
Hi all
I would like to know why "select count (1) of empty_table ' extractions value 0 instead of return null when the empty_table isn't contains anydata?
Thank youHello
A query that uses an aggregation (such as COUNT) function will produce a line of production by group, unless you discard some groups with a HAVING clause.
If you do not have a GROUP BY clause, there will be a group (which includes the entire results set) and therefore a row of output.
COUNT always returns an integer, never NULL.If you really need 0 lines of output in this situation, add a HAVING clause:
SELECT COUNT (1) FROM empty_table HAVING COUNT (*) > 0 ;
If you really need an output line, but NULL in the column NUMBER, use NULLIF:
SELECT NULLIF ( COUNT (1) , 0 ) FROM empty_table ;
-
Stored error for a SELECT COUNT... in proc
DB version: 10 gr 2
I was getting error when compiling for a stored procedure for the
under IF condition
I don't get this error in DB2. It seems that in Oracle, I need put the result of this COUNT in a variable and use it in the IF condition. Is there an alternative? Why Oracle can't handle such a SELECTION within the AOC?if (select count(1) from ship_trk_dtl where order_id = p_orderid and order_status =110) > 0 then ...
the error was
Published by: kraljic on March 4, 2009 04:05LINE/COL -------------------------------------------------------------------------------- ERROR -------------------------------------------------------------------------------- 128/9 PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe LINE/COL -------------------------------------------------------------------------------- ERROR -------------------------------------------------------------------------------- <an alternatively-quoted string literal with character set specification> <an alternativ 129/35 PLS-00103: Encountered the symbol ")" when expecting one of the following: * & - + ; / at for mod remainder rem <an exponent (**)> and or group having intersect minus order start union where connect || multiset
Hello
Born to be used IN the clause to store the code SQL train in a variable. You can use the varuiable with IF.
SQL> DECLARE 2 a NUMBER(2); 3 BEGIN 4 SELECT COUNT(*) INTO a FROM DUAL; 5 DBMS_OUTPUT.PUT_LINE(a); 6 END; 7 / PL/SQL procedure successfully completed. SQL> set serveroutput on SQL> / 1 PL/SQL procedure successfully completed. SQL>
See you soon,.
-
Is it necessary that 'we should select count (*)' before deleting the recor
Hai...
I need to delete a record in my application for which I wrote a process of pl/sql below...
DECLARE
Symbol varchar2 (20);
CTN number (1);
BEGIN
Symbol: =: P1_HIDDEN_FLAG;
Select count (*) in ctn to emp1 where EMPNO = symbol;
If NTC > 0 then
Remove from emp1 where EMPNO = symbol;
End if;
End;
why we must select count (*) table... If we try to remove a record that is not available in the table... How can we handle this Exception? There are also that "we should select count () before you delete the record from the table... *"
Please tell me...
David...Hello
You can use SQL % number of LINES:
delete from emp where empno = p; if sql%rowcount = 0 then -- Nothing deleted! end if;
Greetings,
Roelhttp://roelhartman.blogspot.com/
http://www.bloggingaboutoracle.org/
http://www.Logica.com/ -
Use of bluetooth, how to copy selected music from my Macbook 2009 to my new iMac
Using bluetooth, how can I copy selected songs from iTunes in my old Macbook to my new iMac? (It might help us to let you know that I don't buy music from the iTunes store). Thanks in advance for your advice.
How old is the MacBook? Support AirDrop? If this isn't the case, then the simplest method would be to use a flash drive to move audio files selected from the MacBook to the iMac.
Maybe you are looking for
-
MacBook Pro warmer with ethernet
I just tried with (instead of WiFi) ethernet cable to the internet on my MacBook Pro so that I can download large files without interruption. I noticed that whenever I do that, my MacBook is significantly warmer. Not as bad as if I had to play a vide
-
Artist tri - iTunes 12.3
Hello My iTunes is a little messed up and for a few months now. Whenever I have add a new song, it sorts as a new artist, even if they have exactly the same name (I checked all the different fields etc.) So that means that I found with about 8 variat
-
ThinkPad Yoga 15 Intel wireless AC 7265
I searched the forums and other sources to fix my wifi problems (verification of drivers, changing the adapter setttings etc.) without success. Other devices in the same position and the same access point get positive signals (quality 75% +) and conn
-
Active Protection system for Windows 7 64-bit?
a unique software, it seems such a practice, but why it is not available for users of windows 7 64-bit? When do we expect to get out
-
Just today my wireless worked perfectly no problems at all. And then I'll be back from College 4 hours later and it seems not to work more, I called cisco and they want to charge me to fix it, and I don't have the money for it. I tried reseting the r