How to Display The last 4 digit of numbers and replace the rest of the number with XXXXXXXXX's












-2















How to displays the last four digits of the
Numbers in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first
12 digits of the card number and actual numbers for the last four digits of the number.
Thank YOu










share|improve this question




















  • 1





    The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

    – Barmar
    Nov 25 '18 at 21:23











  • Does it have to work for 15-digit AMEX payment card numbers too?

    – O. Jones
    Nov 25 '18 at 21:25






  • 1





    Recommend avoiding storing credit number, or store them as the masked value.

    – danblack
    Nov 25 '18 at 22:02
















-2















How to displays the last four digits of the
Numbers in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first
12 digits of the card number and actual numbers for the last four digits of the number.
Thank YOu










share|improve this question




















  • 1





    The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

    – Barmar
    Nov 25 '18 at 21:23











  • Does it have to work for 15-digit AMEX payment card numbers too?

    – O. Jones
    Nov 25 '18 at 21:25






  • 1





    Recommend avoiding storing credit number, or store them as the masked value.

    – danblack
    Nov 25 '18 at 22:02














-2












-2








-2








How to displays the last four digits of the
Numbers in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first
12 digits of the card number and actual numbers for the last four digits of the number.
Thank YOu










share|improve this question
















How to displays the last four digits of the
Numbers in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first
12 digits of the card number and actual numbers for the last four digits of the number.
Thank YOu







mysql mysql-workbench






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 21:28







A.Tesma

















asked Nov 25 '18 at 21:18









A.TesmaA.Tesma

12




12








  • 1





    The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

    – Barmar
    Nov 25 '18 at 21:23











  • Does it have to work for 15-digit AMEX payment card numbers too?

    – O. Jones
    Nov 25 '18 at 21:25






  • 1





    Recommend avoiding storing credit number, or store them as the masked value.

    – danblack
    Nov 25 '18 at 22:02














  • 1





    The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

    – Barmar
    Nov 25 '18 at 21:23











  • Does it have to work for 15-digit AMEX payment card numbers too?

    – O. Jones
    Nov 25 '18 at 21:25






  • 1





    Recommend avoiding storing credit number, or store them as the masked value.

    – danblack
    Nov 25 '18 at 22:02








1




1





The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

– Barmar
Nov 25 '18 at 21:23





The question seems to start in the middle of a sentence. Please write more clearly. Also see How to Ask for the way to ask a good question.

– Barmar
Nov 25 '18 at 21:23













Does it have to work for 15-digit AMEX payment card numbers too?

– O. Jones
Nov 25 '18 at 21:25





Does it have to work for 15-digit AMEX payment card numbers too?

– O. Jones
Nov 25 '18 at 21:25




1




1





Recommend avoiding storing credit number, or store them as the masked value.

– danblack
Nov 25 '18 at 22:02





Recommend avoiding storing credit number, or store them as the masked value.

– danblack
Nov 25 '18 at 22:02












1 Answer
1






active

oldest

votes


















0














I wrote a function that you can use to make this job: you can pass to this function any number, the function calculates the modulo 10000 class of the number (i.e. the rest of the division by 10000) in other words the last four digits of your number. Then the function concatenates XXXX-XXXX-XXXX- and zeros as needed.



DELIMITER $$
CREATE FUNCTION N_CREDIT_CARD
(NUMBER INT)
RETURNS VARCHAR(19)
DETERMINISTIC
BEGIN
DECLARE NUM INT;
SET NUM=NUMBER%10000;
RETURN (CASE WHEN NUM < 10 THEN CONCAT('XXXX-XXXX-XXXX-000', CAST(NUM AS CHAR(1)))
WHEN NUM < 100 THEN CONCAT('XXXX-XXXX-XXXX-00', CAST(NUM AS CHAR(2)))
WHEN NUM < 1000 THEN CONCAT('XXXX-XXXX-XXXX-0', CAST(NUM AS CHAR(3)))
ELSE CONCAT('XXXX-XXXX-XXXX-',CAST(NUM AS CHAR(4))) END);
END$$
DELIMITER;





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472069%2fhow-to-display-the-last-4-digit-of-numbers-and-replace-the-rest-of-the-number-wi%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I wrote a function that you can use to make this job: you can pass to this function any number, the function calculates the modulo 10000 class of the number (i.e. the rest of the division by 10000) in other words the last four digits of your number. Then the function concatenates XXXX-XXXX-XXXX- and zeros as needed.



    DELIMITER $$
    CREATE FUNCTION N_CREDIT_CARD
    (NUMBER INT)
    RETURNS VARCHAR(19)
    DETERMINISTIC
    BEGIN
    DECLARE NUM INT;
    SET NUM=NUMBER%10000;
    RETURN (CASE WHEN NUM < 10 THEN CONCAT('XXXX-XXXX-XXXX-000', CAST(NUM AS CHAR(1)))
    WHEN NUM < 100 THEN CONCAT('XXXX-XXXX-XXXX-00', CAST(NUM AS CHAR(2)))
    WHEN NUM < 1000 THEN CONCAT('XXXX-XXXX-XXXX-0', CAST(NUM AS CHAR(3)))
    ELSE CONCAT('XXXX-XXXX-XXXX-',CAST(NUM AS CHAR(4))) END);
    END$$
    DELIMITER;





    share|improve this answer




























      0














      I wrote a function that you can use to make this job: you can pass to this function any number, the function calculates the modulo 10000 class of the number (i.e. the rest of the division by 10000) in other words the last four digits of your number. Then the function concatenates XXXX-XXXX-XXXX- and zeros as needed.



      DELIMITER $$
      CREATE FUNCTION N_CREDIT_CARD
      (NUMBER INT)
      RETURNS VARCHAR(19)
      DETERMINISTIC
      BEGIN
      DECLARE NUM INT;
      SET NUM=NUMBER%10000;
      RETURN (CASE WHEN NUM < 10 THEN CONCAT('XXXX-XXXX-XXXX-000', CAST(NUM AS CHAR(1)))
      WHEN NUM < 100 THEN CONCAT('XXXX-XXXX-XXXX-00', CAST(NUM AS CHAR(2)))
      WHEN NUM < 1000 THEN CONCAT('XXXX-XXXX-XXXX-0', CAST(NUM AS CHAR(3)))
      ELSE CONCAT('XXXX-XXXX-XXXX-',CAST(NUM AS CHAR(4))) END);
      END$$
      DELIMITER;





      share|improve this answer


























        0












        0








        0







        I wrote a function that you can use to make this job: you can pass to this function any number, the function calculates the modulo 10000 class of the number (i.e. the rest of the division by 10000) in other words the last four digits of your number. Then the function concatenates XXXX-XXXX-XXXX- and zeros as needed.



        DELIMITER $$
        CREATE FUNCTION N_CREDIT_CARD
        (NUMBER INT)
        RETURNS VARCHAR(19)
        DETERMINISTIC
        BEGIN
        DECLARE NUM INT;
        SET NUM=NUMBER%10000;
        RETURN (CASE WHEN NUM < 10 THEN CONCAT('XXXX-XXXX-XXXX-000', CAST(NUM AS CHAR(1)))
        WHEN NUM < 100 THEN CONCAT('XXXX-XXXX-XXXX-00', CAST(NUM AS CHAR(2)))
        WHEN NUM < 1000 THEN CONCAT('XXXX-XXXX-XXXX-0', CAST(NUM AS CHAR(3)))
        ELSE CONCAT('XXXX-XXXX-XXXX-',CAST(NUM AS CHAR(4))) END);
        END$$
        DELIMITER;





        share|improve this answer













        I wrote a function that you can use to make this job: you can pass to this function any number, the function calculates the modulo 10000 class of the number (i.e. the rest of the division by 10000) in other words the last four digits of your number. Then the function concatenates XXXX-XXXX-XXXX- and zeros as needed.



        DELIMITER $$
        CREATE FUNCTION N_CREDIT_CARD
        (NUMBER INT)
        RETURNS VARCHAR(19)
        DETERMINISTIC
        BEGIN
        DECLARE NUM INT;
        SET NUM=NUMBER%10000;
        RETURN (CASE WHEN NUM < 10 THEN CONCAT('XXXX-XXXX-XXXX-000', CAST(NUM AS CHAR(1)))
        WHEN NUM < 100 THEN CONCAT('XXXX-XXXX-XXXX-00', CAST(NUM AS CHAR(2)))
        WHEN NUM < 1000 THEN CONCAT('XXXX-XXXX-XXXX-0', CAST(NUM AS CHAR(3)))
        ELSE CONCAT('XXXX-XXXX-XXXX-',CAST(NUM AS CHAR(4))) END);
        END$$
        DELIMITER;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 17:16









        GufusGufus

        11818




        11818






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472069%2fhow-to-display-the-last-4-digit-of-numbers-and-replace-the-rest-of-the-number-wi%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)