Delete duplicate of PL/SQL command result values
Hi all
I am working on SQL Developer 4.1 and using sub PL/SQL command to retrieve the unique values of Batch_No with matching data:
Row_ SELECT TO_NUMBER (ROW_NUMBER () (IN Batch_No ORDER)),
Batch_No,
Record_Source,
Create_Date,
Submitter
Of
(SELECT DISTINCT Batch_No,
RecSource Record_Source,
Get_Date_From_Remedy (Create_Date) Create_Date,
Submitter
OF VOD_SEET_Invoices
WHERE (Batch_No <>"NA")
) batch
UNION
Row_ SELECT TO_NUMBER (ROW_NUMBER () (IN Batch_No ORDER)),
Batch_No,
Record_Source,
Create_Date,
Submitter
Of
(SELECT DISTINCT Batch_No,
'Penalties' Record_Source,
Get_Date_From_Remedy (Create_Date) Create_Date,
Submitter
OF VOD_SEET_Penalties
WHERE (Batch_No <>"NA")
) batch
The output of the above query has many duplicates in Batch_No, no idea how to rewrite the above query so that only unique values of Batch_No to the associated data are retrieved without duplicates?
Thanks in advance,
Kind regards
Mona Fathy
For example...
If your logic is that "Penalties" must have priority over the other record (assuming another in this scenario) of the first query, if there is a record of penalties, then by doing the following:
Select row_number() (order Batch_No) Row_
Batch_No
Record_Source
Create_Date
Author
de)
Select row_number() over (partition by order of batch_no to decode (record_source, 'Penalties', 0, 1)): the nurse
batch_no
record_source
create_date
author
de)
Select Batch_No
Record_Source
Create_Date
Author
to select (separate Batch_No
RecSource Record_Source
Get_Date_From_Remedy (Create_Date) Create_Date
Author
of VOD_SEET_Invoices
where (Batch_No <> 'NA')) batch
Union
Select Batch_No
Record_Source
Create_Date
Author
to select (separate Batch_No
"Penalties" Record_Source
Get_Date_From_Remedy (Create_Date) Create_Date
Author
of VOD_SEET_Penalties
where (Batch_No <> 'NA')) batch
)
)
where rn = 1
determines a row_number in each batch_no, ordering sanctions first duplicate records, and other records.
Then the outer query takes just the first records of each batch_no by applying the "where rn = 1" clause.
The outer query then applies his own row_number compared to results sorted by batch_no.
Tags: Database
Similar Questions
-
I'm doing all the records in the small suitcase to eliminate the sensitivity of the data to display for example
(1) setting a day email set email = lower (email); who gives a unique constraint error
(2) I saw emails in duplicate with the following command
Select E-mail
enamel
where lower (email) in
(select lower (email)
enamel
Lower group (email)
view count (*) > 1) order by e-mail CSA;
(3) I want to delete duplicate entries as described in (2) with the sql statement because they are over 500 and if I start to remove manually it will take too much of my time
Thank you and best regardsSQL> create table t(email varchar2(100)) 2 / Table created. SQL> create unique index t_idx on t(email) 2 / Index created. SQL> insert into t values('[email protected]') 2 / 1 row created. SQL> insert into t values('[email protected]') 2 / 1 row created. SQL> insert into t values('[email protected]') 2 / 1 row created. SQL> insert into t values('[email protected]') 2 / 1 row created. SQL> insert into t values('[email protected]') 2 / 1 row created. SQL> commit 2 / Commit complete. SQL> select * from t 2 / EMAIL ---------------------------------------------------------------------------------------------------- [email protected] [email protected] [email protected] [email protected] [email protected] SQL> update t set email = lower(email) 2 / update t set email = lower(email) * ERROR at line 1: ORA-00001: unique constraint (SYSADM.T_IDX) violated SQL> delete 2 from t 3 where rowid not in (select rowid 4 from (select rowid,row_number() over(partition by lower(email) order by lower(email)) rno 5 from t) 6 where rno = 1) 7 / 3 rows deleted. SQL> update t set email = lower(email) 2 / 2 rows updated. SQL> select * from t 2 / EMAIL ---------------------------------------------------------------------------------------------------- [email protected] [email protected] SQL>
-
Error message when I run delete the query in SQL Server 2008.
Error message when I run delete the query in SQL Server 2008 SP3.
Error message:
MSG 0, level 11, State 0, line 0
A serious error occurred on the current command. The results, if any, should be discarded.I never got any problem since 5 years.
Please let me know what is the cause of the problem.
You can get a response better/faster if repost you your question in the instances of SQL Server dedicated from Microsoft here:
http://social.technet.microsoft.com/Forums/en-us/category/sqlserver .
Thank you. :)
(I'm sorry, but I can't move this thread for you because the two forums are working on separate platforms)
-
Apex - dbms_job.submit (Oracle) in SQL commands
I have connected to oracle apex (version 4.2.5.00.08) at the URL https://apex.oracle.com/pls/apex/f?p=4550:1:0:
I am trying to execute the procedure of dbms_job.submit through SQL Workshop-> SQL commands)
The code is as shown below
*************************************************************************************************************************
declare
-jobno number;
jobno varchar2 (20);
Start
dbms_job. Submit (work = >: jobno,)
This = > ' START
emp_pack.remove_dept (16);
END;',
next_date = > trunc (sysdate + 1).
interval = > 'trunc(sysdate+1) '.
);
-dbms_output.put_line ('Job No. :'||: jobno);
commit;
dbms_output.put_line ('Job No. :'|| is jobno);
end;
*************************************************************************************************************************
The procedure of package I'm talking in the parameter 'WHAT' is defined as shown below
create or replace package emp_pack is
process remove_emp()emp_id in NUMBER)
process remove_dept()dept_id in NUMBER)
end emp_pack ;
create or replace package body emp_pack
is
process remove_emp()emp_id in NUMBER( )
is
begin
delete from EMP
where EMP .EmpNo = emp_id ;
end remove_emp;
process remove_dept()dept_id in NUMBER( )
is
begin
delete from dept
where Dept .DeptNo = dept_id ;
end remove_dept
end emp_pack ;
*************************************************************************************************************************
while trying to run the piece of code (I'm passing avlaue from 35 to the jobno to the RUN time parameter) is the error I get
ORA-06502: PL/SQL: digital or value error: character string buffer too small
I tried to know everything, I have, but have not been able to determine what is causing the error. Help, please
Super weird... I just ran the following on apex.oracle.com and got "1 row (s) deleted', not 'treated statement."
declare l_job int; begin /* dbms_job.submit( l_job, 'begin delete from emp; end;' ); */ rollback; end;
-
SQL command not properly ended.
Hello
I have connected the aplication to the oracle database in developer j. I used the Insert buttons and validation included.
For debugging application it runs correctly. but sometimes it gives error sql command not completed successfully.
I checked the requests when it runs successfully, it runs the query ' insert into Schema_name.table_name (column names) values (?)'.
but when it gives an error it runs the query ' insert into Schema_name. Schema_name. Schema_name. Schema_name. Schema_Name.table_name(column names) VALUES (?) e
Can someone tell me what is the reason of it?
Thank you.Can you try to change your query of
SELECT CD_ID, Data_Type, Data_Value, Misc1, Misc2 FROM Sample_ADF_FinIQ_Common.Common_data
TO
SELECT CD_ID, Data_Type, Data_Value, Misc1, Misc2 FROM Common_data
Note that I deleted the schema name of the query. Specific no reason why you use in front of the table schema name (I assume that you have created the connection to the schema on which you perform these operations).
Arun-
-
How to get the sql query result?
Hello
Currently I use LV2012 to connect to an Oracle database server. After the Oracle Express and Oracle ODBC driver facilities/settings made.
I managed to use the SQL command to query the data through my command prompt window.
Now the problem is, how to do the same task in Labview using database connectivity tools?
I have build a VI to query as being attached, but I have no idea of what range to use to get the result of the query.
Please help me ~ ~
Here is a piece of code that I use to test the SQL commands, you can use the part that retrieves the results of sql.
It is also possible to get the rear column headers, but it's for the next lesson!
;-)
-
Running a SQL command in my bean class
Hi all
I use JDeveloper 12.1.2.0.0.
I have an interest in running a query in my method of bean. I did some research and I always have a code but it does not find the method that the method requires so I tried to add the query in my AppModule and I added my method as a data control, but how do I access and change my method of bean?
The page with the code that does not find the method: http://jjzheng.blogspot.pt/2010/11/run-single-query-in-application-module.html
Gives me: 'Method 'getDBTransaction' not found'
The page that creates my method as a data control: http://amit-adf-work.blogspot.pt/2013/09/how-to-execute-sql-using-adf-application.html
This is the right way? How can I run a SQL command in my bean class?
Kind regards
Frederico.
This is the code I am using
GET A METHOD OF PAGEDEF AND RUN
get the link containe
BindingContainer links is BindingContext.getCurrent () .getCurrentBindingsEntry ();.
get an Action or a MethodAction
Method of the class OperationBinding = bindings.getOperationBinding ("YourMethodAction");
If there are parameters to define...
Map paramsMap = method.getParamsMap ();
paramsMap.put ("param", "value");
execute the method
Method.Execute ();
List errors = method.getErrors ();
If (! errors.isEmpty ())
{
handle errors errors here is a list of exceptions!
}
no error return to normal work
Timo
-
ORA-06502: PL / SQL: numeric or value error: character string buffer too small
Dear friends,
We have a package customized for FTP PLSQL.
I get ORA-06502: PL/SQL: digital or value error: character string buffer too small when the FTP service running.
The FTP function call the HOST function that is in fact to launch the above mentioned error.
Here is the code for FTP and HOST functions.FUNCTION HOST(text_in IN VARCHAR2, result_out IN OUT VARCHAR2) RETURN BOOLEAN IS ret boolean; drun boolean; hid number; BEGIN dbms_output.put_line('host1 begin'); ret := HOST(text_in,result_out,hid,drun,1); if not drun then dbms_output.put_line('not derun'); return false; end if; dbms_output.put_line('after if'); return ret; END HOST;
FUNCTION GET_ENV(env IN VARCHAR2) RETURN VARCHAR2 IS res boolean; out varchar2(256); BEGIN res := HOST('echo '||env,out); return out; END GET_ENV;
FUNCTION HOST(text_in IN VARCHAR2, result_out IN OUT VARCHAR2, hostid IN OUT NUMBER , demrunning IN OUT boolean, maxlines IN NUMBER DEFAULT NULL) RETURN BOOLEAN IS tempid number; tempstat varchar2(10); n number; m number; retry number; mult number; timestamp_date date; lv_result_out varchar2(200); BEGIN --result_out := NULL; --fcxh76 demrunning := true; dbms_output.put_line('host2 begin'); select XXAR_SHELL_CMD_S.nextval into tempid from dual; hostid := tempid; dbms_pipe.pack_message(tempid); n := dbms_pipe.send_message('CMD'); dbms_pipe.pack_message(abs(maxlines)); dbms_pipe.pack_message(rtrim(text_in)); n := dbms_pipe.send_message ('CMD'||rtrim(to_char(tempid)),0); m := dbms_pipe.receive_message('CMDSTAT'||rtrim(to_char(tempid)),5); if m = 1 then demrunning := false; dbms_output.put_line('m=1'); result_out := 'ERROR : GLCC0005 presumed not running'; dbms_output.put_line('result_out - '||result_out); return FALSE; elsif m = 0 then dbms_pipe.unpack_message(tempstat); end if; if tempstat = 'ERROR' then dbms_output.put_line('tempstat = ERROR'); result_out := NULL; dbms_output.put_line('after result out'); return FALSE; end if; <<CHECK_AGAIN>> m := dbms_pipe.receive_message('RSLT'||rtrim(to_char(tempid)),0); if m <> 0 then goto CHECK_AGAIN; end if; if m = 0 then dbms_pipe.unpack_message(result_out); dbms_pipe.purge('RSLT'||rtrim(to_char(tempid))); return TRUE; else result_out := 'ERROR : Call to GLCC0006 failed'; return FALSE; end if; END HOST;
Here is the PLSQL block that I will carry out and also the output on this blockFUNCTION FTP (program_name in VARCHAR2, source_file in VARCHAR2, dest_file in VARCHAR2 default NULL) RETURN BOOLEAN AS fd utl_file.file_type; res boolean; res1 boolean; out varchar2(256); out1 varchar2(256); ftp_dnsname varchar2(50); ftp_user varchar2(50); ftp_pass varchar2(50); ftp_pre_opt varchar2(150); ftp_post_opt varchar2(150); ftp_override varchar2(150); destination_file varchar2(50); ftp_command varchar2(2000); ftp_main varchar2(2000); proc_id varchar2(10); fderr varchar2(100); rec varchar2(1024); temp_buf varchar2(100); base_source varchar2(100); log_dir varchar2(100) := get_env('$APPLCSF')||'/log'; fndc_logfile_dir varchar2(100) := 'FNDC_LOGFILE_DIR'; i number ; ftp_tried boolean; begin ftp_tried := false; dbms_output.put_line('begin'); for ftp_rec in ( select attribute1, attribute2, attribute3, attribute4, nvl(attribute5,' ') attribute5, nvl(attribute6,' ') attribute6, nvl(rtrim(attribute7),'put') attribute7 from fnd_flex_values where flex_value_set_id in (select flex_value_set_id from fnd_flex_value_sets where flex_value_set_name = 'CPC_FTPS' ) and flex_value like program_name ) LOOP dbms_output.put_line('Looping'); ftp_tried := true; ftp_dnsname := ftp_rec.attribute1; ftp_user := ftp_rec.attribute2; ftp_pass := ftp_rec.attribute3; destination_file := ftp_rec.attribute4; if dest_file is not null then destination_file := dest_file; end if; if destination_file is null then destination_file := base_name(source_file); end if; ftp_pre_opt := ftp_rec.attribute5; ftp_post_opt := ftp_rec.attribute6; ftp_override := lower(ftp_rec.attribute7); dbms_output.put_line('host'); res := HOST('echo $$',proc_id); dbms_output.put_line('proc_id - '||proc_id); dbms_output.put_line('after host'); base_source := rtrim(base_name(source_file)); dbms_output.put_line('host 1'); res := HOST('> '||log_dir||'/ftpcmd.'||proc_id || ' ; chmod 777 '||log_dir||'/ftpcmd.'||proc_id,out1); dbms_output.put_line('host 2'); res := HOST('> '||log_dir||'/ftpmain.'||proc_id || ' ; chmod 777 '||log_dir||'/ftpmain.'||proc_id,out1); dbms_output.put_line('host 3'); res := HOST('> '||log_dir||'/ftplog.'||proc_id || ' ; chmod 777 '||log_dir||'/ftplog.'||proc_id,out1); dbms_output.put_line('host completed'); ...... ...... ......
Output:declare lv_ftp_result boolean; begin lv_ftp_result := u.FTP('XXAR_REV_PA', ' ' || '/u07/app/qaoa083a/data/outgoing/xxar/PARECREV' || '/' || 'REVENUE_20120319014318.dat','REVENUE_20120319014318.dat'); IF lv_ftp_result THEN dbms_output.put_line('True'); ELSE dbms_output.put_line('False'); END IF; exception when others then dbms_output.put_line('in exception - '||sqlerrm); end;
The flow of execution goes like this:host1 begin host2 begin m=1 result_out - ERROR : GLCC0005 presumed not running not derun begin Looping host host1 begin host2 begin m=1 in exception - ORA-06502: PL/SQL: numeric or value error: character string buffer too small
1 FTP function called from PL/SQL block
2 inside of the FTP service, the Sub statement calls the HOST function
3. This HOST function in turn calls another function of overloaded HOST (code shown above).log_dir varchar2(100) := get_env('$APPLCSF')||'/log';
4. in the function overloaded with the HOST, the following statements are executed successfully, and FALSE is returned by the function
5. the remaining code in the FTP service is running and the HOST function is called again using the Sub statementdbms_output.put_line('m=1'); result_out := 'ERROR : GLCC0005 presumed not running'; dbms_output.put_line('result_out - '||result_out);
6.again, this HOST function in turn calls another function of overloaded HOST (code posted above).res := HOST('echo $$',proc_id);
7. this time, in the function overloaded host, ORA-06502 is thrown when the following statement is executed and the execution stops here that this exception is unhandled.
This statement is very successfully in the previous call to the function of HOST (step 4), but it fails now.result_out := 'ERROR : GLCC0005 presumed not running';
Any idea on why this error occurs in this scenario? Because the issue of memory?
DB Info:
Kind regardsOracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production
Anthony
Published by: Anthony Alix on March 20, 2012 08:53Hello
HOST (1) calls the function of MODERATOR (2) with his second parameter as result_out
The first time you call the function of host (1) in the function get_env you use
... out varchar2(256); BEGIN res := HOST('echo '||env,out); ...
out is big enough varchar2 (256)
The second time you call (1) HOST of the FTP function as:
... ftp_main varchar2(2000); proc_id varchar2(10); fderr varchar2(100); ... ... res := HOST('echo $$',proc_id); dbms_output.put_line('proc_id - '||proc_id); ...
Here, use you proc_id which is varchar2 (10)
And it's not big enough!
Kind regards
Peter
-
SQL command to define shared_pool_size
Dear Guru:
What is the sql command to define shared_pool_size = 400 MB
I try SQL command below, but not work
change the system shared_pool_size set = 400 M scope = both;
error = > ORA-02097 parameter is not editable because specified value is not valid.
ORA-04033 memory to push the pool.
Thanks in advance.user11403781 wrote:
Dear Guru:What is the sql command to define shared_pool_size = 400 MB
I try SQL command below, but not work
change the system shared_pool_size set = 400 M scope = both;error-online ORA-02097 parameter is not editable because specified value is not valid.
ORA-04033 memory to push the pool.Thanks in advance.
change the system shared_pool_size set = 400 M scope = spfile;
-
Hi I need help with my sql commands please.
1. build a query to list the name of the Department with pay the lowest.
2.construct a query to list the personnel number of the Manager (without duplicates) for managers who make more than twice the average salary of their employees
(Note that not all managers have a function of MANAGER).
I just need some advice please
Published by: 888669 on October 28, 2011 10:36888669 wrote:
I had the min() function before and I got a message error "function group is nested too deeply.Select dname, sum (sal) of the Department of inner join emp = dept.deptno emp.deptno group of dname with min (sum (sal));
Try:
select ... from .... group by deptno having sum(sal) <= ALL (SELECT sum(sal) from emp group by deptno)
-
How to delete duplicate records
Suppose I have a table with N columns and K TAB (K < N) for which I should not have duplicated (in other words, the K column can be a key primary candidated)
Can you give me a SQL query to delete duplicate records of TAB for columns K?
Thank you very much!remove the tab where rowid not in (select min (rowid) of the TAB group by k)
-
SUPERIOR service... ORA-00921: unexpected end of SQL command
Hello
get the below error.
SQL > @c:\test_user.sql;
Enter the user name value: mapple
old 1: DROP USER UPPER(&&USERNAME) CASE
new 1: DROP USER UPPER (mapple) WATERFALL
DROP USER UPPER (mapple) WATERFALL
*
ERROR on line 1:
ORA-00921: unexpected end of SQL command
you want to convert to uppercase in user input.
cant we use UPPER() function here?
How can we do?
RegardingNo, you can use the UPPER part.
Or do you need it. Oracle will automatically translate all identifiers (table names, column names, etc.) in uppercase, except if you wrap them in double quotes.
If you insist on the use of capital letters:Set sqlcase higher
send all your statements translated into letters on the server.
-------------
Sybrand Bakker
Senior Oracle DBA -
suppress the output of the sql command
Hello
is it possible that I can delete the output of a command sql in a pl/sql script? I want to only display the output of dbms_output in my file queued. I tried power off and power of the echo set termout, but I'm still getting messages like: modified etc. trigger that I would like to delete.
Thank you.LEAVE YOUR COMMENTS.
-
ORA-00900 - the SQL commands: invalid SQL statement
Hello world
I installed Oracle Xe on a Centos 5.5 host yesteday.
Installation was Ok, I can connect to the web interface on "http://127.0.0.1:8080 / apex / '.
But when I want to use sql commands, regardless of the input control, I have the "ORA-00900: invalid SQL statement" message.
I can enter the command "Show all", for example, in a terminal after SQL > command prompt, it works... but not in the web interface...
I tried to import the .sql, script trought the web interface, no much result, no display in the window.
Can someone help me,
Thank youShow all is NOT a SQL command is a command that I think, not a command from pl/sql, sql more... Why not try to do a select on a table is know YOU the schema...
Thank you
Tony Miller
Webster, TX -
Hi all
Can anyone help me please with the sql command.
Here is the example of the table:-
Please note that there is % of the letter ' to some account numbers.Table:- EMP *EMP_ID ACCOUNT_NUMBER ACOCUNT_NAME* 102 1658751S10 JOHN MILTON 103 18425335S3 ROSE MILTON 104 184344751S2 CHRISTOPHER MARK 125 20808778S2 SUE 145 224532472S1 ABDUL HALIM AHMAD 165 45216698 RABAB ABDUL 166 5896542 SURAYA AKTER 168 145879 TUHIN AHAMED 169 4578956 FREDERICK ADCOCK 170 4213588 ANDREW HILTON 105 805878997S3 WILLIAM ALLAN 108 98714739S2 KENNETH JOHN ANSTEY 109 1377658043S21 JILLIAN MINEAR BOURNE 111 19942551S12 ELIZABETH MARGARET BLOXHAM
I would like to remove % ' account number and the place, the account name.
After updating the result would be as below:
Please advice how would be to this day.EMP_ID ACCOUNT_NUMBER ACOCUNT_NAME 102 1658751 JOHN MILTON (S10) 103 18425335 ROSE MILTON (S3) 104 184344751 CHRISTOPHER MARK (S2) 125 20808778 SUE (S2) 165 45216698 RABAB ABDUL 166 5896542 SURAYA AKTER
Concerning
JoyI think that u inserted bad records in the table emp1.
Data also well account_number and account_name are interchanged. I think so
check your data
S
Maybe you are looking for
-
Videos Flash freezes and does not load
Nice day.. I've had this laptop for 2 years... until that a month ago, everything worked perfectly and well.Microsoft 'sent' various improvements and that's when things started to go wrong. My main problem is:nothing to do with videos, for example th
-
LabVIEW FPGA, 2015 compilation error
I've recently switched to LabVIEW 2015 and I'm working on OR myRIO. So also installed myRIO 2015 bundled software. The problem I have is that the compilation of fpga fails within 10 seconds. and the target Xilinx journal report is empty The first tim
-
We currently have a 9205 analog input module. I have several analog inputs (CSR) receive signals output of material. Recently, I discovered that if a piece of equipment is taken offline, creating an undefined signal for the data acquisition module, o
-
Reference Dell ST2220T 21.5 "Touchscreen Flat Panel Monitor
If you can't download the necessary drivers from the Dell support site, is compatible with this monitor in Windows XP? Or you install Windows 7 to use the features of the touch screen? Thank you!
-
Compaq presario 12xl410: disk removing hard compaq 12xl410
How can I remove the hard drive of the compaq presario 12 x 410?