Oracle Query Always return records
I want to have an Query In Which i always want to return one records regardless of exitence.
If no records exist ...it should appear as
NAME ID
0 0
if records exit it should appear as
NAME ID
manish 1
Hi,
You can do that with a UNION of your real query and something that selects the default values from dual. Just be sure the second part returns 0 rows when the real query returns anything.
WITH real_query AS
SELECT name
, id
FROM table_x
WHERE ...
SELECT *
FROM real_query
UNION ALL
SELECT '0' AS name
, 0 AS id
FROM dual
WHERE NOT EXISTS (
SELECT 1
FROM real_query
;As always, be careful that the two prongs of the UNION have the same number and types of columns in the SELECT clause.
Similar Messages
-
Restrictive query always returns no rows
I am trying to run a query with a where clause, but I'm always getting no rows returned. I am obviously overlooking something. Here are my scripts that are on the employee dept tables.
The scripts run without any errors and when I do a 'select * from dept_xml' I get the complete XML output. However if I run the query
select * from dept_xml
where existsNode(sys_nc_rowinfo$, '/DEPT_T[DEPTNO=40]') = 1
no rows returned
WHY??
drop type emp_t force
drop type emplist_t force
drop type dept_t force
drop type deptlist_t force
drop type depts_t force
CREATE OR REPLACE TYPE emp_t AS OBJECT
EMPNO NUMBER(4),
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(8,2),
COMM NUMBER(8,2)
CREATE OR REPLACE TYPE emplist_t AS TABLE OF emp_t
CREATE OR REPLACE TYPE dept_t AS OBJECT
DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13),
EMPS EMPLIST_T
CREATE OR REPLACE TYPE deptlist_t AS TABLE OF dept_t
CREATE OR REPLACE TYPE depts_t AS OBJECT
DEPTS DEPTLIST_T
begin
dbms_xmlschema.deleteSchema('http://www.oracle.com/depts.xsd', 4);
dbms_xmlschema.registerSchema('http://www.oracle.com/depts.xsd', dbms_xmlschema.generateschema('SCOTT','DEPT_T'),TRUE,FALSE);
end;
CREATE OR REPLACE VIEW dept_xml OF XMLTYPE
XMLSCHEMA "http://www.oracle.com/depts.xsd" ELEMENT "DEPT_T"
WITH OBJECT ID (sys_nc_rowinfo$.extract('/DEPT_T/DEPTNO').getNumberVal())
AS
SELECT dept_t(d.deptno,
d.dname,
d.loc,
cast(multiset(SELECT emp_t(e.empno,
e.ename,
e.job,
e.mgr,
e.hiredate,
e.sal,
e.comm)
FROM emp e
WHERE e.deptno = d.deptno)
AS emplist_t))
FROM dept d;#1. I would strong recommend using the SQL/XML operators (XMLElement, XMLForest etc)to define your view, rather than creating SQL Types. We will be focusing future development on improving the performance and functionality of the SQL/XML operators, so these operators are now the preferred approach.
#2 Please post the XML document that is generated by teh view. I suspect that the XPATH expression does not match the generated docuemnt. -
Count query always return value 1
Hi all,
I got the following sql command :-
select count(*)
from mtl_txn_request_lines mtrl
WHERE mtrl.date_required >= to_date(:fdate || '00:00:00','DD-MON-YYYY HH24:MI:SS') and mtrl.date_required <= to_date(:Tdate || '23:59:59','DD-MON-YYYY HH24:MI:SS')
and mtrl.header_id = :header_id1
however when I put into the report, the count value always show 1. ( :header_id1 is the key search from another query ).
Rgds
Limdid you get 1 when you run it on sql/plus too?
-
Oracle query running very slow
Hi,
We've MS-Access application which was pointing to UDB. Now we migrated it to point Oracle DB 9.2. After migration some of the query is running very slow.
These queries used to take less than 30 seconds in UDB now taking more than 5 Minutes in Oracle.
some more obeservation :
(1) Some of the queries using "HAVING" clause without any aggregate function. When I moved this condition to "WHERE" clause, performance improved a lot.
But problem is that I can't suggest this solution to "USERS". They are creating query using "query wizard" in MS-Access and they started creating noise on this.
(2) I tested same MDB in two different PCs and same query is returning records in 4 seconds in one system, is taking more than 10 minutes in other system.
Since I'm new to MS-Access, I don't know what other information I need to provide here.
Please help me out.ms wrote:
Hi All
I am using Oracle 11g . My table contains 10-12 lac rows.Do not use the word lac: it is common in the Indian sub-continent but not known much outside of
there because it is not standard English.
>
1) what is the difference between a index on one column and an index of number of columns ( i.e composite index). The obvious answer of one contains only one column and the other contains more than one.
2) For what columns in a where clause should index be created ( single columns index or composite index ).Depends
3) Also can u suggest how to improve the perfomane of thsi query?Please read: SQL and PL/SQL FAQ
which tells you how to ask a performance related question -
Returning Records Only for the Current Month
Hello,
I have a query that returns records for the current week and I would like to extend it to return records for the current month.
where TRUNC (START_DATE) < NEXT_DAY (TRUNC (CURRENT_TIMESTAMP) - 1, 'Sat') + 1
AND TRUNC (END_DATE) > NEXT_DAY (TRUNC (CURRENT_TIMESTAMP) - 1, 'Sat') - 7
I have two date fields, the first is called 'Start_Date', the second is called 'End_Date'. I would like the query to return all records for the current month including those that may begin prior to or finish post the month as events can begin in one month and end in another. Does anyone know how this is done in a 'Where Clause'?
Kind Regards,
Steve WelchActually LAST_DAY(ADD_MONTHS(TRUNC(sysdate),-1))+1 gives you the starting day of the current month, and LAST_DAY(TRUNC(sysdate)) gives you the last day of the current month.
So the where be
WHERE TRUNC(START_DATE) >= LAST_DAY(ADD_MONTHS(TRUNC(sysdate),-1))+1 OR TRUNC(END_DATE) <= LAST_DAY(TRUNC(sysdate))
Start Date >= 1st Day of Month OR End Date <= Last Day of Month, meaning either date is within the current month. -
Returning records based on the max timestamp
I am writing a query to return records for each dat with max timestamp. so the query must return 1 record for each day with the latest timestamp. I am doing a partition over the timestamp column and wondering which analytic func gives the fastest result. This is in a data warehouse environment where there may be millions of recs.
thanksMy sample table has 3 columns - deptno, deptdesc, and eff_ts. There may be multiple rows for each day but I want to pick only the first (or last) record for each day.
This is one query I am thinking about using analytic functions.
SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
select FIRST_VALUE(eff_ts)
OVER (PARTITION BY trunc(eff_ts) ORDER BY eff_ts) eff_ts FROM test_dates)
I can also use max (or min) timestamp and do a group by.
SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
select min(eff_ts) FROM test_dates group by trunc(eff_ts))
Which is better (or is there any other better way) to use in a data warehousing env? -
Global Temp Table, always return zero records
I call the procedure which uses glbal temp Table, after executing the Proc which populates the Global temp table, i then run select query retrieve the result, but it alway return zero record. I am using transaction in order to avoid deletion of records in global temp table.
whereas if i do the same thing in SQL navigator, it works
Cn.ConnectionString = Constr
Cn.Open()
If FGC Is Nothing Then
Multiple = True
'Search by desc
'packaging.pkg_msds.processavfg(null, ActiveInActive, BrandCode, Desc, Itemtype)
SQL = "BEGIN packaging.pkg_msds.processavfg(null,'" & _
ActiveInActive & "','" & _
BrandCode & "','" & _
Desc & "','" & _
Itemtype & "'); end;"
'Here it will return multiple FGC
'need to combine them
Else
'search by FGC
SQL = "BEGIN packaging.pkg_msds.processavfg('" & FGC & "','" & _
ActiveInActive & "','" & _
BrandCode & "',null,null); end;"
'will alway return one FGC
End If
' SQL = " DECLARE BEGIN rguo.pkg_msds.processAvedaFG('" & FGC & "'); end;"
Stepp = 1
Cmd.Connection = Cn
Cmd.CommandType = Data.CommandType.Text
Cmd.CommandText = SQL
Dim Trans As System.Data.OracleClient.OracleTransaction
Trans = Cn.BeginTransaction()
Cmd.Transaction = Trans
Dim Cnt As Integer
Cnt = Cmd.ExecuteNonQuery
'SQL = "SELECT rguo.pkg_msds.getPDSFGMass FROM dual"
SQL = "select * from packaging.aveda_mass_XML"
Cmd.CommandType = Data.CommandType.Text
Cmd.CommandText = SQL
Adp.SelectCommand = Cmd
Stepp = 2
Adp.Fill(Ds)
If Ds.Tables(0).Rows.Count = 0 Then
blError = True
BlComposeXml = True
Throw New Exception("No Record found for FGC(Finished Good Code=)" & FGC)
End If
'First Row, First Column contains Data as XML
Stepp = 0
Trans.Commit()Hi,
This forum is for Oracle's Data Provider and you're using Microsoft's, but I was curious so I went ahead and tried it. It works fine for me. Here's the complete code I used, could you point out what are you doing differently?
Cheers,
Greg
create global temporary table abc_tab(col1 varchar2(10));
create or replace procedure ins_abc_tab(v1 varchar2) as
begin
insert into abc_tab values(v1);
end;
using System;
using System.Data;
using System.Data.OracleClient;
class Program
static void Main(string[] args)
OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger");
con.Open();
OracleTransaction txn = con.BeginTransaction();
OracleCommand cmd = new OracleCommand("begin ins_abc_tab('foo');end;", con);
cmd.Transaction = txn;
cmd.ExecuteNonQuery();
cmd.CommandText = "select * from abc_tab";
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Console.WriteLine("rows found: {0}", ds.Tables[0].Rows.Count);
// commit, cleanup, etc ommitted for clarity
} -
Cascading LOV always returns first row in af:query
HI
JDEV 11.1.1.3.0
A strange thing is happening with my cascading LOV which is input text with LOV.
I have a read only table with a query section. I then also bring up any of the tables rows in a popup with single record view where the row is then in an af:form for inserting and updating.
Both the af:query and af:form have the cascaing LOV in them.
When testing the cascading LOV in the BC Browser it works fine. When I use it in the popup in the af:form record it works fine. But in the af:query section, no matter which row I choose in the LOV, it always returns the 1st row of the LOV back to my input text component.
Has anyone experienced this...any ideas?
Thanks,
MarioAha...and the above log message lead me to the solution!! :-)
The VO is based on an Oracle data dictionary view, DBA_TAB_COLUMNS. When you create the read only VO, by default it does not create any of the attributes as "key" attributes, because the oracle view has no primary key.
Setting owner, tableName and columnName as key attributes solved this issue, now my cascading LOV works in the BC Tester, af:query component and my af:form component.
Regards,
Mario -
Select query on table rcv_lots_interface is always returning null
Hi ,
I need a help on the below issue.
The issue is after creating PO in Oracle 11i I receive it in MSCA application.
When we receive it at that point data gets inserted in the table " rcv_transactions_interface " and we have written a trigger on it.
From the trigger on table " rcv_transactions_interface " we are calling a package and in the package we have select query on "rcv_lots_interface."
But the select query is always returning null even though we are passing the correct "interface_transaction_id " and also after the "Receiving Transaction Processor" is executed i can see data in the table " RCV_LOT_TRANSACTIONS " for the same transaction.
Below is the sample code i am using.
CREATE OR REPLACE TRIGGER inv.RCV_TRAN_TRIGGER
AFTER UPDATE
ON po.rcv_transactions_interface
FOR EACH ROW
WHEN (NEW.processing_status_code='PENDING'
AND NEW.destination_type_code IN ('INVENTORY','RECEIVING')
AND NEW.mobile_txn = 'Y')
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
v_user_id NUMBER;
v_interface_transaction_id NUMBER;
v_organization_id NUMBER;
v_item_id NUMBER;
v_quantity NUMBER;
v_resp_id NUMBER;
v_mobile_txn VARCHAR2(5);
v_shipment_header_id NUMBER;
v_bill_of_lading VARCHAR2(100);
v_group_id NUMBER;
v_header_interface_id NUMBER;
BEGIN
v_interface_transaction_id := :NEW.interface_transaction_id;
v_organization_id := :NEW.to_organization_id;
v_user_id := :NEW.created_by;
v_item_id := :NEW.item_id;
v_quantity := :NEW.quantity;
v_resp_id :=fnd_profile.VALUE('RESP_ID');
v_transaction_type := :NEW.transaction_type;
v_mobile_txn := :NEW.mobile_txn;
v_bill_of_lading := :NEW.bill_of_lading;
v_group_id := :NEW.group_id;
v_header_interface_id := :NEW.HEADER_INTERFACE_ID;
INV.INV_RCV_TRX_PKG.INV_RCV_LABEL_GEN_PRC( v_user_id,
v_interface_transaction_id,
v_item_id,
v_quantity,
v_organization_id,
v_resp_id,
v_shipment_header_id,
v_bill_of_lading,
v_header_interface_id,
v_group_id);
END;
CREATE OR REPLACE PACKAGE BODY INV.INV_RCV_TRX_PKG
AS
PROCEDURE INV_RCV_LABEL_GEN_PRC( p_user_id IN NUMBER,
p_interface_transaction_id IN NUMBER,
p_item_id IN NUMBER,
p_quantity IN NUMBER,
p_organization_id IN NUMBER,
p_resp_id IN NUMBER,
p_shipment_header_id IN NUMBER,
p_bill_of_lading IN VARCHAR2,
p_header_interface_id IN NUMBER ,
p_group_id IN NUMBER
IS
v_user_id NUMBER;
v_print BOOLEAN;
v_resp_id NUMBER;
v_resp_appl_id NUMBER;
v_lot_num VARCHAR2(50);
BEGIN
BEGIN
SELECT application_id
INTO v_resp_appl_id
FROM apps.fnd_responsibility_tl frt
WHERE responsibility_id=p_resp_id;
END;
apps.fnd_global.apps_initialize(p_user_id, p_resp_id, v_resp_appl_id);
BEGIN
SELECT rli.lot_num , rli.expiration_date
INTO v_lot_num ,
v_expiration_date
FROM apps.rcv_lots_interface rli
WHERE rli.interface_transaction_id = p_interface_transaction_id ;
EXCEPTION
WHEN OTHERS THEN
v_lot_num :=NULL;
v_expiration_date :=NULL;
apps.fnd_file.put_line(fnd_file.log,'Exception while deriving LOT Number ######### '||p_interface_transaction_id||'------'||SQLERRM);
END;
END;
Need your help to understand why the below query is always returning null and what is the solution for it ?
SELECT rli.lot_num , rli.expiration_date
FROM apps.rcv_lots_interface rli
WHERE rli.interface_transaction_id = p_interface_transaction_id ;
Thanks
Jaydeep
Edited by: user10454886 on Mar 25, 2013 6:31 AM
Hi ,
I need a solution to this issue at the earliest.
Appreciate all of your help
Thanks
JaydeepCentinul wrote:
There are a lot of bugs listed in Metalink with respect to wrong results and function-based indexes.
Here are a few:
Bug 4028186 Wrong results if function based index exists
Bug 4717546 Wrong results / poor plan when function based index exists
Bug 5092688 Wrong results if function based index exists
Based on reviewing them the workarounds range from dropping the index to setting "_disable_function_based_index" to TRUE.Facinating. It seems to me that if you use the undocumented intitialization parameter you might just as well drop the FBIs too.
Another hazard of FBIs is the Law of Unintended Consequences. 2 years ago we tried to use one to speed up a query in a PL/SQL package. Worked OK for that purpose, but an unrelated loader on the affected table ran and rand but never finished until the FBI was dropped. -
Query returns record in SQL Developer but not in iSQLPlus
... back in a minute, I may not have done a commit at the end of the insert.
The problem I was having was I hadnt commited the record in SQL Developer but the queries where returning records in this environment but not in iSQLPlus or Apex and it was confusing me.
Message was edited by:
Benton
Message was edited by:
BentonFinally got to know the reason why Timezone Abbr woudn't show up in SQL Plus.
I ran below query in SQL PLUS
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP, systimestamp, LOCALTIMESTAMP FROM DUAL;
SESSIONTIMEZONE CURRENT_TIMESTAMP SYSTIMESTAMP LOCALTIMESTAMP
-05:00 08-SEP-12 12.00.31.575228 AM -05:00 08-SEP-12 12.00.31.575223 AM -05:00 08-SEP-12 12.00.31.575228 AM
Now executed the same query in SQL Developer:
SESSIONTIMEZONE CURRENT_TIMESTAMP SYSTIMESTAMP LOCALTIMESTAMP
America/Chicago 08-SEP-12 12.08.32.072424000 AM AMERICA/CHICAGO 08-SEP-12 12.08.32.072420000 AM -05:00 08-SEP-12 12.08.32.072424000 AM
The difference between the 2 outputs is the way in which time_zones were respresented. In SQL PLUS, it is shown as an offset whereas in SQL Developer as a time zone region name. Now there are many "time sone regions" that follow an offset of -5:00. This confuses Oracle and a "UNK"(Unknown) for a query like the one below when trying to execute in SQL PLUS:
select extract(timezone_abbr from from_tz(cast(sysdate as timestamp),SESSIONTIMEZONE)) from dual;
EXTRACT(TI
UNK
Therefore we need to specify the exact Time Zone Region(TZR) in order to obtain the corresponding TZD(Daylight Savings Format i.e. CDT or CST). This we do by altering the session environment vaiable time_zone
alter session set time_zone='America/Chicago';
Now executing the queries to find the abbreviated time zone( in TZD format) will finally work to return a non-null char value.
select extract(timezone_abbr from from_tz(cast(sysdate as timestamp),SESSIONTIMEZONE)) from dual;
EXTRACT(TI
CDT
select to_char(CURRENT_TIMESTAMP, 'TZD') from dual;
TO_CHA
CDT -
Oracle:JDBC Call returns no results, SQL*Plus returns 1 record, Please help
Any help would be greatly appreciated.
Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
Query:
SELECT
ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
FROM
WEB_FRM
WHERE
ID_WEB_FRM = ' '
OR
(ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
AND NUM_WEB_PG_ID = 0)
Record returned from SQL*Plus:
ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
NfRRmc5XZu test u2T 1 0
Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
Java code:
int count = 1;
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++,form.getSiteID());
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++, form.getFunctionID());
findDBNameStatement.setInt(count++,form.getPageNumber());
findDBNameStatement.setInt(count++,form.getSectionNumber());
ResultSet resultSet = findDBNameStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
resultSet.next() returns false
DB table:
CREATE TABLE web_frm (
ID_WEB_FRM varchar2(10) NOT NULL,
ID_WEB_SIT varchar2(20) NOT NULL,
NAM_WEB_FRM varchar2(40),
TXT_EMAIL_SUBJ varchar2(50),
CDE_LVL_1_FUNC char(3),
CDE_LVL_2_FUNC char(3) NOT NULL,
NUM_WEB_FUNC_PG int NOT NULL,
NUM_WEB_PG_ID smallint NOT NULL,
DTE_WEB_FRM_EFF date NOT NULL,
DTE_WEB_FRM_TRM date,
CDE_VLDT_RUL char(3),
DTE_LAST_EXPRT date,
TXT_CNFRMN_MSG varchar2(4000),
IND_UPDT_ALWD char(1) NOT NULL,
TXT_RECAP_HDR varchar2(4000),
TXT_RECAP_FTR varchar2(4000),
CDE_WEB_OBJ char(3),
NUM_MAX_FRM_WIDTH number(4,0),
IND_RECAP_PG char(1) NOT NULL,
IND_CNFRM_PG char(1) NOT NULL,
IND_DSPL_CNFRM_NUM char(1) NOT NULL,
CNT_SUBM_MAX int,
TXT_CHCE_ADD_MSG varchar2(255),
TXT_CHCE_MOD_MSG varchar2(255),
TXT_WEB_HDR varchar2(4000),
TXT_WEB_FTR varchar2(4000),
TXT_WAIT_LIST_MSG varchar2(255),
FORMOBJECTHEIGHT int NOT NULL,
FORMOBJECTWIDTH int NOT NULL
ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
Thanks,
MattThat's not quite right. From the javadocs:
next
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs -
Execute oracle stored procedure from C# always returns null
Hi,
I'm trying to execute a stored procedure on oracle 9i. I'm using .Net OracleClient provider.
Apparently, I can execute the stored procedure, but it always returns null as a result (actually all the sp's I have there returns null)! I can execute any text statement against the database successfully, and also I can execute the stored procedure using Toad.
This is not the first time for me to call an oracle stored procedure, but this really is giving me a hard time! Can anyone help please?
Below are the SP, and the code used from .Net to call it, if that can help.
Oracle SP:
CREATE OR REPLACE PROCEDURE APIECARE.CHECK_EXISTENCE(l_number IN NUMBER) AS
v_status VARCHAR2(5) := NULL;
BEGIN
BEGIN
SELECT CHECK_NO_EXISTENCE(to_char(l_number))
INTO v_status
FROM DUAL;
EXCEPTION WHEN OTHERS THEN
v_status := NULL;
END;
DBMS_OUTPUT.PUT_LINE(v_status);
END CHECK_CONTRNO_EXISTENCE;
C# Code:
string connStr = "Data Source=datasource;Persist Security Info=True;User ID=user;Password=pass;Unicode=True";
OracleConnection conn = new OracleConnection(connStr);
OracleParameter param1 = new OracleParameter();
param1.ParameterName = "v_status";
param1.OracleType = OracleType.VarChar;
param1.Size = 5;
param1.Direction = ParameterDirection.Input;
OracleParameter param2 = new OracleParameter();
param2.ParameterName = "l_number";
param2.OracleType = OracleType.Number;
param2.Direction = ParameterDirection.Input;
param2.Value = 006550249;
OracleParameter[] oraParams = new OracleParameter[] { param1, param2 };
OracleCommand cmd = new OracleCommand("CHECK_EXISTENCE", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(oraParams);
conn.Open();
object result = cmd.ExecuteScalar();
conn.Close();Hi,
Does that actually execute? You're passing two parameters to a procedure that only takews 1 and get no error?
Your stored procedure doesnt return anything and has no output parameters, what are you expecting to be returned exactly?
If you're trying to access V_STATUS you'll need to declare that as either an output parameter of the procedure, or return value of the function, and also access it via accessing Param.Value, not as the result of ExecuteScalar.
See if this helps.
Cheers,
Greg
create or replace function myfunc(myinvar in varchar2, myoutvar out varchar2) return varchar2
is
retval varchar2(50);
begin
myoutvar := myinvar;
retval := 'the return value';
return retval;
end;
using System;
using System.Data;
using Oracle.DataAccess.Client;
public class odpfuncparams
public static void Main()
OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
con.Open();
OracleCommand cmd = new OracleCommand("myfunc", con);
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter retval = new OracleParameter("retval",OracleDbType.Varchar2,50);
retval.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(retval);
OracleParameter inval = new OracleParameter("inval",OracleDbType.Varchar2);
inval.Direction = ParameterDirection.Input;
inval.Value="hello world";
cmd.Parameters.Add(inval);
OracleParameter outval = new OracleParameter("outval",OracleDbType.Varchar2,50);
outval.Direction = ParameterDirection.Output;
cmd.Parameters.Add(outval);
cmd.ExecuteNonQuery();
Console.WriteLine("return value is {0}, out value is {1}",retval.Value,outval.Value);
con.Close();
} -
Query is returning multiple records for a bank account id and party id
Hi All,
I am not getting why this query is returning multiple records for a particular bank account id and party id:
SELECT instrument_payment_use_id
,instrument_type
,instrument_id
,start_date
,ext_pmt_party_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =:lv_num_ext_bank_account_id
and exists (select 1 from iby_external_payees_all b where PAYEE_PARTY_ID= :lv_num_party_id and b.ext_payee_id = ext_pmt_party_id)
I want above values to be used in api iby_disbursement_setup_pub.set_payee_instr_assignment in R12.
Please help asap.
ThanksO/P of query run for
SELECT rowid, instrument_payment_use_id
FROM iby_pmt_instr_uses_all
WHERE instrument_id =6642
AND EXISTS (
SELECT 1
FROM iby_external_payees_all b
WHERE payee_party_id= 85470
AND b.ext_payee_id = ext_pmt_party_id);
is below:
Rowid INSTRUMENT_PAYMENT_USE_ID
AABiDXAGIAABhiKAAS 236586
AABiDXAGRAABSjtAAz 148437
The version is R12 -
SQL- Query that return only one record
Hello,
is it possible to execute a pure SQL-Query which returns only one row although multiple rows are found.
It is no problem in PL/SQL, but I have no idea if the same is also possible in SQL.
thanks in advance
MichaelWhy not? There are 4 records in this table, but only selected one.
SQL> with t
2 as
3 (
4 select '#%$@#$@$@##$' Addr from dual
5 union all
6 select '18 Jalan Scott' from dual
7 union all
8 select '18 Lemana St' from dual
9 union all
10 select '32-penstation' from dual
11 union all
12 select '99999999999' from dual
13 )
14 select addr
15 from t
16 where rownum =1
17 /
ADDR
#%$@#$@$@##$
SQL>Cheers
Sarma. -
Oracle 11g:Query to return only 1 to 1 relationship & random selection
Hi
I have a complex query to modify but I have below the sample tables and data with only very few fields(only affected fields).
Query based on 2 tables b_test and s_test.
Pls see below.
create table b_test(building_id number not null,invalid varchar2(1));
create table s_test(sub_building_id number not null,building_id number ,invalid varchar2(1),sequence_no number);
insert into b_test values (1000,'N');
insert into b_test values(2000,'N');
insert into b_test values(3000,'N');
commit;
insert into s_test values(1,1000,'N',90);
insert into s_test values(2,1000,'N',91);
insert into s_test values(3,1000,'N',92);
insert into s_test values(4,1000,'Y',93);
insert into s_test values(5,NULL,'N',NULL);
insert into s_test values(1,2000,'N',94);
insert into s_test values(2,2000,'N',95);
insert into s_test values(3,2000,'N',96);
insert into s_test values(4,2000,'N',97);
insert into s_test values(5,2000,'N',98);
insert into s_test values(6,NULL,'N',NULL);
insert into s_test values(10,3000,'N',99);
insert into s_test values(11,3000,'N',100);
commit;The query below returns all rows required:(also see results:)
select b.building_id,b.invalid,s.sub_building_id,s.sequence_no from b_test b,
(select * from s_test where invalid='N') s
where b.building_id = s.building_id(+)
and b.invalid='N'
Results:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 91
1000 N 3 92
2000 N 1 94
2000 N 2 95
2000 N 3 96
2000 N 4 97
2000 N 5 98
3000 N 10 99
3000 N 11 100Now there are 2 requirements:
1)How can the above query be changed so that 1:1 relationship if sub_building_id is returned?i.e For 1 building_id, only show 1 sub_building(This could be a random selection)
(Pls help with query)
The results would be like
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11 1002)How can the same SEQUENCE_NO be shown for all sub_buildings for the same building? (Pls help with query)
The results will be:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 3 94
2000 N 4 94
2000 N 5 94
3000 N 10 99
3000 N 11 99Many thanks!
Edited by: Krithi on 08-Nov-2012 08:48
Edited by: Krithi on 08-Nov-2012 08:55Krithi wrote:
Hi
I have a complex query to modify but I have below the sample tables and data with only very few fields(only affected fields).
Query based on 2 tables b_test and s_test.
Pls see below.
create table b_test(building_id number not null,invalid varchar2(1));
Thanks for posting the CREATE TABLE and INSERT statements, and your existing query; that's very helpful.
The query below returns all rows required:(also see results:)
select b.building_id,b.invalid,s.sub_building_id,s.sequence_no from b_test b,
(select * from s_test where invalid='N') s
where b.building_id = s.building_id(+)
and b.invalid='N'
Results:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 91
1000 N 3 92
2000 N 1 94
2000 N 2 95
2000 N 3 96
2000 N 4 97
2000 N 5 98
3000 N 10 99
3000 N 11 100
When I run your query, I get NULL for sequence_no on the last 2 rows, where building_id=3000. The numbers 99 and 100 don't seem to occur in either table. Did you post the worng sample data and/or results?
>
Now there are 2 requirements:
1)How can the above query be changed so that 1:1 relationship if sub_building_id is returned?i.e For 1 building_id, only show 1 sub_building(This could be a random selection)
(Pls help with query) Here's one way:
WITH got_r_num AS
SELECT sub_building_id
, building_id
, sequence_no
, ROW_NUMBER () OVER ( PARTITION BY building_id
ORDER BY sequence_no
) AS r_num
FROM s_test
WHERE invalid = 'N'
SELECT b.building_id
, b.invalid
, r.sub_building_id
, r.sequence_no
FROM b_test b
LEFT OUTER JOIN got_r_num r ON r.building_id = b.building_id
WHERE NVL ( r.r_num
, 1
) = 1
ORDER BY b.building_id
;This is called a Top-N Query , because we're picking N items (N = 1 in this case) from the top of an ordered list. What makes one item the "top", and another one "lower"? That's determined by the analytic ORDER BY clause, in this case
ORDER BY sequence_noThat means the row with the lowest sequence_no (for each building_id) will get r_num=1. If you want a random row from that building_id to be chosen as #1, then you can change the analytic ORDER BY clause to
ORDER BY dbms_random.valueYou can ORDER BY anything you like, even a constant, but you must have an analytic ORDER BY clause. ROW_NUMBER requires an analytic ORDER BY clause.
The results would be like
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11 100
Again, I don't see where the 100 comes from. The results I get are:
BUILDING_ID I SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
2000 N 1 94
3000 N 11
2)How can the same SEQUENCE_NO be shown for all sub_buildings for the same building? (Pls help with query)
SELECT b.building_id
, b.invalid
, s.sub_building_id
, MIN (s.sequence_no) OVER ( PARTITION BY s.building_id)
AS seq_no
FROM b_test b
LEFT OUTER JOIN s_test s ON s.building_id = b.building_id
AND s.invalid = 'N'
The results will be:
BUILDING_ID INVALID SUB_BUILDING_ID SEQUENCE_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 3 94
2000 N 4 94
2000 N 5 94
3000 N 10 99
3000 N 11 99
Again, I don't see where you get sequence_no = 99. The results I get are:
BUILDING_ID I SUB_BUILDING_ID SEQ_NO
1000 N 1 90
1000 N 2 90
1000 N 3 90
2000 N 1 94
2000 N 2 94
2000 N 5 94
2000 N 3 94
2000 N 4 94
3000 N 10
3000 N 11Edited by: Frank Kulash on Nov 8, 2012 12:12 PM
Added explanation and results
Edited by: Frank Kulash on Nov 8, 2012 12:28 PM
It looks like you cahnged your sample data from
insert into s_test values(10,3000,'N',NULL);
insert into s_test values(11,3000,'N',NULL);to
insert into s_test values(10,3000,'N',99);
insert into s_test values(11,3000,'N',100);The queries I posted are niow getting 99, like you requested.
Maybe you are looking for
-
Ipod won't sync anymore.
I recently was at a friends house, and he had some music on his computer that I wanted on my iPod. I told him I didn't think it was possible to get music onto my iPod without my iTunes, but he proved me wrong and used another mp3 player (not itunes)
-
Retrieve rows in order as they are feeded
Hello all My problem is that when i retrieve records from a table the rows are in order in which they are feeded but after joining the table with others the retrieve sequence is changed. I want to get data in the same order in which they are feeded e
-
If I try to log in to the following site http://www.epl.ca/ it appears that the cursor is not working on the top of the screen. If I use Internet Explore I do not have this problem.
-
Hi, I have issue with AE CC 2014. Every time i try to RAM preview project it freezing up with message " Locking existing frames" Here is image of it: It is really frustrating now that i can't properly level the audio on project...Please help!!!
-
Good Day Experts: I have run into an error that I am unable to find information on. It is number -2028 "Associated statement is not prepared". This results when I try add a query programatically using this code: Dim sboUserQuery As SAPbobsCOM.UserQ