How to use a table in a SQL query
HelloI need to use a table of numbers as a VARRAY or table of associated Index so that I can do the following SQL code:
Select *.
of *.
where the array is null or id is in table
So that if the array is empty it returns all the records, and if the table is not empty, then it will return only the rows associated with the ID of the table.
Is this possible?
Kind regards
Nestor Boscan
In fact, solution I posted returns all rows when VARRAY is empty, not when it is null. To return all the rows when VARRAY is null, use:
SQL> select ename
2 from emp
3 where deptno in (select * from table(cast(sys.OdciNumberList(10,30) as sys.OdciNumberList)))
4 or sys.OdciNumberList(10,30) is null
5 /
ENAME
----------
ALLEN
WARD
MARTIN
BLAKE
CLARK
KING
TURNER
JAMES
MILLER
9 rows selected.
SQL> select ename
2 from emp
3 where deptno in (select * from table(cast(null as sys.OdciNumberList)))
4 or null is null
5 /
ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
ENAME
----------
JAMES
FORD
MILLER
14 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
How to use the concepts Advanced PL/SQL in oracle reports and forms
Hi all
Can anyone suggest me how to use the Concepts(nested tables,PAA,Varrays,Objects...) Advanced PL/SQL in Oracle forms.
In fact, I created a Table whose column of type Varray. now, I want to create an element in oracle forms on this field. can anyone suggest me how to proceed.
Thank you
KumarHello
Take a look at this one:
http://SheikYerbouti.developpez.com/tutoforms10g/tutoforms10g.htm
especially the chapter on the block that contains a collection of (2.3.3). The sample is built around a nested table, but you get the idea to adapt to work with a varray.Kind regards
AlexIf someone useful or appropriate please mark accordingly.
-
How to use the API of PL/SQL DBFS
Hi guys,.
I re-post this question to see if someone can help out me. I'm trying to use the API of PL/SQL DBFS to manipulate the files stored in DBFS.
Details of the environment:
Windows 7 or 5.5 OEL (I tried both platforms)
Database: Oracle DB EE 11.2.0.2
IDE: SQLDeveloper on Windows 7
I have two users, DBFS_USER, who is the shop owner DBFS and MYUSER that connects to the store to manipulate files using the API of PL/SQL DBFS.
Creation scripts:
-----------------
Connect / as sysdba;
Dbfs_ts CREATE TABLESPACE DATAFILE 'D:\oracle\oradata\orcl\dbfs01.dbf' SIZE 1 M AUTOEXTEND ON NEXT 1 M;
-create users
create dbfs_user user identified by dbfs_user quota default tablespace unlimited dbfs_ts on dbfs_ts;
create myuser identified by myuser;
-grant the role
GRANT RESOURCES, CREATE VIEW, CREATE SESSION, DBFS_ROLE, CREATE TABLE TO dbfs_user.
GRANT RESOURCES, CREATE VIEW, CREATE SESSION, DBFS_ROLE, CREATE TABLE TO myuser.
-create a filesystem (such as DBFS_USER)
connect dbfs_user/dbfs_user;
exec dbms_dbfs_sfs.createFilesystem ('STAGING_AREA_FS');
exec dbms_dbfs_content.registerStore ('STAGING_AREA_FS', 'posix', 'DBMS_DBFS_SFS');
dbms_dbfs_content.mountStore exec ('STAGING_AREA_FS', 'staging_area');
commit;
-export store STAGING_AREA_FS (as DBFS_USER)
exec dbms_dbfs_sfs.exportFilesystem ('STAGING_AREA_FS');
-Check the names of table (like MYUSER)
connect myuser/myuser;
-He can't see (without brackets)
Select * from table (dbms_dbfs_content.listMounts);
-Note at the bottom of the table table_name
Select * from table (dbms_dbfs_sfs.listTables);
-Mount as MYUSER (example with SFS table_name $ _FST_32)
dbms_dbfs_sfs.registerFilesystem exec ('MYUSER_FS', 'DBFS_USER', ' FS$ _FST_32');
exec dbms_dbfs_content.registerStore ('MYUSER_FS', 'posix', 'DBMS_DBFS_SFS');
dbms_dbfs_content.mountStore exec ('MYUSER_FS', 'staging_area');
commit;
-verification of Mount (like MYUSER)
Select * from table (dbms_dbfs_content.listMounts);
Select the path in dbfs_content;
CREATE a STORED PROC (like MYUSER)
----------------------------
CREATE OR REPLACE PACKAGE MYUSER_PKG
CreateDirectory function
(P_File_Path IN VARCHAR2,
P_ErrMsg OUT VARCHAR2)
return number;
END MYUSER_PKG;
/
CREATE OR REPLACE PACKAGE BODY MYUSER_PKG
CreateDirectory function
(P_File_Path IN VARCHAR2,
P_ErrMsg OUT VARCHAR2)
Return number
IS
l_Return NUMBER;
l_props DBMS_DBFS_CONTENT. PROPERTIES_T;
BEGIN
l_Return: = 0;
() DBMS_DBFS_CONTENT.createDirectory
path = > P_File_Path,
Properties = > l_props);
RETURN l_Return;
EXCEPTION
WHILE OTHERS THEN
l_Return: = NVL (SQLCODE,-1);
P_ErrMsg: = SQLERRM;
RETURN l_Return;
CreateDirectory END;
END MYUSER_PKG;
/
When you compile the package, I get this error:
Error (9,11): PLS-00201: identifier 'DBMS_DBFS_CONTENT' must be declared
Error (9,11): PL/SQL: ignored element
Error (13.3): PL/SQL: statement ignored
Error (15,19): PLS-00320: the declaration of the type of the expression is incomplete or incorrect
How can I solve the problem in the error message? I'm not an expert in DB. I used this reference documentation: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e18294/adlob_client.htm#CIHDEJAA
Thanks in advance.
CAPPAYou must directly grant the privileges of DBFS_ROLE because roles are not enabled in stored PL/SQL:
SQL> select* from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production PL/SQL Release 11.2.0.2.0 - Production CORE 11.2.0.2.0 Production TNS for Solaris: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production SQL> show user USER is "SYS" SQL> SQL> create user myuser identified by myuser; User created. SQL> GRANT CREATE SESSION, RESOURCE, CREATE VIEW, DBFS_ROLE, CREATE TABLE TO myuser; Grant succeeded. SQL> SQL> begin 2 for x in (select privilege, table_name 3 from dba_tab_privs 4 where grantee='DBFS_ROLE') 5 loop 6 execute immediate 'grant ' || x.privilege || ' on ' || x.table_name 7 || ' to myuser '; 8 end loop; 9 end; 10 / begin * ERROR at line 1: ORA-22812: cannot reference nested table column's storage table ORA-06512: at line 6 SQL> SQL> connect myuser/myuser Connected. SQL> SQL> CREATE OR REPLACE PACKAGE MYUSER_PKG IS 2 Function CreateDirectory 3 (P_File_Path IN VARCHAR2, 4 P_ErrMsg OUT VARCHAR2) 5 return Number; 6 END MYUSER_PKG ; 7 / Package created. SQL> show errors No errors. SQL> SQL> CREATE OR REPLACE PACKAGE BODY MYUSER_PKG IS 2 Function CreateDirectory 3 (P_File_Path IN VARCHAR2, 4 P_ErrMsg OUT VARCHAR2) 5 return Number 6 IS 7 l_Return NUMBER; 8 l_props DBMS_DBFS_CONTENT.PROPERTIES_T; 9 BEGIN 10 l_Return := 0; 11 DBMS_DBFS_CONTENT.createDirectory ( 12 path => P_File_Path, 13 properties => l_props); 14 RETURN l_Return; 15 EXCEPTION 16 WHEN OTHERS THEN 17 l_Return := NVL(SQLCODE, -1); 18 P_ErrMsg := SQLERRM; 19 RETURN l_Return; 20 END CreateDirectory; 21 END MYUSER_PKG ; 22 / Package body created. SQL> show errors No errors.
You should check why some GRANT statement fails if you have another problem with the other piece of code.
-
Hello
How can I use a table defined in the main Script block in an InlineCode Block of a DataGridColumn ComboBox itemRenderer?
Thanks for any help!
Martin West
I hope my problem with the Code:
< fx:Script >
<! [CDATA]
private var myArrayOut: Array =new Array (' one of ','out two', "three out");
< / fx:Script >
...
DataGrid...
< mx:DataGridColumn headerText = "MyColumn" dataField = "MyColumn" rendererIsEditor = "true".
< mx:itemRenderer >
< fx:Component >
< mx:ComboBox creationComplete = "init ()" >
< fx:Script >
<! [CDATA]
private var myArrayIn: Array = new Array ('one', 'two', 'three');
private function init (): void {}
this.dataProvider = myArrayIn; / / How can I use myArrayOut here?
}
[]] >
< / fx:Script >
< / mx:ComboBox >
< / fx:Component >
< / mx:itemRenderer >
< / mx:DataGridColumn >Hello
outerDocument is a link to external data and functions.
If you need
outerDocument.myArrayOut.
-
How to write the result of a SQL query to a text file?
I'm using Oracle 11 g and SQL Plus.
I have a large table called side.
Whenever I do
SQL > select * rating.
The output goes well beyond what can show the screen sqlplus. So, I want to store the result of this query in a text file.
How is that possible? Help, please. Thank you.SQL > SPOOL results.txt
SQL > select * rating.
SQL > SPOOL OFF -
Using Variables in a system SQL query
Hello!
I m new on Oracle and SQL so I Don t know not big thing about it.
There is problem of customization:
Is it possible to use the System Variable % username % in a SQL query?
I tried... where table.shorttag = "% username %";
but it does not work.
Oracle is able to manage Systemvariables? Or y at - it another way to use the current Windows user in a SQL query.
It is very Important to use the current Windows user and not the Oracle user.
Thank you
MFGSELECT OSUSER FROM V$SESSION WHERE audsid = USERENV('sessionid')
URS
-
How to measure the performance of the sql query?
Hi Experts,
How to measure the cost of performance, efficiency and CPU of an sql query?
What are all the measures available to a sql query?
How to identify the optimal query writing?
I use Oracle 9i...
It'll be useful for me to write the effective query...
Thanks and greetingsPSRAM wrote:
Could you tell me how to activate the PLUSTRACE role?First put on when you do a search on PLUSTRACE: http://forums.oracle.com/forums/search.jspa?threadID=&q=plustrace&objID=f75&dateRange=all&numResults=15&rankBy=10001
Kind regards
Rob. -
How to use Bulk collect in dynamic SQL with the example below:
My Question is
Using of dynamic SQL with collection in bulkif we pass the name of the table as "to the parameter' function, I want to display those
An array of column names without vowels (replace the vowels by spaces or remove vowels and display).
Please explain for example.
Thank you!!It's just a predefined type
SQL> desc sys.OdciVarchar2List sys.OdciVarchar2List VARRAY(32767) OF VARCHAR2(4000)
You can just as easily declare your own collection type (and you are probably better served declaring your own type of readability if nothing else)
SQL> ed Wrote file afiedt.buf 1 CREATE OR REPLACE 2 PROCEDURE TBL_COLS_NO_VOWELS( 3 p_owner VARCHAR2, 4 p_tbl VARCHAR2 5 ) 6 IS 7 TYPE vc2_tbl IS TABLE OF varchar2(4000); 8 v_col_list vc2_tbl ; 9 BEGIN 10 EXECUTE IMMEDIATE 'SELECT COLUMN_NAME FROM DBA_TAB_COLUMNS WHERE OWNER = :1 AND TABLE_NAME = :2 ORDER BY COLUMN_ID' 11 BULK COLLECT 12 INTO v_col_list 13 USING p_owner, 14 p_tbl; 15 FOR v_i IN 1..v_col_list.COUNT LOOP 16 DBMS_OUTPUT.PUT_LINE(TRANSLATE(v_col_list(v_i),'1AEIOU','1')); 17 END LOOP; 18* END; SQL> / Procedure created. SQL> exec tbl_cols_no_vowels( 'SCOTT', 'EMP' ); MPN NM JB MGR HRDT SL CMM DPTN PL/SQL procedure successfully completed.
Justin
-
How to use "Routing Table" option in the Proxy in OSB service?
Hello
I created business services and Proxy in my console of OSB. I used the "Custom Query" option when creating the database adapter and I am passing a parameter to the query. My input parameter is 'name '.
Based on the input for this parameter values, I spend a values corresponding to the query. By example, if I pass the following values to the input parameter "Name" (India) I need to spend "Value1" to my request.
The India-> value1
China-> value2
America-> value3
To achieve this requirement, I used option "Routing Table". I specified the values as follows: -.
Expression - $body / fet:FetchCustDataInput / fet:Name
Operator - '='
Compare the value - India
Service - "my Webservice.
Operaton-"my Service operation.
In the "application of Actions:" I added the 'add an Action-> processing e-mail-> replace' and provided the following values.
Replace < XPath > = $body / fet:FetchCustDataInput / fet:Name
Variable = 'name '.
with the Expression = xs:string('Value1')
and the "Replace the content of the node" option selected.
No validation error I encountered. I created the routing table in the Proxy service. But when I try to run the service proxy in my Test Console, I get the following error
«The call resulted in an error: an unknown error during the processing of the message of service ProxyService OSBQueryService/FetchByCustomQuery/FetchByCustomQueryPS.»
I even activated "Direct call" and 'Include Tracing' options as well. The message in "Tracing" give "(echo request)
Routed service. No Service has been invoked, echoed the demand. ».
Can someone please help me solve this problem.
Thanks in advance,
UdayaHi Marion,.
Replace
= $body / fet:FetchCustDataInput / fet:Name
Variable = 'name '.
with the Expression = xs:string('Value1')
and the "Replace the content of the node" option selected.Above replace the action is wrong. It should be like -
Replace
= $body / fet:FetchCustDataInput / fet:Name
Variable = body
with the Expression = xs:string('Value1')
and the "Replace the content of the node" option selected.Kind regards
Anuj -
Using CASE in a dynamic sql query
Hello
I want to create a dynamic query using the CASE statement to replace the below 2 SQL statements:
+++++
Select "create or replace the synonym ' |" SYNONYM_NAME | 'for'. TABLE_OWNER |'. ' || TABLE_NAME | » @'|| SUBSTR (Db_link, 1, 30) |';' OF USER_SYNONYMS where db_link is not null;
Select "create or replace the synonym ' |" SYNONYM_NAME | 'for'. TABLE_OWNER |'. ' || TABLE_NAME |';' OF USER_SYNONYMS where the db_link is null;
+++++
While I have a unique select query which will give her create synonym statements for all with or without links db
Using the example of CASE statement as below:
SELECT
FirstName, LastName,
Salary, date of birth,
ABOUT sex
WHEN'm ' THEN 'male '.
WHEN 'F' THEN 'woman '.
END
Employees
I don't get how to write this CASE statement. Can someone guide me here?
Thank you
Malika"" The thread has been moved to Forum Home "database" SQL and PL/SQL+.
Nicolas.
-
How to use weab bean values in the query of VO
I created new region who having 3 components of shuttle
4 text fields, two submit buttons GO and claire and a table
This area is research area after that click on GO button result should be
in the Bulletin Board
I did a VO
I want to write the query in VO to accomplish my task
How can I take page field valuesHello
-U can not use one based on your requirement.
-After co value, if it is not null then set where param in vo class run the query.Concerning
Meher Irk -
Using a URL parameter in SQL query
Newbie question...
I've developed a dashboard application, and I use the enter SQL bind variables. Everything works well.
I want to do is to have a user access to a page via a URL with the parameters like this:
http://Atlas:7777 / pls/apex/f? p = 112:1:9191429456552868531:P1_ITM_CD_PASSED:JMINV
where P1_ITM_CD_PASSED is the parameter and the JMINV is the value.
So, I want the SQL to run using that:
Select *.
ITM
where itm_cd = ': P1_ITM_CD_PASSED'
I tried to test this on a page. Set up a report from the region, but it seems that the setting is not what makes the SQL. "No record found".
Is there a simple example that someone knows? Maybe I'm missing a point, process, calculation, etc. to be able to use the parameter?
Thanks in advanceHello
You have an extra ':' in the URL. Try this http://atlas:7777 / pls/apex/f? p = 112:1:9191429456552868531:P1_ITM_CD_PASSED:JMINV
The syntax of the URL of the APEX is described here http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/concept.htm#sthref165
CITY
-
How to use AS operator with my requriment query
Hi all
I have a requirement as follows
EMPID ENAME SAL JOB
------------------------------------------------------------------------------------
10 RAJ KAMAL MANAGER 25000
20 REZZIK NIZAR CLERK 4000
CHRISTINE GUPTA ANALYST 20000 30
ASHUTOSH GUPTA DEVELOPER 10000 40
ASHUTOSH 50 NAYAR PROGRAMMER 15000
I'm looking enames I need to get the full name, even if I search with just a single LETTER/WORD immaterial the order they exist in the name I need to get the full name. (INFACT WORD comparison)
ex:
(1) select * from emp where ename like '% ka.
I get:
10 RAJ KAMAL MANAGER 25000
20 REZZIK NIZAR CLERK 4000
This isn't what I need I need just Word camparision no comparision letters let me tell you...
Select * from emp where ename like 'amal %.
Even for this ill request to get the same result... is not my option to go...
I need just word comparison with letter of departure and immaterial to the position of the word in the name
If it is possible to do with the query please let me know...
Thanking you
Julien VishwanathamOr maybe
SQL> with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all select 50, 'ASHUTOSH IMKAL', 'DEVELOPER', 10000 from dual union all select 60, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual ) --- --- select * from e where regexp_like(ename,'(^| )ka(.*)( |$)','i') / EMPID ENAME JOB SAL ---------- --------------- ---------- ---------- 10 RAJ KAMAL MANAGER 25000 20 KAMAL RAJ NAYAK CLERK 4000 2 rows selected.
-
How to move the Page Item in SQL query
Hello, I have a need to transmit a page element in a function, plsql on the way but none of it works according to the following. What Miss me?
I tried immediately, but no luck.select aplsqlfunction(:P29_X) from dual;
: P29_X
#P29_X #.
& P29_X.
P29_X
Thank you
R
Published by: Rich V on June 6, 2010 16:55Well then...
Select aplsqlfunction (V('P29_X') AS Xyz of double;
Thank you
Tony Miller
Webster, TX -
How to know the status of the process flow using a SQL query
Hello
I want to know the final status of a process flow after execution by using a sql query?
The available entries are:
-Item_Key
-Process_Flow_Package_Name
-Process_Flow_Name
I ran the process flow using a WF_Engine.LaunchProcess ()procedure, but I was not able to know the status of the process flow.
Is it possible to know the status of the process flow?
using a procedure or an sql query?
Thanks in advance,
SriGP.Once the process is completed, or not, you can see the status by calling:
UAS (your_OWF_shema) .wf_engine. ItemStatus()
Maybe you are looking for
-
I wrote it in my Terminal words "hidden chflags" and got: chflags [-VHF] [r [h |]] L | -P]] flags file... does that mean? If it is not necessary could it be removed? How? Thank you.
-
I have a MAC and you cannot upgrade the operating system. Firefox keeps asking me to upgrade and I can't. How can I stop it asking me every time I go to another page? Even with google and gmail. I can't be upgraded more. How can I stop it asks all th
-
Okay so a few hours ago, I picked up my phone and the sim card had just "disassembled" itself, I guess you could say. On the lock screen, it said I had no mobile network connected, I couldn't call someone or text message to anyone. Then at 10 minutes
-
What are the registry errors and are they more than a gadget?
I hava a 2 year, HP laptop, XP Professional. I get the e-mail promising fix registry errors and make my computer faster and more efficiant - it seems a bit "drasggy", these products work? Is there a free source for the same thing? Thank you very mu
-
Push to Production of EVAL: AppId + Port
If you move of EVAL in the Production, the Port and the AppId will remain the same and only PPG Base URL change? or should I expect that everything will change THX 4 info