Returns a record with a 0 if no row is returned by the query
HelloI use oracle 10g.
Please forgive me if this is a crazy question
select null ltd, 'aig' company from dual
where sysdate = to_date('6/13/2011','mm/dd/yyyy')
Is it possible to get the following resultltd company
null aig
or the followingltd company
0 aig
Thanks in advance
You can use UNION ALL and add line if the query returns nothing.
WITH T
AS (SELECT NULL ltd, 'aig' company
FROM DUAL
WHERE SYSDATE = TO_DATE ( '6/13/2011', 'mm/dd/yyyy'))
SELECT * FROM T
UNION ALL
SELECT 0 ltd, 'aig' company
FROM DUAL
WHERE NOT EXISTS (SELECT * FROM T)
G.
Tags: Database
Similar Questions
-
When no rows returned in the query loop, replace Null - need help
Hello
I have a requirement where I have a request in the loop for and based on the results of the query, I do some operations.
But even if the query does not match, I should get back something like 'No Data'.
My loop is:
FOR V_SL IN)
SELECT ID, CATEGORY, DI_CD, REV_CD, SL_ID
OF SB, SLOT_2001 S2 SLOT_DATA WHERE
PBM BENEFIT_ID = S2. BENEFIT_ID AND
REV_CD = IN_REV_CD AND
(PROC_CD IS NULL OR PROC_CD = IN_PROC_CD)
ORDER OF DIAGCODE, PROCEDURECODE)
LOOP
END LOOP;
I do some operations inside the loop for. I want the loop to run even if the query returns no rows.
Can someone help me out here.
Thank you
RambeauFrank. I am really surprised to see this coming from you. A slider to not find all the lines loop does not cause an exception no_data_found.
-
Get the columns returned by the query without running
I have a table that stores SELECT queries in a column. I developed a .net application where the interesting thing for the user is what columns of the following SELECT statement returns. Currently, I load the sql as an OracleCommand object CommandText and fill a DataTable using an OracleDataAdapter object. I then read the names of the columns of the table filled. The data is not fully used. Requests can take up to 15 seconds to run. Because I do not used the data, I was hoping to eliminate the actual recovery of data and reduce the time needed to retrieve the records. Is it possible to analyze the statement for the colunm names with it makes the request for enforcement? Thank you.I imagine that there is a way you can search in the data dictionary, but you can also try to add 'WHERE 1 = 0' If you want the metadata.
It will be useful,
Greg -
Disable the generation of report when there are no returned by the query
I would like to write a preliminary report trigger that disables reports generation when my main query in my data model will return no data. If possible, I would like to reuse the same query in the data model from the writing of a motion to double again.
Thank you allCreate a view for the main request. In this case, you just have to do it in the front trigger of the report:
select count(*) into my_var from my_view where ...; if my_var = 0 then return false; else return true; end if;
In where clause you can use the same settings as in your main report query.
-
Return of the query classification
This sounds like it should be simple. I want to be able to classify data in a query in return. Currently I have:
SELECT salesID, sale
Of allmembers
ORDER BY sales DESC
< cfset salesRank = 0 >
< cfoutput >
< cfset salesRank = #salesRank # + 1 >
< cfquery >
INSERT INTO rankings (salesID, salesRank)
VALUES (' #salesID #', #salesRank #)
< / cfquery >
This places the seller ID and access to his rank in the League table. My question is how can I manipulate links? If two people or more have the same value of sale I would like that they all have the same rank. Then the person after them would have its correct classification.
example of
John has a rank of 1. Bob, Chris, and Tom all related and have not 2 but 4 rankings. Then the next person after them would have a rating of 5 (unless there's another link.
How can code in search for links and classify correctly. It is similar to how the tournament golfers are classified.
Here is an example that determines rank according to my previous post:
-
Need help to write a MySQL query that returns only the peer matching records
Because I don't know how to explain it easily, I use the table below as an example.
I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.
Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.
How can I create a query that will do it?
ID | col1 | col2
--------------------
1. ABC | DEF
2. DEF | ABC
3. ABC | IGS
4. DEF | IGS
5. IGS | DEF
* Please let me know if you have no idea of what I'm trying to explain.I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.
SELECT a.col1,
a.col2
FROM table_name AS a
LEFT OUTER
Table_name JOIN b
ON b.col1 = a.col2
AND a.col1 = b.col2
WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '. -
By comparing the two records and return only the differences
Hi all!
Assume the records as follows:
UserID is PK on this table. Imagine that this application represents two versions of the same record on a table. This recording was 'day' and the phone field changed from null to "(31) 234-1234'.»USERID USERNAME STREET CITY PHONE ---------- ---------- -------- ------ ------------- 1 John Smith Street 1 City 1 1 John Smith Street 1 City 1 (31) 234-1234
What I´d like to do is to retrieve only (or fields) that changed between these 2 versions of the same record. The idea is to call this query (or process PLSQL) a trigger and save these data on a table. The data returned by the query (or process), on the example above, should be something like:
If two columns have been modified, (Eg., City column also changed "City 1' to 'city 12'), the return value should be:USERID USERNAME STREET CITY PHONE ---------- -------- ------ ---- ------------- 1 (31) 234-1234 1 row selected.
Any idea?USERID USERNAME STREET CITY PHONE ---------- -------- ------ ------ ------------- 1 City12 (31) 234-1234 1 row selected.
Thank you very much for your attention.Hello
What I´d like to do is to retrieve only (or fields) that changed between these 2 versions of the same record. The idea is to call this query (or process PLSQL) a trigger and save these data on a table.
Looks like you're simply wanting a trigger?
Something like:
CREATE OR REPLACE TRIGGER audit_trg AFTER UPDATE ON your_table FOR EACH ROW BEGIN INSERT INTO audit_table(userid, username, street, city, phone) VALUES( :new.userid, nullif(:new.username, :old.username), nullif(:new.street, :old.street), nullif(:new.city, :old.city), nullif(:new.phone, :old.phone) ); END; /
-
Problem with case when try to alter the query from siimple
Hello PL/SQL gurus and Experts.
I'm stuck with a question (can be simple), but not gettings all headsway.
value returns is as - 1.46select 365/day_num_yr Anul_Fact from Date where date_dt = trunc(sysdate -1)
need to write it in the form of case (I have to multiply it to some other outer query), I want to store variable ina and then use the same in an outside -.
but when use the following syntax, then it always returns 0 and not the same output returned by the query above without the scabbard.
Help kindly, I appericate your time and effort in advance.select (case when date_dt =trunc(sysdate -1) then 365/day_num_yr else 0 END) Anul_Fact
user555994 wrote:
Problem is that I do not get the output as 1.46, even the output is coming like the 0 only if using the query - nextselect /*date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,*/ case when date_dt = trunc(sysdate -1) then 365/day_num_yr else 0 end num_day from date_dim;
Completely, which seems to be a question of DATA. Have you checked if the table contains data for DATE_DT = SYSDATE - 1? Can you check if the data stored do not have hours and Minutes stored?
Although I have provided examples of data, which is the same as the data in my main table and once I used the previous solution you provided and then also gives the result as same as those mentioned by you.
I think it's something like -
select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt, case when date_dt = trunc(sysdate -1) then 366/day_num_yr where day_num_yr=(select day_num_yr from date_dim where date_dt = trunc(sysdate -1)) else 0 end num_day from date_dim;
Once we get the day_num_yr then he deviding by 366/day_num_yr :(
but he does not like throwing an error ORA-95 - missing keywordYes, it does not work
-case when date_dt = trunc (sysdate-1) then 366/day_num_yr where day_num_yr = (select day_num_yr from the date_dim where date_dt = trunc (sysdate-1))
due to a syntax of alien.
I don't think that you really need. I already said, with the data in your Table, you will be having only * 1 * record with a Non - zero value. Thus, simply apply a filter to extract the corresponding record SYSDATE - 1 and you should get an output which is Non-zero. If you apply a where predicate, then would not need you a CASE statement. You can directly use something like below:select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt, 365 / day_num_yr num_day from t4 where date_dt = trunc(sysdate - 1);
Published by: Jen K, September 7, 2012 16:00
-
Function returning the query takes longer to run in Apex4.0
Hi all
I've created a report using the function returns the query. The function returns the query based on parameters that returns the dynamic columns. When I run the query in sql developer the query generates and returns the result in 3mins. But in the apex, it takes 35 minutes maximum to return.
The query returns about 10000 lines.
What a performance problem in the query or Apex? can someone help plz
Concerning
REDANo it's just the first tranche of 500. You can run it in good old SQL * more and the total time of the time (be patient however)
-
Return only the records with a string of text that is less than a certain value?
Hi people,
I'm not sure whether this is possible or not, but worth-
I need to be able somehow output only the lines with the text of a column field less to (because of the arguments) 30 characters (including spaces). I know that I can use CFs Left() function to cut the chain, but I don't want to have words cut off mid-sentence. Therefore, I want to somehow restrict the query to only the records that contain a string of less than 30 characters.
Is this possible?
Thanks in advance :-)You can use the length of the db function. It may or may not be named LEN()
SELECT SomeColumn
FROM YourTable
WHERE LEN (SomeColumn)<=>=>Or you can retrieve all of the records and use one of the functions of the chain at cflib.org as FullLeft().
http://www.cflib.org/UDF.cfm?id=329 -
Sony Handycam DCR-HC52 will play tapes recorded with dcr-hc38
Sony Handycam DCR-HC52 will play tapes recorded with dcr-hc38
Thank you
Hey trip,.
Welcome to the community of Sony!
Yes, the DCRHC52 will make playback tapes recorded with the DCRHC38 Handycam. Both models record in MiniDV format, and all Handycam that records in this type of format or backward compatible units can play their return.
If my post answered your question, please mark it as "accept as a Solution. Thanks_Mitch
-
Mr President.
What is wrong with this sequence, it does not work when, after 3 inserts, I add a new record with the trigger it gives an error.
--SL_CUSTOMERS table data INSERT INTO SL_CUSTOMERS VALUES(1,'Kamrul Hasan',NULL,NULL,'Moghbazar', 'Dhaka','0456789123',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(2,'Rabiul Alam',NULL,NULL,'Motijheel', 'Dhaka','0567891234',NULL,NULL,NULL,'Y',NULL); INSERT INTO SL_CUSTOMERS VALUES(3,'Shahed Hasan',NULL,NULL,'2-G/1,2-2,Mirpur', 'Dhaka','0678912345',NULL,NULL,NULL,'Y',NULL);
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW BEGIN IF :NEW.CUSTOMER_ID IS NULL OR :NEW.CUSTOMER_ID < 0 THEN SELECT SL_CUSTOMERS_SEQ.nextval INTO :NEW.CUSTOMER_ID FROM DUAL; END IF; END; /
When I try to insert several records with the seq.nextval it gives error
violation of primary key.
INSERT INTO "ALIZA"."SL_CUSTOMERS" (CUSTOMER_NAME) VALUES ('sdfsd') ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1 One error saving changes to table "ALIZA"."SL_CUSTOMERS": Row 4: ORA-00001: unique constraint (ALIZA.SL_CUSTOMERS_PK) violated ORA-06512: at line 1
Concerning
Mr President.
I find the solution by creating a function before the triiger
as below
CREATE SEQUENCE "ALIZA"."SL_CUSTOMERS_SEQ" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE ; CREATE OR REPLACE FUNCTION get_SL_CUSTOMERS_vId RETURN VARCHAR2 AS BEGIN RETURN SL_CUSTOMERS_SEQ.NEXTVAL; END; / CREATE OR REPLACE TRIGGER SL_CUSTOMERS_TRG BEFORE INSERT ON "ALIZA"."SL_CUSTOMERS" FOR EACH ROW DECLARE dummy VARCHAR2(200); BEGIN dummy := get_SL_CUSTOMERS_vId(); :NEW.CUSTOMER_ID := dummy; END; /
It works very well
Thank you all for the suggestions.
Concerning
-
have a multi-record with several unrelated elements blocking, filled by simply calling
Forms of oracle, I have a form with a block of several recording, with several unrelated elements.
One of these non-is a basic formula element.
The formula for this article fills the others not consolidated items.
A procedure with several out parameters is called.
For example
: cmr.id (now the unique id of a database record)
: cmr.unbound_dummy, with the formula f_fill_blk_unbound_items(:blk.id)
: cmr.unbound_adres
: cmr.unbound_contactperson
function f_fill_blk_unbound_items (p_id in customers.id%type)
Return number
is
number of l_rc;
Start
customer_pck.get_adres_and_contactperson
(p_id = > p_id - IN)
, p_adres = >: cmr.unbound_adres - OUT
, p_contactperson = >: cmr.unbound_contactperson - OUT
);
Return (0);
end;
QUESTION: How can I do something similar in the APEX; have a blocking of multi-record with several elements not related, filled by calling a procedure with several out parameters?The suggestion refers to functions in pipeline
http://www.Oracle-Developer.NET/display.php?ID=207This will allow you to select your information you need in a query like
SELECT * FROM TABLE(table_function)
It should also more powerful than the example of forms.
Scott
-
by comparing the records with another table
Hello
I have the following 2 tables (test_prs & test_dep) and registers
My goal is to compare test_prs with test_dep records and return the records that are not in test_dep
Here is the table scripts
I tried the following query to meet my criteria. My output should be null, but all recordscreate table test_prs (id ,p_id ,r_id) as select 1,200566,200566 from dual union all select 2,200567,200567 from dual create table test_dep (id,de_typ,de_id,de_u_typ,de_u_id) as select 10,'AS',200566,'PG',200566 FROM DUAL UNION ALL select 11,'AS',200567,'PG',200567 FROM DUAL insert into test_dep select 12,'AS',400189,'PG',400273 FROM dual union all select 13,'AS',400273,'PG',400250 FROM dual union all select 14,'AS',400273,'PG',400192 FROM dual union all select 15,'AS',400273,'PG',400191 FROM dual insert into test_prs select 3,400273,400273 from dual
Could you please help me the sameselect * from test_prs prs where exists (select 1 from test_dep de where de.de_id !=prs.p_id and de.de_u_id !=prs.p_id )
Published by: smile on 7 March 2012 15:00Smile says:
Thanks for the requestThe query does not work with the following documents
insert into test_dep select 16,'AS',750664,'PG',750758 FROM dual insert into test_prs select 4,750758,750668 from dual
the r_id should not be put in correspondence with the columns in the test_dep table. P_id must only be put in correspondence
OK, you want to match against the de_id and the de_u_id p_id? Or a line where either p_id concordances r_id de_u_id or de_id must not be returned?
To match p_id against de_id and de_u_id, you can write the query like this:
select id, p_id, r_id from test_prs where p_id in (select p_id from test_prs minus select de_id from test_dep minus select de_u_id from test_dep);
Brgds
Johan -
Query to find records with more than 2 decimal places.
Output:-I have written the below query to find records with more than 2 decimal places, but it is returning records with decimal places 1 & 2. The datatype of the AMT column is NUMBER (without any precision). SELECT amt FROM amount_table WHERE substr(amt, instr(amt, '.')) LIKE '.%' AND length(substr(amt, instr(amt, '.') + 1)) > 2
AMT
* 41591.1*
* 275684.82*
* 64491.59*
* 3320.01*
* 6273.68*
* 27814.18*
* 30326.79*
131.8413635
162.5352898
208.5203816
8863.314632
22551.27856
74.716992
890.0158441
2622.299682
831.6683841
* 1743.14*
2328.195877
3132.453438
5159.827334
3.236234727
37.784
Thanks
Hello
user1585440 wrote:
when i inserted fee_amt as 41591.0999999999 it is displayed as 41591.1 in the output i.e, insert into amount_table (line_number,fee_amt) values (100,41591.0999999999); select fee_amt from amount_table where line_number = 100. this query shows the output as below fee_amt 41591.1 The fee_amt column has number as datatype (without precision) Why it is automatically shown rounded off as 41591.1?
Published by: user1585440 on December 28, 2010 04:50
You use SQL * more your front end?
SQL * Plus has a fixed width to display all columns. The default for numbers is 10 characters. If necessary, SQL * Plus will be round a number or the use of scientific notation, to represent the number of the expected number of characters.
You can use the SQL * more "SET NUMLARGEUR" to change the default view for all the numbers of orders, or "COLUMN" to set a sepcific format in an individual column.
If you explicitly convert your channel numbers in a query, SQL * Plus adjusts the column width to whatever is needed. For exampleSELECT TO_CHAR (fee_amt, 'TM') AS fee_amt_d
"TM" is the default format; You can call TO_CHAR with a single argument, if you prefer.
Maybe you are looking for
-
One of my two Firefox Windows is stuck at halfway offscreen
I am running Vista, fully updated. I have two windows open in firefox, both with ten legs. I was moving around and accidentally moved one half out of the screen. Now he is stuck there, and whenever I try to bring him back, he moves slightly, then fre
-
NEET to put in place the gray button. Several people seem to have the same problem. Don't see the answer?
-
IOS app in iTunes 12 deleting will remove them from the iPhone as well (iOS 9)
Then... I have not been able to find an answer to this question and I'm a little paranoid to try it with so many apps on my iPhone 6. I am currently using iTunes 12.3 and iOS 9.2. I have about 60 GB of apps on my years iTunes download, and if I delet
-
my phone (samsung RV410-T01) stop automatically. I removed the battery when I was with her. and then it stopped and I can't open it with a battery or even I plug.
-
How to replace the onMenu methods?
Hi, I can simply call to some Menu key methods: this.getScreen () .onMenu (0); Menu-key has a few methods, also "close." is it possible to change it? Kind regards