Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:05:17+00:00 2026-06-18T16:05:17+00:00

I am typing a function and i’m having an error here, I dont know

  • 0

I am typing a function and i’m having an error here, I dont know what it is.
Could you give me a Hand ?

CREATE or replace FUNCTION function1(pIdReg in number,pIdPeriod in number) RETURN 

number
IS
  ncv number DEFAULT 0;
BEGIN
     SELECT COUNT(IdPeriod)
         INTO ncv
         FROM(
             SELECT a.IdPeriod, SUM(case when a.nt=0 then -a.valor else a.valor end) AS total --IF(a.nt=0,-a.valor,a.valor))
             FROM dc a
             JOIN emp b ON a.idDoc = b.idDoc
             WHERE a.idReg = pIdReg AND a.IdPeriod < pIdPeriod AND
             b.cc != 305 AND
                  (
                    b.cc = 302 AND(b.tipomov != 4)
                    OR
                    b.cc != 302 AND(1=1)-- emular el TRUE
                  )
             AND a.type != 7
             GROUP BY 1 HAVING total != 0
             ) AS ncv;
      RETURN ncv;
END;
/

The error is SQL command not properly ended.
Sqldeveloper shows “AS ncv” underlined. Is there any problem with group by or having clause ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:05:18+00:00Added an answer on June 18, 2026 at 4:05 pm

    I see three errors (though there may be more)

    • Oracle does not use the AS keyword for assigning table aliases. So AS ncv is invalid. If you want to use ncv as the alias for your subquery, you’d need to remove the AS (though it seems odd to choose an alias that happens to collide with the name of a local variable).
    • You cannot use positional notation in a GROUP BY clause. You would need to specify the name of the column(s) you want to group by not their position.
    • You cannot use aliases defined in your SELECT list in your HAVING clause. You would have to specify the aggregate function in the HAVING clause

    Putting those three things together, I suspect you want something like this

    CREATE or replace FUNCTION function1(pIdReg in number,pIdPeriod in number) 
      RETURN number
    IS
      ncv number DEFAULT 0;
    BEGIN
      SELECT COUNT(IdPeriod)
        INTO ncv
        FROM(
             SELECT a.IdPeriod, 
                    SUM(case when a.nt=0 
                             then -a.valor 
                             else a.valor 
                         end) AS total --IF(a.nt=0,-a.valor,a.valor))
               FROM dc a
               JOIN emp b ON a.idDoc = b.idDoc
              WHERE a.idReg = pIdReg AND a.IdPeriod < pIdPeriod 
                AND b.cc != 305 
                AND (
                      b.cc = 302 AND(b.tipomov != 4)
                      OR
                      b.cc != 302 AND(1=1)-- emular el TRUE
                    )
               AND a.type != 7
             GROUP BY a.IdPeriod
            HAVING SUM(case when a.nt=0 
                            then -a.valor 
                            else a.valor 
                        end) != 0
           ) ncv;
      RETURN ncv;
    END;
    /
    

    If you are still getting errors, it would be extremely helpful if you could edit your question and provide the DDL to create the tables that are referenced in this code. That would allow us to test on our systems whether the function compiles or not rather than trying to guess at the syntax errors

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could swear I've seen people typing function headers and then hitting some key
Is it possible to make all function's vars global without typing all of them
I have a function that is being called when the user is typing in
$("#input").keyup(function(){ console.log($(this).val()); }) When one is typing slowly "a" & "b" the above code
I have a jquery function that should count characters the user is typing in
I want my function to take an argument that could be an unicode object
I am trying to create a function that conjugate a complex number for example
Would like to know if there is a function in python that can take
I have combined itechroom checkUserName function with JohnP's run js after user finished typing
The Mac R-Gui has a nice feature where when you start typing a function,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.