Sorting does not work with ROW_NUMBER () OVER (ORDER BY

CREATE OR REPLACE PROCEDURE SP_SALES)
p_sales_id IN VARCHAR2,
p_rownnum_from in NUMBERS
p_rownnum_to in NUMBERS
p_sort_by IN VARCHAR2,
p_query ON SYS_REFCURSOR,
)
AS
v_query VARCHAR2 (32000);
v_sort_list VARCHAR2 (32000);
BEGIN

IF p_spv_sort_by IS NULL THEN
v_sort_list: = 'nom_donne ASC ";
ON THE OTHER
v_sort_list: = p_spv_sort_by;
END IF;

DBMS_OUTPUT. Put_line ('v_sort_list' | v_sort_list);
OPEN FOR P_query
SELECT sales_id
item_id,
order_num,
Employee_Name
nom_donne
dept_id,
manager_name,
NO_LIG
Of
(SELECT x.*,
ROW_NUMBER () OVER (ORDER BY v_sort_list) no_lig
OF (sales_id,
item_id,
order_num,
Employee_Name
nom_donne
dept_id,
manager_name,
Vaughan Williams order.
sale pol,
CA of the EMP,
WHERE pol.id = rvw.pr_order_id
AND ca.empid = pol.employee_id
(AND status = "SUP") x)
WHERE the arguments no_lig BETWEEN p_rownnum_from AND p_rownnum_to;
-ORDER by v_sort_list;
DBMS_OUTPUT. Put_line ('v_sort_list' | v_sort_list);

EXCEPTION
WHILE OTHERS THEN
DBMS_OUTPUT. PUT_LINE ('EX');
END;
END;
/
DISPLAY ERRORS


Sorting does not work. I'm doing something wrong here?

How to run for help below
declare
x SYS_REFCURSOR;
number of y;
BEGIN
SP_SALES ('70159_502', 1, 5, 'GIVEN_NAME' |') ASC',: x);
-dbms_output.put_line (: x);
END;

Hello

According to the number of columns different, you can sort on and data types, it may be possible for you to include conditional logic in the existing statement without requiring dynamic sql code...

DTYLER_APP@pssdev2> var p_spv_sort_by varchar2(100)
DTYLER_APP@pssdev2>
DTYLER_APP@pssdev2> exec :p_spv_sort_by:='some other column'

PL/SQL procedure successfully completed.

P_SPV_SORT_BY
----------------------------------------------------------------------------------------
some other column

DTYLER_APP@pssdev2>
DTYLER_APP@pssdev2> WITH source AS
  2  (   SELECT 'a' given_name, 'z' other_column from dual UNION ALL
  3      SELECT 'b' given_name, 'y' other_column from dual UNION ALL
  4      SELECT 'c' given_name, 'x' other_column from dual
  5  )
  6  SELECT
  7      given_name,
  8      other_column,
  9      ROW_NUMBER ()
 10     OVER (
 11        ORDER BY
 12           CASE
 13              WHEN :p_spv_sort_by IS NULL THEN given_name
 14              WHEN :p_spv_sort_by = 'some other column' THEN other_column
 15           END)
 16        ROW_NUM
 17  FROM
 18      source
 19  /

G O    ROW_NUM
- - ----------
c x          1
b y          2
a z          3

3 rows selected.

DTYLER_APP@pssdev2> exec :p_spv_sort_by:=NULL;

PL/SQL procedure successfully completed.

P_SPV_SORT_BY
----------------------------------------------------------------------------------------

DTYLER_APP@pssdev2> WITH source AS
  2  (   SELECT 'a' given_name, 'z' other_column from dual UNION ALL
  3      SELECT 'b' given_name, 'y' other_column from dual UNION ALL
  4      SELECT 'c' given_name, 'x' other_column from dual
  5  )
  6  SELECT
  7      given_name,
  8      other_column,
  9      ROW_NUMBER ()
 10     OVER (
 11        ORDER BY
 12           CASE
 13              WHEN :p_spv_sort_by IS NULL THEN given_name
 14              WHEN :p_spv_sort_by = 'some other column' THEN other_column
 15           END)
 16        ROW_NUM
 17  FROM
 18      source
 19  /

G O    ROW_NUM
- - ----------
a z          1
b y          2
c x          3

3 rows selected.

DTYLER_APP@pssdev2>

But this would depend on the columns that you sort to be of the same data type or at least have the possibility of converting the same type of data without loss of the sort order.

DTYLER_APP@pssdev2> WITH source AS
  2  (   SELECT 'a' given_name, sysdate - 2 other_column from dual UNION ALL
  3      SELECT 'b' given_name, sysdate - 1 other_column from dual UNION ALL
  4      SELECT 'c' given_name, sysdate  other_column from dual
  5  )
  6  SELECT
  7      given_name,
  8      other_column,
  9      ROW_NUMBER ()
 10     OVER (
 11        ORDER BY
 12           CASE
 13              WHEN :p_spv_sort_by IS NULL THEN given_name
 14              WHEN :p_spv_sort_by = 'some other column' THEN other_column
 15           END)
 16        ROW_NUM
 17  FROM
 18      source
 19  /
            WHEN :p_spv_sort_by = 'some other column' THEN other_column
                                                           *
ERROR at line 14:
ORA-00932: inconsistent datatypes: expected CHAR got DATE

DTYLER_APP@pssdev2> WITH source AS
  2  (   SELECT 'a' given_name, sysdate - 2 other_column from dual UNION ALL
  3      SELECT 'b' given_name, sysdate - 1 other_column from dual UNION ALL
  4      SELECT 'c' given_name, sysdate  other_column from dual
  5  )
  6  SELECT
  7      given_name,
  8      other_column,
  9      ROW_NUMBER ()
 10     OVER (
 11        ORDER BY
 12           CASE
 13              WHEN :p_spv_sort_by IS NULL THEN given_name
 14              WHEN :p_spv_sort_by = 'some other column' THEN TO_CHAR(other_column,'YYYYMMDDHH24MISS')
 15           END)
 16        ROW_NUM
 17  FROM
 18      source
 19  /

G OTHER_COLUMN            ROW_NUM
- -------------------- ----------
a 12-SEP-2011 15:04:19          1
b 13-SEP-2011 15:04:19          2
c 14-SEP-2011 15:04:19          3

3 rows selected.

HTH

David

Tags: Database

Similar Questions

  • New iPhone IS does not work with MAC Mini 10.6.8. Apple support says upgrade your iTunes. Its the wrong color icon. WHAT? iTunes is the last 11.4 for my mac. All my music is on my Mac. Help!

    New iPhone IS does not work with MAC Mini 10.6.8. Apple support says upgrade your iTunes. Its the wrong color icon. WHAT? iTunes is the last 11.4 for my mac. All my music is on my Mac. Help!

    That is right. The requires iTunes 12.3.3 and in order to get it, you will need to update OS X to El Capitan. That's how Apple has created for better or worse, I'm sorry.

  • the joystick does not work with windows 8

    Hello

    I have a problem using the joystick; When I used it with windows 7 it works, but when I tried to use it with windows 8, even if it is detected in windows, it does not work with any of my VIs(labview_2012).is there an issue with labview, or there is a solution to solve this.

    Thank you

    I wrote this VI in order to study how to integrate a Joystick into my LabVIEW code (I called the "Joystick Sampler" VI).  It has two parts - the lowest fact function, "Query Input Devices", an array of devices, their names and the number of Axes, buttons and POV "hat", in a table called "Joystick Info".  Look at this attention first, in pay to the array Index that seems to match your gamepad, when plug you it into a USB port.

    The upper code can enjoy (one of the) Joystick (s) at the rate of 10 Hz, which allows you to test the buttons, axes, etc..  Note that the primary function of "Initialize the Joystick" takes a parameter (default = 0) which corresponds to the Index of Joystick, you have discovered by looking at the table Info Joystick (see previous paragraph) - If your joystick, for example, seems to be at Index = 4, thread has '4' in the function Initialize Joystick.

    BS

  • DeskJet 712c does not work with Win 7

    I recently switched to a new win 7 Home Premium SP1 (64) my old XP computer which worked well with my printer.  The printer does not work with the new OS and the computer.  Even if the computer indicates that the device is functioning normally, the printer will not accept print orders.  Not even the printer print test.  There is no error reports but the system behaves as if the usb is not connected, even though it is.   There were no changes in connectivity before or after installing new software (or trying) trying to get the new computer set up.

    I just found it and tried the wizard of the printer which also implies that the usb is not connected even though it is.

    The compatibility options have done nothing to help.

    Tara,.

    EUREKA!  At the risk of party too early, it seems that I am able to print with my new computer (HP).  Fixed after almost endless hours trying to get my printer to work despite many internet messages saying it could not be done and other giving solutions that didn't work.

    Why o ' why the solution apparently a hidden secret and why the tools did not work?

    In any case, thank you very much.  With all the problems I'm having to migrate to Windows 7, it's a very important achievement.  Thank you, thank you.

    Chuck

  • 128 - GB MicroSD card does not work with the new Clip +.

    My old Clip + (black, 8 GB) was getting very long in the tooth, so I ordered a replacement off Amazon.  As far as I know, it is identical to the old, but a very unpleasant difference is presented - it does not work with the MicroSD card which has been a huge part of why I got a Sansa at all.  He acknowledges, but after a media updated I'm lucky if more than one album appears.  And that's what's so crazy!  You just blow through the update in a few seconds, and when I navigate on the map, there is nothing or a handful of albums random, orphaned.  That's happened?  I updated the new Clip + for the current firmware (as I had done with previous); I made sure to reproduce all the parameters that I would be put in place before--I can't imagine what could be the cause!

    Treats quick closing:

    The card is formatted in FAT32 with the same sector size in storage aboard the player (32 768 bytes).

    A 64 GB card format works even without any problem.

    I tried to update the media in MTP and MSC mode; the problem is the same in both.

    There is ample space for MTABLE. SYS - I have not yet loaded all the music on the Clip + itself.

    Rockbox plays the card without problem, but the sound quality is horrible (at least on this player; I'm sure that other versions sound best), and its interface is a headache.  No thanks.

    HM.  Looks like to run CHKDSK /F on the map the problem resolved!

  • dedicated on microsoft 4000 keyboard back button does not work with firefox

    Hello-

    I have a microsoft 4000 keyboard.

    He dedicated the buttons back and next to the navigation of the browser: http://xahlee.info/kbd/ms_keyboard/i/ms_n4000_keyboard_LED.jpg

    the back button does not work with firefox

    other info: the next button does not work with firefox. buttons next and previous works with IE, tor and chrome. the keyboard shortcut for back in firefox (alt + left arrow) does not work.

    I've tried clearing cache and cookies and start firefox in safe mode.

    advice?

    Hello

    Thanks for posting your query in Microsoft Community.

    I understand you have questions only by using the back button in the Firefox browser.

    But I would like more information on this topic in order to help you.

    (1) the back button worked before with Firefox?

    (2) don't you make changes before this problem?

    According to your description, there is no problem with the material since it works with Internet Explorer and Google Chrome. Previous key does not only work with Firefox. Therefore, I would advice you to check with Firefox and see if that helps, because they have more expertise on products here to help you better.

    Support for Firefox

    https://support.Mozilla.org/en-us/products/Firefox

    Hope this information is useful. Please write us back for assistance.

  • SortSpec does not work with CRMI

    Hi all

    We have a custom user interface to display the content from the content server and use the below code to retrieve data from the content server. But somehow SortSpec does not work with CRMI. Any pointer?

    DataBinder requestBinder = idcClient.createBinder ();

    requestBinder.putLocal ("IdcService", "GET_SEARCH_RESULTS");

    requestBinder.putLocal ("SortSpec",

    'order by dDocName ASC, dInDate DESC');

    requestBinder.putLocal ("QueryText", queryText);

    DataBinder answer =

    idcClient.sendRequest (idcContext, requestBinder) .getResponseAsBinder ();

    error: oracle.stellent.ridc.protocol.ServiceException: unable to retrieve search results. Has encountered an exception during execution of a query.

    env: Webcenter content 11.1.1.8

    Thank you

    DM

    Hi Olivier,.

    Instead of

    requestBinder.putLocal ("SortSpec",

    'order by dDocName ASC, dInDate DESC');

    Try this:

    requestBinder.putLocal ("SortSpec", "CSA sddDocName, dInDate DESC");

    Test and report the results.

    Thank you

    Srinath

  • It does not work with macbook air 2008! What should I do?

    It does not work with the macbook air 2008 os x 10.5.8. What should I do?

    What does not work?

    More details please!

  • Why do code grayscaler site image Web does not work with Mozilla Firefox, but it does to another browser?

    I just noticed that my code (in my blog site), which is a regular code that allows the image to transform into its form in grayscale and cast its original color, does not work with the Mozilla Firefox browser. But with other browsers, it works. I hope you can help me with this little problem. Thank you!

    Should I use a CSS rule that is similar to:

    filter: grayscale(100%)
    

    This property is not yet implemented in Firefox. It is supposed to be implemented in Firefox 34, according to https://developer.mozilla.org/en-US/docs/Web/CSS/filter

  • iCloud 5.2.1.69 does not work with Outlook 2016 (16.0.6965.2053)

    I installed the new iCloud (v5.2.1.69) and found that it does not work with Outlook 2016 (16.0.6965.2053). There is no button "Options"... "to"Mail, Contacts, calendars and tasks"(see photo). In addition, the iCloud Outlook add-in does not display in Outlook. I tried to reinstall the Office 365 and iCloud, but nothing has changed.

    I have exactly the same problem with the latest version of iCloud.  I have Outlook 2016 and 10 Windows and when I try to install iCloud there saying "set up" next "Mail, Contacts, calendars and tasks.  I left it for hours and it does not go beyond this point.  Outlook displays the listed add-in but it is not doing anything.  I tried to remove all of the Apple software, and then reinstall iCloud without result. I've deleted and reinstalled MS Office and then tried to reinstall iCloud - once again no luck.

  • keyconfig does not work with FF 24.0. Is there a way?

    I just finished rebuilding my PC from a hard drive format. In doing so, I loaded the last 24.0 FF.
    Part of my essential app is a script used keyconfig causes a single copy to send the source page to the Clipboard, where the script analysis. Unfortunately, keyconfig does not work with FF 24.0.

    Writing for easy copy begins to explain how acting on a combination of keys, rather than the action of the mouse, without the use of keycopy - but then told how he has no need, because it's too much effort, and besides - keyconfig exists and does the job - which, I agree, he used, very well - but it is no more.

    What should do? If there is no other way, can I get a downgrade of FF that works with keyconfig?

    There is a new add-on, key config (note the space), but it does not what keyconfig did.

    The end of the thread main support doesn't mention a major problem in Firefox 24: keyconfig 20110522 - mozillaZine Forums.

    Did you install from source: http://mozilla.dorando.at/keyconfig.xpi

    Is the problem that Firefox won't let you activate keyconfig, but the dialog box opens, or you can activate or extension allows you to create shortcuts but they do not work?

  • Downloaded the new firefox and it told me that it does not work with my software, how do I go back to my old version

    I have a mac 10.5.8 software. I downloaded moxilla firefox 24 and has replaced the old version to download. Then I got a message that firefox 24 does not work with my software. How to bring back the old version?

    Hello patcouse, if you want to stay with you older version of the OS, then firefox 16 is the last version available that will run in this environment. for a download link, please refer to the Firefox no longer works with Mac OS X 10.5 (at the end of the article).

  • The CD/DVD does not work with El Capitan 10.11.5 on Macbook Pro

    Hello everyone, I spent the time to research on the here and the other site on why the CD/DVD does not work with El Capitan 10.11.5 on MacBook Pro mid 2009. This discussion forum has said that he will not work with the El Capitan software. Any idea or suggestion? Back to Marverick or Yosemite? I tried to use SMC reset, restart, recovery and still the same issue.

    I thank in advance.

    ~ Mike

    I have my doubts that the (10.11.5) software is the problem.  Are you sure that the DVD player is simply not defective?  Have you tried to clean the lens?  What is the State of the disc?

    Your best option may be a date at a bar in engineering of the Apple store for a FREE evaluation.

    Ciao.

  • SQLite Manager does not work with the v11. Until make you it easier to go back to older versions or newer versions stop, breaking most of the modules I won't use Firefox

    SQLite Manager does not work with the v11. Until that make it easier to return to older versions or newer versions stop, breaking most of the modules I use FirefoxHow to come back at 10 Firefox?

    Update Firefox 23.0 which published yesterday afternoon.

  • Norton Toolbar does not work with Firefox 17, provided Comcast Norton Security Suite, Win 7.

    I have Norton Security Suite provided by Comcast. Norton Toolbar does not work with Firefox 17.0.1 on my Win 7 machine. I lived all the questions on this topic and did all the steps and when I click on "Add-ons", he always says that the toolbar is not compatible. It works with IE, but I prefer to use Firefox.

    I had the same problem in the past. If you call customer Norton service toll-free they have always helped me start (without charges) when I have updated to a new version of Firefox - seems to happen every time even if I run the updates regularly. Hope that this phone help-Norton support is always very friendly and helpful-just Google their 800 number.

Maybe you are looking for