DECODE works in SQL but not in a CURSOR

I have simplified my problem to "DUAL":
While in a SQL session :
select decode(
(select 1 from dual)
,(select 1 from dual)
,1
,0)
from dual;
Expected result: 1;
Actual result: 1;
Place this code in a PL/SQL block :
declare
X number;
begin
SELECT decode(
(select 1 from dual)
,(select 1 from dual)
,1
,0)
INTO X;
FROM dual;
end;
Expected Result: X=1;
Actual Result: ORA-06550 & PLS-00103 "Encountered the symbol SELECT".
My Question:
Why can't I place a select within a decode while in a PL/SQL block? I have also tried this in an Explicit cursor.

This is another of those cases when the PL/SQL engine does not support a feature/syntax of the SQL engine. To do this in PL/SQL, execute it as dynamic SQL (which uses the SQL engine):
declare
X number;
begin
  execute immediate
    'SELECT decode((select 1 from dual),' ||
                  '(select 1 from dual),1,0) ' ||
    '  FROM dual' into x;
  dbms_output.put_line( x );
end;

Similar Messages

  • DB Link - works via SQL but not via packages

    I have a database link on user ODB on database A, to database B. The DB Link seems fine for SQLs that i do, but doesn't compile in my package code. Please tell me why it works for "regular sqls" but not inside a package.
    Example: while connected as ODB user on database A, if I do this query:
    SELECT "TRAXDOC_DETAIL"."FILE_NAME",
    "TRAXDOC_DETAIL"."FILE_TYPE",
    FROM "TRAXDOC_DETAIL"@TRAXDOC_LINK
    WHERE "TRAXDOC_DETAIL"."TRAXDOC_ROW_ID" = 100031 AND
    "TRAXDOC_DETAIL"."TRAXDOC_LINE"= 2
    It works fine. But the same query inside a package that is owned by user ODB on database A will not compile, stating the table/view does not exist.
    The database link is owned by use ODB on database A, connects directly to the owner of the tables in question on database B.
    Any suggestions welcome... this is an urgent issue, because it also worked fine on my customer's test environment, but not on their Production that they just upgraded. I need to know what to look for as to what could be wrong.

    Thanks so much for your response - Prefixing the call to the table within the package, with the schema owner does indeed solve the problem. Since this is a Production issue, i have implemented this fix in my customer's database.
    However, I would still like this issue permanently resolved. The next time we send out updated package code, this will happen again (unless we then fix it again). I'd still like info from anyone on what exactly must be done to allow the call within the package to work without specifically pre-fixing the table's schema owner. It shouldn't be needed... The DB link is connecting via the same schema on database B that owns the table in question.
    pre-fixing the schema owner is something we don't do in our sql statements, and this has worked fine for many of our cusomer's environments. We're only seeing this issue on one environment.

  • Connect by prior working in sql but not in forms 10g hierarchical tree

    Hello Friends,
    I have the following connect by prior example which is working in sql command prompt but not in Forms 10g hierarchical tree item type. Can you please let me know why ?
    configuration: Forms 10g patchset 10.1.2.0.2 and oracle 11g database on windows 7
    SQL> SELECT 1 InitialState,
    2 level Depth,
    3 labeller NodeLabel,
    4 NULL NodeIcon,
    5 to_char(reportno) NodeValue
    6 FROM reports where formname = 'billinin.fmx' or reportno > 9999
    7 start with reportno > 9999
    8 CONNECT BY PRIOR reportno = labelno
    9 /
    INITIALSTATE DEPTH NODELABEL N NODEVALUE
    1 1 FIRST 10000
    1 2 report1 UD Label 1
    1 2 report2 UD Label 2
    1 2 report3 UD Label 3
    1 1 SECOND 10001
    1 1 THIRD 10002
    If I write this command in forms hierarchical tree, then it is working, why not the above code ?
    SQL> SELECT 1 InitialState,
    2 level Depth,
    3 labeller NodeLabel,
    4 NULL NodeIcon,
    5 to_char(reportno) NodeValue
    6 FROM reports
    7 start with reportno > 9999
    8 CONNECT BY PRIOR reportno = labelno

    Thanks Room,
    This command worked ! I will put the sample working code here. It will help you to filter the records in a tree in sql command prompt as well as in forms hierarchical tree 10g.
    SELECT 1 InitialState,
    level Depth,
    labeller NodeLabel,
    NULL NodeIcon,
    to_char(reportno) NodeValue
    FROM reports
    start with reportno > 9999
    CONNECT BY PRIOR reportno = labelno
    AND FORMNAME = :reports.testitem

  • ORA-01891 - Query works in SQL+ but not in JDev

    JDev 9.0.4 / DB 8i...
    I run a query in SQL+ and it returns results, I run it in JDev Worksheet and I get "ORA-01891: Datetime/Interval internal error".
    The query is a select from a view based on a synonym that links to a table in another DB (database link). I have boiled it down to it's "simplest" form for testing and it looks like:
    select * from some_table;
    I can also run this query in 9.0.5.2 worksheet.

    Funny you should mention that. The reason I found this error is because one of my VOs wasn't working, so I tried running the query in the worksheet. Didn't work there either but I was getting this different error (posted above). Anways, turns out the viewobject had the wrong attribute listed so I fixed that but the worksheet doesn't work.
    I don't think it's the attribute because the worksheet isn't directly connected to the VO so it shouldn't be aware of it. Additionally, only the VOs that are based on the view/synonym/link are affected.
    Thanks for the suggestion though!

  • Query working in sql but not if  forrms!!!!

    I transferred my column apprnum from tblrefstaff to paymast using
    SQL>update paymast set paymast.apprnum=(select tblrefstaff.apprnum from tblrefstaff where tblrefstaff.empno=paymast.empno and rownum=1);
    5072 rows updated
    Now i query for the records in paymast
    SQL> select empno from paymast where apprnum='338';
    EMPNO
    2217
    SQL> select apprnum from paymast where empno='2217';
    APPRNUM
    338
    Now in forms when i write this under POST-QUERY
    begin
         select apprnum
         into :paymast.apprnum
         from paymast
         where empno = :paymast.empno;
    exception when no_data_found then null;
         end;
    no data is retrieved in to the item apprum
    its only retrieved when the name of table is that of the previous one like this
    begin
         select apprnum
         into :paymast.apprnum
         from tblrefstaff
         where empno = :paymast.empno;
    exception when no_data_found then null;
         end;
    2nd CASE: after transferring apprnum to paymast all the items are now under paymast so i just removed the code under POST-QERY and the set the datbase item to yes and column name to APPRNUM but still no use
    It only fetches records in apprnum using
    select apprnum
         into :paymast.apprnum
         from tblrefstaff
         where empno = :paymast.empno;
    exception when no_data_found then null;
         end;
    how should solve this.?
    Edited by: Suhail Faraaz on Nov 10, 2009 2:10 AM

    i think you forgot to commit; after executing update stmt..
    It will work in SQL becoz, you wrote the Query immediately after the select stmt.
    But Forms is in another session, it cannot access the data until you commit the SQL session.
    Regards
    Dora
    Edited by: Dora on Nov 10, 2009 2:26 PM

  • Query working in sql but not in forms

    hi this is my query
    insert into sa_prod_temp
    select sa_idno,sa_srno_desc,count(*) qty from sa_master,
              select sa_code,sa_idno,sa_prod_date,sa_srno,sa_srno1 from
                   select sa_code,sa_idno,sa_prod_date,sa_srno,sa_srno1 from bom_sa_prod
                   order by sa_prod_date desc
              where rownum <=50
         ) b
         where sa_type = :dummy.sa_code and sa_type = sa_code
         and sa_master.sa_srno = b.sa_idno
         group by sa_idno,sa_srno_desc     ;

    insert into sa_prod_temp
    select sa_idno,sa_srno_desc,count(*) qty from sa_master,
    select sa_code,sa_idno,sa_prod_date,sa_srno,sa_srno1 from
    select sa_code,sa_idno,sa_prod_date,sa_srno,sa_srno1 from bom_sa_prod
    order by sa_prod_date desc
    where rownum <=50
    ) b
    where sa_type = :dummy.sa_code and sa_type = sa_code
    and sa_master.sa_srno = b.sa_idno
    group by sa_idno,sa_srno_desc ;
    VALUE CLASS IS MISSING
    -----------------

  • Abnormal, Same query get data in sql but not working on Fron-end

    Dear,
    Version :Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    We have created packed in oracle database befor two months ago & was working fine, but since morning select statment in package is not working while running via application which mentioned below and raise not data found but surprising thing is that same query is getting data when we execut on sql plus return one record.
    i don't know either it's abnormal behaviour or sth else becuase the same query run without changing any singl column in where_clause work in sql but not getting data while submition request through oracle application and raising not data found.
    --thankse
    Edited by: oracle0282 on Dec 29, 2011 2:20 AM

    Actully when i run this query in sql it return one record on the same parameter, while when we exeucte this select in pl/sql on the same parameter oracle raise no data found error.
    so i got confused the same query with same parameter retur record in sql but when we call it fron-end through packege raise 'no data found error'.
    hope you understand now.
    --thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • ORA-01031: insufficient privileges in PL/SQL but not in SQL

    I have problem with following situation.
    I switched current schema to another one "ban", and selected 4 rows from "ed"
    alter session set current_schema=ban;
    SELECT * FROM ed.PS WHERE ROWNUM < 5;
    the output is OK, and I get 4 rows like
    ID_S ID_Z
    1000152 1
    1000153 1
    1000154 1
    1000155 1
    but following procedure is compiled with warning
    create or replace
    procedure proc1
    as
    rowcnt int;
    begin
    select count(*) into rowcnt from ed.PS where rownum < 5;
    end;
    "Create procedure, executed in 0.031 sec."
    5,29,PL/SQL: ORA-01031: insufficient privileges
    5,2,PL/SQL: SQL Statement ignored
    ,,Total execution time 0.047 sec.
    Could you help me why SELECT does work in SQL but not in PL/SQL procedure?
    Thanks.
    Message was edited by:
    MattSk

    Privs granted via a role are only valid from SQL - and not from/within stored PL/SQL code.
    Quoting Tom's (from http://asktom.oracle.com) response to this:I did address this role thing in my book Expert one on one Oracle:
    <quote>
    What happens when we compile a Definer rights procedure
    When we compile the procedure into the database, a couple of things happen with regards to
    privileges.  We will list them here briefly and then go into more detail:
    q    All of the objects the procedure statically accesses (anything not accessed via dynamic SQL)
    are verified for existence. Names are resolved via the standard scoping rules as they apply to the
    definer of the procedure.
    q    All of the objects it accesses are verified to ensure that the required access mode will be
    available. That is, if an attempt to UPDATE T is made - Oracle will verify the definer or PUBLIC
    has the ability to UPDATE T without use of any ROLES.
    q    A dependency between this procedure and the referenced objects is setup and maintained. If
    this procedure SELECTS FROM T, then a dependency between T and this procedure is recorded
    If, for example, I have a procedure P that attempted to 'SELECT * FROM T', the compiler will first
    resolve T into a fully qualified referenced.  T is an ambiguous name in the database - there may be
    many T's to choose from. Oracle will follow its scoping rules to figure out what T really is, any
    synonyms will be resolved to their base objects and the schema name will be associated with the
    object as well. It does this name resolution using the rules for the currently logged in user (the
    definer). That is, it will look for an object owned by this user called T and use that first (this
    includes private synonyms), then it will look at public synonyms and try to find T and so on.
    Once it determines exactly what T refers to - Oracle will determine if the mode in which we are
    attempting to access T is permitted.   In this case, if we as the definer of the procedure either
    owns the object T or has been granted SELECT on T directly or PUBLIC was granted SELECT, the
    procedure will compile.  If we do not have access to an object called T by a direct grant - the
    procedure P will fail compilation.  So, when the object (the stored procedure that references T) is
    compiled into the database, Oracle will do these checks - and if they "pass", Oracle will compile
    the procedure, store the binary code for the procedure and set up a dependency between this
    procedure and this object T.  This dependency is used to invalidate the procedure later - in the
    event something happens to T that necessitates the stored procedures recompilation.  For example,
    if at a later date - we REVOKE SELECT ON T from the owner of this stored procedure - Oracle will
    mark all stored procedures this user has that are dependent on T, that refer to T, as INVALID. If
    we ALTER T ADD  some column, Oracle can invalidate all of the dependent procedures. This will cause
    them to be recompiled automatically upon their next execution.
    What is interesting to note is not only what is stored but what is not stored when we compile the
    object. Oracle does not store the exact privilege that was used to get access to T. We only know
    that procedure P is dependent on T. We do not know if the reason we were allowed to see T was due
    to:
    q    A grant given to the definer of the procedure (grant select on T to user)
    q    A grant to public on T (grant select on T to public)
    q    The user having the SELECT ANY TABLE privilege
    The reason it is interesting to note what is not stored is that a REVOKE of any of the above will
    cause the procedure P to become invalid. If all three privileges were in place when the procedure
    was compiled, a revoke of ANY of them will invalidate the procedure - forcing it to be recompiled
    before it is executed again. Since all three privileges were in place when we created the procedure
    - it will compile successfully (until we revoke all three that is). This recompilation will happen
    automatically the next time that the procedure is executed.
    Now that the procedure is compiled into the database and the dependencies are all setup, we can
    execute the procedure and be assured that it knows what T is and that T is accessible. If something
    happens to either the table T or to the set of base privileges available to the definer of this
    procedure that might affect our ability to access T -- our procedure will become invalid and will
    need to be recompiled.
    This leads into why ROLES are not enabled during the compilation and execution of a stored
    procedure in Definer rights mode. Oracle is not storing exactly WHY you are allowed to access T -
    only that you are. Any change to your privileges that might cause access to T to go away will cause
    the procedure to become invalid and necessitate its recompilation. Without roles - that means only
    'REVOKE SELECT ANY TABLE' or 'REVOKE SELECT ON T' from the Definer account or from PUBLIC. With
    roles - it greatly expands the number of times we would invalidate this procedure. If some role
    that was granted to some role that was granted to this user was modified, this procedure might go
    invalid, even if we did not rely on that privilege from that role. ROLES are designed to be very
    fluid when compared to GRANTS given to users as far as privilege sets go. For a minute, let's say
    that roles did give us privileges in stored objects. Now, most any time anything was revoked from
    ANY ROLE we had, or any role any role we have has (and so on -- roles can and are granted to roles)
    -- many of our objects would become invalid. Think about that, REVOKE some privilege from a ROLE
    and suddenly your entire database must be recompiled! Consider the impact of revoking some system
    privilege from a ROLE, it would be like doing that to PUBLIC is now, don't do it, just think about
    it (if you do revoke some powerful system privilege from PUBLIC, do it on a test database). If
    PUBLIC had been granted SELECT ANY TABLE, revoking that privilege would cause virtually every
    procedure in the database to go invalid. If procedures relied on roles, virtually every procedure
    in the database would constantly become invalid due to small changes in permissions. Since one of
    the major benefits of procedures is the 'compile once, run many' model - this would be disastrous
    for performance.
    Also consider that roles may be
    q    Non-default: If I have a non-default role and I enable it and I compile a procedure that
    relies on those privileges, when I log out I no longer have that role -- should my procedure become
    invalid -- why? Why not? I could easily argue both sides.
    q    Password Protected: if someone changes the password on a ROLE, should everything that might
    need that role be recompiled?  I might be granted that role but not knowing the new password - I
    can no longer enable it. Should the privileges still be available?  Why or Why not?  Again, arguing
    either side of this is easy. There are cases for and against each.
    The bottom line with respect to roles in procedures with Definer rights are:
    q    You have thousands or tens of thousands of end users. They don't create stored objects (they
    should not). We need roles to manage these people. Roles are designed for these people (end users).
    q    You have far fewer application schema's (things that hold stored objects). For these we want
    to be explicit as to exactly what privileges we need and why. In security terms this is called the
    concept of 'least privileges', you want to specifically say what privilege you need and why you
    need it. If you inherit lots of privileges from roles you cannot do that effectively. We can manage
    to be explicit since the number of development schemas is SMALL (but the number of end users is
    large)...
    q    Having the direct relationship between the definer and the procedure makes for a much more
    efficient database. We recompile objects only when we need to, not when we might need to. It is a
    large efficiency enhancement.
    </quote>

  • In line view works in 9i but not 11g

    The following subset of a larger in ilne view works in 9i, but not in 11g. Any thoughts on why it doesn't work in 11g. An 'ORA-00979 : not a group by expression' message is displayed. This error message refers to the last 'group by' statement.
    select a.appl_start_term
    ,count(*)apps
    ,acc_total--, acc_gre
    from datatel_snap.applicant_current_part a
    , datatel_snap.acad_program b
    --accepted
    select appl_start_term
    ,count(*) acc_total
    --, sum(decode(test_grev,null,0,1)) acc_gre
    from datatel_snap.applicant_current_part a
    , datatel_snap.acad_program b
    , datatel_snap.dept c
    where appl_admit_status_cat in ('MASTER')
    and substr(appl_start_term,5,1)= 'F'
    and appl_school='SIS'
    and a.appl_acad_program = b.id
    and b.dept_1 = c.id
    and (derived_appl_disp = 'AC')
    group by appl_start_term
    ) z
    where appl_admit_status_cat in ('MASTER')
    and substr(a.appl_start_term,5,1)= 'F'
    and appl_school= 'SIS'
    and a.appl_acad_program = b.id
    and a.appl_start_term = z.appl_start_term(+)
    group by a.appl_start_term ,acc_total--, acc_gre
    order by 1
    Edited by: user8377830 on Jul 17, 2010 10:05 AM
    Edited by: user8377830 on Jul 17, 2010 10:10 AM

    Fine, you shoud do do either:
    - a group by "acc_total" or
    - use an aggregate function on "acc_total" (like: sum(acc_total), max(acc_total) etc.)
    Edited by: user11268895 on Jul 17, 2010 7:14 PM
    sorry id didn't read carrefully your statement...
    Try to prefix the column acc_total with "z." (both in the select and in the group by expression)
    SELECT   a.appl_start_term, COUNT (*) apps, z.acc_total              --, acc_gre
        FROM datatel_snap.applicant_current_part a,
             datatel_snap.acad_program b,
    --accepted
              SELECT   appl_start_term, COUNT (*) acc_total
    --, sum(decode(test_grev,null,0,1)) acc_gre
              FROM     datatel_snap.applicant_current_part a,
                       datatel_snap.acad_program b,
                       datatel_snap.dept c
                 WHERE appl_admit_status_cat IN ('MASTER')
                   AND SUBSTR (appl_start_term, 5, 1) = 'F'
                   AND appl_school = 'SIS'
                   AND a.appl_acad_program = b.ID
                   AND b.dept_1 = c.ID
                   AND (derived_appl_disp = 'AC')
              GROUP BY appl_start_term) z
       WHERE appl_admit_status_cat IN ('MASTER')
         AND SUBSTR (a.appl_start_term, 5, 1) = 'F'
         AND appl_school = 'SIS'
         AND a.appl_acad_program = b.ID
         AND a.appl_start_term = z.appl_start_term(+)
    GROUP BY a.appl_start_term, z.acc_total                              --, acc_gre
    ORDER BY 1.. and use different aliases in your subquery (not the same a the main one).
    Edited by: user11268895 on Jul 17, 2010 7:23 PM

  • Custom F4 help in a BSP application working in Mozilla but not in IE

    Hi,
    I have created a custom F4 help in a BSP application.
    It is working in Mozilla but not in IE. I tried enabling javascript as well but still it is not working.
    Can someone please suggest a possible solution for this?

    Hi,
    See simmilar discussion in thread /thread/1883519 [original link is broken]
    I think this may be helpful for you.
    Thanks,
    Chandra

  • Why does the counter work in MAX, but not Labview?

    Please help, I have been away from Labview for over 3 months, and I am quite rusty....
    Last year, I successfully configured NI9401 to measure period (seconds) by counting the rising edges of my sensor signal.  Since then, I have aquired a new PC, and loaded all my software into it, including the Labview VI's that successfully worked on the old computer.
    I can see the digital signal using MAX and the test panel for the NI9401, so, I know my wiring and my TTL signal is OK, but, when I try to run the attached VI, nothing happens except the error below..  How do I tell this VI to look for the signal on MOD3/CTR0 and channel 14?
    Thanks. I am sure it is a small adjustment...this worked fine a few months ago...not sure what is wrong now.
    Thanks,
    Dave
    Solved!
    Go to Solution.
    Attachments:
    continuously measure period buffered_singlechannel_forum_feb_23_2012.vi ‏20 KB

    OK, now.  Resolved the issue. The vi is fine, but, some shaky wires were identified...worked in MAX but not in the vi.  Now that the connections have been tightened up, it works for both.  Sorry for the inconvenience.
    Dave

  • Works on emulators but not on mobile devices

    Hello,
    My project works on emulators but not on mobile devices (no image and on Samsung it says "unsupported file").
    Please help, I don't know what to do. My configurations: MIDP 2.1, CLDC 1.1.
    Thanks in advance.
    Edited by: Vitali.pom on Oct 27, 2011 12:01 PM

    Edit: I succeeded to solve it accidentally. I did the following: Sign the jar in Netbeans, clean and build, the jar didn't work, I wiped out the .ks from the jar and clean and build again. Now it worked.
    Edited by: Vitali.pom on Oct 30, 2011 1:28 AM

  • Wifi works at home but not when away from home

    My Wifi works at home but not when away from home, what is wrong?  I thought with a phone plan I didn't need to have a wifi connection.

    You either need WiFi or Cellular (or both). If you have neither, you can't connect to the internet.
    Most people use WiFi at home and Cellular while away from home, or connect to public WiFi networks where there are some.

  • Can't FaceTime anymore?  iPad states wifi connected and iPhone 4 states not connected?  I have wireless in my home? Not sure what happened.  Password works for iPad but not on phone?

    iPhone won't connect to wifi.  iPad is connected.  Password working on iPad but not on phone.  Can't upload software update of IOS 7.1 because phone not connecting to wifi?

    Connect iPhone to computer and open iTunes.  You will be prompted to update to iOS 7.0.  Keep your phone connected until the update is finished.

  • My apple id works on itunes but not on my ipod touch, what gives ?

    my apple id works on itunes but not on my ipod touch, what gives ?

    What are you trying to do on the iPod?
    Have you went to Settings>Store and sign out and then sign back in?

Maybe you are looking for

  • [SOLVED] PekWM menu font size

    I just installed a new theme (it's called Case) to use with PekWM and it is pretty ideal for me. However, the menu's font size is really, really small. After delving into Case's theme file, I found some "$font" strings, but I cannot find where font i

  • CSS issues in Firefox and Safari

    I have this bit of code that i cant seem to get working in firefox or safari .backgr { text-align:center; margin-left:0px; margin-top:0px; background-color:#CCCCCC; border:solid 1px; What am i doing wrong ASP, SQL2005, DW8 VBScript, Access

  • String to Object, then get the Class

    hi I'm new in Java! what I want to do is to convert a String and convert it to a Object then get the classname of the Object. for example: ExampleClass classObject = new ExampleClass(); String exampleString = "classObject"; I want to convert the stri

  • Is 1.3 Bios really better than 1.52B?? Neo2 Board and Some Observations!

    Hi All... I read this post on the forums and it got me thinking and i did some fiddling and made some observations.. This is whith regard to the 1.3Bios being better than the 1.52B Bios.. because it would let you run in turbo mode... Ok i've spent th

  • Poster Frame will not work

    After reviewing all of the suggestions here in the forum, I still cannot get Poster Frame to work. Here is what I have done: - Published to a Desktop folder and ran the index.html page to see if functionality worked. Did not. - Trashed iWeb prefs, re