SQL & PL/SQL :: Can Call A Function Within Decode Statement
Oct 19, 2011
Can we call a function within decode statement. I am able to do the same for simple example function . But In my actual procedure it's giving the error message . Are there any restrictions to call function with in decode statement?
I am trying to use decode function in sql and inside decode function can I use select statement ?
here is my sql
select we.wf_entity_id, decode(object_type_id, 1, select audit_number from ea_audit_general where sys_audit_id=object_id 2,'test', object_type_id ) from wf_entity we where
[code]....
see this
decode(object_type_id, 1, select audit_number from ea_audit_general where sys_audit_id=object_id 2,'test', object_type_id )
How to call a function with a row type return in an Oracle select statement.
For e.g. :
If I had this function with a rowtype return: ------------------------------ create function abc return xyz%rowtype is rec xyz%rowtype; begin select * into rec from xyz where col1 = n; return rec; end; -------------------------------- How could I use this in a select clause, as there is a multi column return by the function ?
I'm having some trouble writing this query using a decode statement within a join. First, lets say I have two tables. Table A has the fields 'Baseline', 'NAD', 'Null', and 'Harn'. Table B has the fields 'Null', 'NAD', and 'Harn'. I want to join these tables together by these fields to return their ID's. Because table B doesn't have 'Baseline' to even have a match between the two tables, in Table A, we want to treat 'Baseline' as 'Harn', hence a decode statement. My query is below
Select ... ... ... From ... inner join oracle_srid_xref B on A.horizontal_datum = B.horizontal_datum and decode(A.horizontal_epoch, 'BASELINE', 'HARN', loc.horizontal_epoch ) = B.horizontal_epoch
I'm not getting the ID's where the horizontal_epoch was initially 'Baseline'
I have to conditionally update a set of columns in a table. If the column status_code_stage_3 IS NULL THEN I have to update the column status_code_stage_2. The below query is giving error:-
Test Table create scripts CREATE TABLE test11( date_stage_3 date, reason_code_stage_3 varchar2(20), reason_code_stage_2 varchar2(20), opportunity_date date ) INSERT INTO test11 values(sysdate,'reason1',NULL,sysdate) INSERT INTO test11 values(sysdate,NULL,'reason2',sysdate)
[code]....
how to work out the update statement to use the conditional statement for columns.
means if C_TYPE_DESC is 'TXIS CAUSAL LEAVE' it return ABSENCE_DAYS but if ABSENCE_DAYS are null it will be return 0 else it should be return Absence_days
List supplier�s name, id, number of pending orders, number of completed orders and number of all orders from this supplier. (my query doesn't include the last part yet).
My tables are as follows:
Suppliers: S_ID NAME ADDRESS PROVINCE PHONE_NUMBER
and this is what I have so far: select name, s_id sum(decode(order_status, 'P',1,0)) pending, sum(decode(order_status, 'C',1,0)) completed from suppliers where s_id in (select supplier_id from orders);
but I still get an error that says "sum(decode(order_status, 'P',1,0)) pending, * ERROR at line 2: ORA-00923: FROM keyword not found where expected"
I assume this is because I'm not properly referencing the orders table.
Table 1 have 3 columns ID, CUS_NAME, LOC insert into table1 values (001,ABC,North); insert into table1 values (002,DEF,South); insert into table1 values (003,GHI,West);
Table 2 have 3 columns ID, CUS_NAME, LOC insert into table2 values (001,ABC,North); insert into table1 values (002,DEF,East); insert into table1 values (003,JKL,South);
Table 3 is Result_Tab table having 8 columns ID, TAB1_CUS_NAME, TAB2_CUS_NAME, Cus_Name_Res, TAB1_CUS_LOC, TAB2_CUS_LOC, Cus_LOC_Res, Comment.
I have written two cursors which fetches data from both the tables and compares each data between each other and inserts the value into the result table.
the code is as follow:
Insert into Result_Tab values (T1.ID, T1.Cus_Name, T2.Cus_Name, decode(T1.Cus_Name,T2.Cus_Name,'Y','N'),T1.LOC, T2.LOC, decode(T1.LOC,T2.LOC,'Y','N'),Null);
Now I want the resul as follows: ID T1.N T2.N N_Res T1.L T2.L L_Res Comment 001 ABC ABC Y North North Y Null 002 DEF DEF Y South East N Loc 003 GHI JKL N West South N Name, Loc
Is there a way wherein i could capture the column names in decode function when it doesn't match, so that I can insert the same in the comment column.
I am trying to use decode funtion with GROUP BY ROLLUP.
MY query is working fine when i use this two queris individually
SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ((DEPTNO),(DEPTNO,JOB)); SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP((JOB),(DEPTNO,JOB)); But when i use Decode funtion so that i can combine above two scenarios it is not working SELECT SUM(SAL),DEPTNO,JOB FROM EMP GROUP BY ROLLUP ( DECODE(:A,'S',((DEPTNO),(DEPTNO,JOB) ),((JOB),(DEPTNO,JOB) ) ) )
I am using oracle 11G database,I have to check length of name column value from employee table and if length(name) > 39 then value should be substr(name,0,39) else value should be name only. i tried below code
select CASE when length(name) > 39,substr(name,0,39) else name END
from employee but its not working ..can I do this using decode too ? ,,which one would be better or this is not a right way ?
I have Two cursor record block..which is attached in form..
My TASK IS
In my first Block, When DBCR Column = 'D' Then in backend this column value should be save as a '1' WHEN DBCR Column = 'C' Then Then in backend this column value should be save as a '2'
My Both Field is on Data Block...
In Property palette of this field can we write any decode condition..so it reflects directly on database.
I want to have something like this:Run PL/SQL function and in middle of function call JAVA function and when JAVA function is done continue PL/SQL function.
Because I have PL/SQL function who inserts into table information.And the JAVA function is uploading/streaming file to column->blob.And in the end of PL/SQL function goes insert into table with file extension and check for *.edoc validation.I can't do it with PL/SQL only. how to do this right or how to run JAVA function in PL/SQL.
I am defining a function in a schema as a user with admin role (default). The function is to do a call to another function on a custom package in SYS schema.
something funny happens : when I compile the function (defined with authid as DEFINER)it says that the function SYS.custom_package.myFunction is not defined.
however if I do a select sys.custom_package.my Function from dual it's okay.
why this behaviour and how to work around it? You see, the package in SYS proposes a number of other functions that I don't want to expose. I only intend to create some sort of wrapper function that would Marshall the call to the my Function only on the custom_package in SYS.
my wrapper function looks something like that :
create or replace function myFunction_wrapper authid definer return pls_integer is begin return sys.custom_package.myFunction; end;
I have a package includes 22 functions, each function just returns a sql template (clob type).
I also have a stored procedure called query_builder, query_builder has applicationName and statementName as parameters. I need to call these functions in the package based on the given applicationname and statementname.
CREATE OR REPLACE PROCEDURE Query_builder (ApplicationName varchar2, StatementName varchar2) IS SQLSkeleton varchar2; BEGIN PackageName := ApplicationName||'_SKELETON; SQLSkeleton := PackageName.StatementName; -- I know this will not work, but how can i call these function dynamically?
I am in the process of converting my skill in oracle and this time PRO*C from Windows to Linux. I have oracle 11g R2 installed on a UBUNTU (12.04) server and have installed the instant client as described in
[URL]
This has a query which will run in SQLPLUS but fails with PRO*C
:~/Projects/proc/proctest1$ proc INAME=proctest.pc SQLCHECK=NONE ONAME=proctest.c LNAME=proctest.lis LTYPE=long Pro*C/C++: Release 11.2.0.3.0 - Production on Mon Apr 22 21:00:18 2013 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. System default option values taken from: /home/neill.rutherford/instantclient_11_2/precomp/admin/pcscfg.cfg PCC-W-02109, SQLCHECK=NONE is no longer supported.. using SYNTAX
I made this script but I still don't quite understand if the syntax is correct. I just wanted to create a function and call it in an anonymous block. I then wanted it to use a variable as a parameter in an iteration and output the variable every iteration. It's done basically but I know it's not 100% right. The fibonacci function looks like its going to loop an infinite number of times if the parameter is greater than 2.
CREATE OR REPLACE PACKAGE myPACKAGE AS CREATE OR REPLACE FUNCTION fibonacci (n BINARY_DOUBLE) RETURN BINARY_DOUBLE IS BEGIN IF n <= 2 THEN RETURN 1; [code]........
error call a function which alter sequence value..I created a function to reset a sequence value as below
CREATE OR REPLACE FUNCTION rebuildSequence return number As l_csmsgid1 PLS_INTEGER; l_csmsgid2 PLS_INTEGER; l_val PLS_INTEGER; plsql_block VARCHAR2(500); [code]....
I verified and executed the pl/sql block without a problem. but when only put into a fuction and call it, got then error.
create function xxx_sal (p_number in number) return number is v_sal number; begin select sum(sal) into v_sal from emp where empno = p_number; return v_sal; end;